From d4a310445cd2fda41257c44bfef5b78122c52a83 Mon Sep 17 00:00:00 2001 From: Spenser Truex Date: Wed, 17 Aug 2022 13:46:22 -0300 Subject: [PATCH] Add 'only' delete keybinding --- config.def.h | 2 ++ mtm.1 | 2 ++ mtm.c | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/config.def.h b/config.def.h index 200d5f8..ad60bba 100644 --- a/config.def.h +++ b/config.def.h @@ -56,6 +56,7 @@ /* The delete terminal key. */ #define DELETE_NODE KEY(L'w') +#define ONLY_NODE KEY(L'q') /* The force redraw key. */ #define REDRAW KEY(L'l') @@ -193,3 +194,4 @@ static wchar_t CSET_GRAPH[] ={ /* Graphics Set One */ }; #endif + diff --git a/mtm.1 b/mtm.1 index fbdb6fe..68a1ef9 100644 --- a/mtm.1 +++ b/mtm.1 @@ -85,6 +85,8 @@ or stack vertically the newly-created terminal will be focused. .It Em "w" Delete the currently focused terminal. +.It Em "q" +Delete all other terminals, except this one. .It Em "l" .Pq "the letter ell" Redraw the screen. diff --git a/mtm.c b/mtm.c index 5e1427f..1d1145b 100644 --- a/mtm.c +++ b/mtm.c @@ -893,6 +893,26 @@ deletenode(NODE *n) /* Delete a node. */ freenode(n, true); } +static void +onlynode(NODE *n) /* Delete other nodes. */ +{ + struct NODE *node = NULL; + int next = false; + if (n != focused) + focus(n); + while(true){ + /* KLUDGE: should go to the "next" node instead. */ + (next=false) || ((node=findnode(root, ABOVE(n))) && (next=true)); + next || ((node=findnode(root, BELOW(n))) && (next=true)); + next || ((node=findnode(root, LEFT(n))) && (next=true)); + next || ((node=findnode(root, RIGHT(n))) && (next=true)); + if(!next) + break; + deletenode(node); + } +} + + static void reshapeview(NODE *n, int d, int ow) /* Reshape a view. */ { @@ -1101,6 +1121,7 @@ handlechar(int r, int k) /* Handle a single input character. */ DO(true, HSPLIT, split(n, HORIZONTAL)) DO(true, VSPLIT, split(n, VERTICAL)) DO(true, DELETE_NODE, deletenode(n)) + DO(true, ONLY_NODE, onlynode(n)) DO(true, REDRAW, touchwin(stdscr); draw(root); redrawwin(stdscr)) DO(true, SCROLLUP, scrollback(n)) DO(true, SCROLLDOWN, scrollforward(n)) @@ -1171,3 +1192,4 @@ main(int argc, char **argv) quit(EXIT_SUCCESS, NULL); return EXIT_SUCCESS; /* not reached */ } +