]> granicus.if.org Git - procps-ng/commitdiff
top: extend 'focus' navigation to shift+tab (back_tab)
authorJim Warner <james.warner@comcast.net>
Tue, 17 May 2022 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Wed, 18 May 2022 11:30:56 +0000 (21:30 +1000)
Some of those bottom windows grow quite large, as with
the firefox environment. If one is navigating the data
using the tab key, it can be very inconvenient when an
element should be reexamined but that focus has moved.

Therefore, this commit will support the 'back_tab' key
which is a standard combination of the shift+tab keys.

Now a user can easily backup up to any missed element,
assuming a terminal emulator honors that terminfo key.

[ a gui emulator typically will honor the 'back_tab' ]
[ terminfo string, whereas a linux console does not. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c
top/top.h

index 87ba96e7e997d3bf94c6a1c7a89874685e9c1382..2a980388ca0e2cd44506616706003be730b68661 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -1124,9 +1124,9 @@ static int iokey (int action) {
       const char *str;
       int key;
    } tinfo_tab[] = {
-      { NULL, kbd_BKSP  }, { NULL, kbd_INS   }, { NULL, kbd_DEL   },
-      { NULL, kbd_LEFT  }, { NULL, kbd_DOWN  }, { NULL, kbd_UP    }, { NULL, kbd_RIGHT },
-      { NULL, kbd_HOME  }, { NULL, kbd_PGDN  }, { NULL, kbd_PGUP  }, { NULL, kbd_END   },
+      { NULL, kbd_BKSP  }, { NULL, kbd_INS   }, { NULL, kbd_DEL   }, { NULL, kbd_LEFT  },
+      { NULL, kbd_DOWN  }, { NULL, kbd_UP    }, { NULL, kbd_RIGHT }, { NULL, kbd_HOME  },
+      { NULL, kbd_PGDN  }, { NULL, kbd_PGUP  }, { NULL, kbd_END   }, { NULL, kbd_BTAB  },
          // remainder are alternatives for above, just in case...
          // ( the h,j,k,l entries are the vim cursor motion keys )
       { "\033h",    kbd_LEFT  }, { "\033j",    kbd_DOWN  }, /* meta+      h,j */
@@ -1160,6 +1160,7 @@ static int iokey (int action) {
       tinfo_tab[8].str  = tOk(key_npage);
       tinfo_tab[9].str  = tOk(key_ppage);
       tinfo_tab[10].str = tOk(key_end);
+      tinfo_tab[11].str = tOk(back_tab);
       // next is critical so returned results match bound terminfo keys
       putp(tOk(keypad_xmit));
       // ( converse keypad_local issued at pause/pgm end, just in case )
@@ -5619,6 +5620,14 @@ static void keys_global (int ch) {
       case kbd_CtrlU:
          bot_item_toggle(EU_SGN, "supplementary groups", ',');
          break;
+      case kbd_BTAB:
+         if (Bot_what) {
+            --Bot_indx;
+            num = Bot_focus_func(NULL, NULL);
+            if (Bot_indx <= BOT_UNFOCUS)
+               Bot_indx = num + 1;
+         }
+         break;
       case kbd_ENTER:             // fall through
 #ifdef BOT_MENU_YES
          if (Bot_what == BOT_MENU_ON && Bot_indx != BOT_UNFOCUS)
@@ -6463,11 +6472,12 @@ static void do_key (int ch) {
       { keys_global,
          { '?', 'B', 'd', 'E', 'e', 'f', 'g', 'H', 'h'
          , 'I', 'k', 'r', 's', 'X', 'Y', 'Z', '0'
-         , kbd_CtrlE, kbd_CtrlG, kbd_CtrlI, kbd_CtrlK, kbd_CtrlN, kbd_CtrlP, kbd_CtrlR, kbd_CtrlU
+         , kbd_CtrlE, kbd_CtrlG, kbd_CtrlI, kbd_CtrlK
+         , kbd_CtrlN, kbd_CtrlP, kbd_CtrlR, kbd_CtrlU
 #ifdef BOT_MENU_YES
          , kbd_CtrlH
 #endif
-         , kbd_ENTER, kbd_SPACE, '\0' } },
+         , kbd_ENTER, kbd_SPACE, kbd_BTAB, '\0' } },
       { keys_summary,
          { '!', '1', '2', '3', '4', 'C', 'l', 'm', 't', '\0' } },
       { keys_task,
index 4814b83b3387302f85ea2067af3b2c0008bbddff..bcca7e3599b79d606d2db929eda895f7d5bd0687 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -175,6 +175,7 @@ char *strcasestr(const char *haystack, const char *needle);
 #define kbd_BKSP   137
 #define kbd_INS    138
 #define kbd_DEL    139
+#define kbd_BTAB   140
 #define kbd_CtrlE  '\005'
 #define kbd_CtrlG  '\007'
 #ifdef BOT_MENU_YES