8000 Add a clear-screen bind function to clear the screen by faho · Pull Request #10044 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc_src/cmds/bind.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ The following special input functions are available:
``capitalize-word``
make the current word begin with a capital letter

``clear-screen``
clears the screen and redraws the prompt. if the terminal doesn't support clearing the screen it is the same as ``repaint``.

``complete``
guess the remainder of the current token

Expand Down
4 changes: 1 addition & 3 deletions share/functions/__fish_shared_key_bindings.fish
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod
bind --preset $argv \el __fish_list_current_token
bind --preset $argv \eo __fish_preview_current_file
bind --preset $argv \ew __fish_whatis_current_token
# ncurses > 6.0 sends a "delete scrollback" sequence along with clear.
# This string replace removes it.
bind --preset $argv \cl 'echo -n (clear | string replace \e\[3J ""); commandline -f repaint'
bind --preset $argv \cl clear-screen
bind --preset $argv \cc cancel-commandline
bind --preset $argv \cu backward-kill-line
bind --preset $argv \cw backward-kill-path-component
Expand Down
1 change: 1 addition & 0 deletions src/input.cpp
8000
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static constexpr const input_function_metadata_t input_function_metadata[] = {
{L"cancel", readline_cmd_t::cancel},
{L"cancel-commandline", readline_cmd_t::cancel_commandline},
{L"capitalize-word", readline_cmd_t::capitalize_word},
{L"clear-screen", readline_cmd_t::clear_screen_and_repaint},
{L"complete", readline_cmd_t::complete},
{L"complete-and-search", readline_cmd_t::complete_and_search},
{L"delete-char", readline_cmd_t::delete_char},
Expand Down
2 changes: 2 additions & 0 deletions src/input_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ enum class readline_cmd_t {
end_undo_group,
repeat_jump,
disable_mouse_tracking,
// ncurses uses the obvious name
clear_screen_and_repaint,
// NOTE: This one has to be last.
reverse_repeat_jump
};
Expand Down
21 changes: 21 additions & 0 deletions src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4339,6 +4339,27 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
outp.writestr(L"\x1B[?1000l");
break;
}
case rl::clear_screen_and_repaint: {
parser().libdata().is_repaint = true;
auto clear = screen_clear();
if (!clear.empty()) {
// Clear the screen if we can.
// This is subtle: We first clear, draw the old prompt,
// and *then* reexecute the prompt and overdraw it.
// This removes the flicker,
// while keeping the prompt up-to-date.
outputter_t &outp = stdoutput();
outp.writestr(clear.c_str());
screen.reset_line(true /* redraw prompt */);
this->layout_and_repaint(L"readline");
}
exec_prompt();
screen.reset_line(true /* redraw prompt */);
this->layout_and_repaint(L"readline");
force_exec_prompt_and_repaint = false;
parser().libdata().is_repaint = false;
break;
}
// Some commands should have been handled internally by inputter_t::readch().
case rl::self_insert:
case rl::self_insert_notfirst:
Expand Down
7 changes: 7 additions & 0 deletions src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ maybe_t<size_t> escape_code_length(const wchar_t *code) {
return found ? maybe_t<size_t>{esc_seq_len} : none();
}

wcstring screen_clear() {
if (clear_screen) {
return str2wcstring(clear_screen);
}
return wcstring{};
}

long escape_code_length_ffi(const wchar_t *code) {
auto found = escape_code_length(code);
return found.has_value() ? (long)*found : -1;
Expand Down
1 change: 1 addition & 0 deletions src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,6 @@ maybe_t<size_t> escape_code_length(const wchar_t *code);
// Always return a value, by moving checking of sequence start to the caller.
long escape_code_length_ffi(const wchar_t *code);

wcstring screen_clear();
void screen_set_midnight_commander_hack();
#endif
0