perf ui browser: Add key_name() helper

We'll use it to show unhandled keys in the various TUI browsers.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/Z_TYux5fUg2pW-pF@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo
2025-04-08 17:17:10 -03:00
parent e0eb84cd51
commit f165523931
3 changed files with 47 additions and 0 deletions

View File

@@ -8,5 +8,6 @@ perf-ui-y += stdio/hist.o
CFLAGS_setup.o += -DLIBDIR="BUILD_STR($(LIBDIR))"
perf-ui-$(CONFIG_SLANG) += browser.o
perf-ui-$(CONFIG_SLANG) += keysyms.o
perf-ui-$(CONFIG_SLANG) += browsers/
perf-ui-$(CONFIG_SLANG) += tui/

44
tools/perf/ui/keysyms.c Normal file
View File

@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include "keysyms.h"
#include <linux/ctype.h>
#include <linux/kernel.h>
const char *key_name(int key, char *bf, size_t size)
{
if (isprint(key)) {
scnprintf(bf, size, "%c", key);
} else if (key < 32) {
scnprintf(bf, size, "Ctrl+%c", key + '@');
} else {
const char *name = NULL;
switch (key) {
case K_DOWN: name = "Down"; break;
case K_END: name = "End"; break;
case K_ENTER: name = "Enter"; break;
case K_ESC: name = "ESC"; break;
case K_F1: name = "F1"; break;
case K_HOME: name = "Home"; break;
case K_LEFT: name = "Left"; break;
case K_PGDN: name = "PgDown"; break;
case K_PGUP: name = "PgUp"; break;
case K_RIGHT: name = "Right"; break;
case K_TAB: name = "Tab"; break;
case K_UNTAB: name = "Untab"; break;
case K_UP: name = "Up"; break;
case K_BKSPC: name = "Backspace"; break;
case K_DEL: name = "Del"; break;
default:
if (key >= SL_KEY_F(1) && key <= SL_KEY_F(63))
scnprintf(bf, size, "F%d", key - SL_KEY_F(0));
else
scnprintf(bf, size, "Unknown (%d)", key);
}
if (name)
scnprintf(bf, size, "%s", name);
}
return bf;
}

View File

@@ -27,4 +27,6 @@
#define K_SWITCH_INPUT_DATA -4
#define K_RELOAD -5
const char *key_name(int key, char *bf, size_t size);
#endif /* _PERF_KEYSYMS_H_ */