Skip to content

Commit 762cace

Browse files
committed
[textinput] add hotkeys to increase/decrease the multi-line prompt size
1 parent 1694119 commit 762cace

6 files changed

Lines changed: 55 additions & 0 deletions

File tree

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ Features:
2626
- `⌘-X` to cut the current selection to the
2727
clipboard.
2828
- `⌘-Z` to undo the last change.
29+
* The multi-line prompt can now be resized with the
30+
keyboard: `ALT-=` grows the prompt by one line and
31+
`ALT--` shrinks it by one line. This complements
32+
the existing click-and-drag resize on the prompt's
33+
status bar.
2934
* Additional readline-style key bindings in the
3035
prompt (issue #1676):
3136
- `ALT-f` / `ALT-b` move forward/backward by word.

docs/source/hotkeys.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ editing:
460460
-
461461
- In search mode, search for the previous occurrence. Otherwise,
462462
search history using current contents of the prompt
463+
* - :kbd:`Alt` + :kbd:`=`
464+
-
465+
- In multi-line mode, grow the prompt by one line. The prompt's
466+
status bar can also be dragged with the mouse to resize.
467+
* - :kbd:`Alt` + :kbd:`-`
468+
-
469+
- In multi-line mode, shrink the prompt by one line.
463470

464471
Customizing
465472
-----------

src/lnav.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,17 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
17511751
= std::max(2, full_height - (prompt.p_editor.get_y() + me.me_y));
17521752
prompt.p_editor.set_height(std::min(max_height, new_height));
17531753
};
1754+
lnav::prompt::get().p_editor.tc_on_height_change
1755+
= [](textinput_curses& tc, int delta) {
1756+
if (tc.tc_height == 1) {
1757+
return;
1758+
}
1759+
auto full_height = (int) ncplane_dim_y(tc.tc_window);
1760+
auto max_height = std::max(2, full_height - 16);
1761+
auto new_height
1762+
= std::clamp(tc.tc_height + delta, 2, max_height);
1763+
tc.set_height(new_height);
1764+
};
17541765
lnav_data.ld_bottom_source.get_field(bottom_status_source::BSF_HELP)
17551766
.on_click
17561767
= [](status_field&) { ensure_view(&lnav_data.ld_views[LNV_HELP]); };

src/textinput_curses.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ textinput_curses::get_help_text()
168168
.append("CTRL-O"_hotkey)
169169
.append(" - Open the contents in an external editor\n")
170170
.append("\n")
171+
.append("Resizing"_h2)
172+
.append("\n ")
173+
.append(""_list_glyph)
174+
.append(" ")
175+
.append("ALT-="_hotkey)
176+
.append(
177+
" - Grow the multi-line prompt by one line\n ")
178+
.append(""_list_glyph)
179+
.append(" ")
180+
.append("ALT--"_hotkey)
181+
.append(
182+
" - Shrink the multi-line prompt by one line\n")
183+
.append("\n")
171184
.append("History"_h2)
172185
.append("\n ")
173186
.append("\u2022"_list_glyph)
@@ -1160,6 +1173,20 @@ textinput_curses::handle_key(const ncinput& ch)
11601173
this->change_word_case(uc_toupper);
11611174
return true;
11621175
}
1176+
case '=':
1177+
case '+': {
1178+
if (this->tc_on_height_change) {
1179+
this->tc_on_height_change(*this, 1);
1180+
}
1181+
return true;
1182+
}
1183+
case '-':
1184+
case '_': {
1185+
if (this->tc_on_height_change) {
1186+
this->tc_on_height_change(*this, -1);
1187+
}
1188+
return true;
1189+
}
11631190
}
11641191
}
11651192

src/textinput_curses.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ public:
525525
std::function<void(textinput_curses&)> tc_on_reformat;
526526
std::function<void(textinput_curses&)> tc_on_perform;
527527
std::function<void(textinput_curses&)> tc_on_external_open;
528+
std::function<void(textinput_curses&, int)> tc_on_height_change;
528529
};
529530

530531
#endif

src/third-party/notcurses/src/lib/in.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ prep_xtmodkeys(inputctx* ictx){
220220
.modifiers = NCKEY_MOD_ALT },
221221
{ .esc = "\033z", .key = 'z',
222222
.modifiers = NCKEY_MOD_ALT },
223+
{ .esc = "\033-", .key = '-',
224+
.modifiers = NCKEY_MOD_ALT },
225+
{ .esc = "\033=", .key = '=',
226+
.modifiers = NCKEY_MOD_ALT },
223227
{ .esc = "\033\x7f", .key = NCKEY_BACKSPACE,
224228
.modifiers = NCKEY_MOD_ALT },
225229

0 commit comments

Comments
 (0)