1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

LibVT+Everywhere: Introduce 'automarks' and 'clear previous command'

Automarks are similar to bookmarks placed by the terminal, allowing the
user to selectively remove a single command and its output from the
terminal scrollback.
This commit implements a single way to add marks: automatically placing
them when the shell becomes interactive.

To make sure the shell behaves correctly after its expected prompt
position changes, the terminal layer forces a resize event to be passed
to the shell on such (possibly) partial clears; this also has the nice
side effect of fixing the disappearing prompt on the preexisting "clear
including history" action: Fixes #4192.
This commit is contained in:
Ali Mohammad Pur 2024-02-06 01:41:35 +03:30 committed by Ali Mohammad Pur
parent cde528fdd9
commit 54ab6fe5b9
12 changed files with 238 additions and 0 deletions

View file

@ -284,6 +284,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_obey_widget_min_size(false);
auto terminal = window->set_main_widget<VT::TerminalWidget>(ptm_fd, true);
terminal->set_startup_process_id(shell_pid);
terminal->on_command_exit = [&] {
app->quit(0);
};
@ -309,6 +311,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
terminal->set_bell_mode(VT::TerminalWidget::BellMode::Visible);
}
auto automark = Config::read_string("Terminal"sv, "Terminal"sv, "AutoMark"sv, "MarkInteractiveShellPrompt"sv);
if (automark == "MarkNothing") {
terminal->set_auto_mark_mode(VT::TerminalWidget::AutoMarkMode::MarkNothing);
} else {
terminal->set_auto_mark_mode(VT::TerminalWidget::AutoMarkMode::MarkInteractiveShellPrompt);
}
auto cursor_shape = VT::TerminalWidget::parse_cursor_shape(Config::read_string("Terminal"sv, "Cursor"sv, "Shape"sv, "Block"sv)).value_or(VT::CursorShape::Block);
terminal->set_cursor_shape(cursor_shape);
@ -399,6 +408,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_fullscreen(!window->is_fullscreen());
}));
view_menu->add_action(terminal->clear_including_history_action());
view_menu->add_action(terminal->clear_to_previous_mark_action());
auto adjust_font_size = [&](float adjustment, Gfx::Font::AllowInexactSizeMatch preference) {
auto& font = terminal->font();

View file

@ -40,10 +40,15 @@ ErrorOr<void> MainWidget::setup()
auto& beep_bell_radio = *find_descendant_of_type_named<GUI::RadioButton>("beep_bell_radio");
auto& visual_bell_radio = *find_descendant_of_type_named<GUI::RadioButton>("visual_bell_radio");
auto& no_bell_radio = *find_descendant_of_type_named<GUI::RadioButton>("no_bell_radio");
auto& automark_off_radio = *find_descendant_of_type_named<GUI::RadioButton>("automark_of");
auto& automark_on_interactive_prompt_radio = *find_descendant_of_type_named<GUI::RadioButton>("automark_on_interactive_prompt");
m_bell_mode = parse_bell(Config::read_string("Terminal"sv, "Window"sv, "Bell"sv));
m_original_bell_mode = m_bell_mode;
m_automark_mode = parse_automark_mode(Config::read_string("Terminal"sv, "Terminal"sv, "AutoMark"sv));
m_original_automark_mode = m_automark_mode;
switch (m_bell_mode) {
case VT::TerminalWidget::BellMode::Visible:
visual_bell_radio.set_checked(true, GUI::AllowCallback::No);
@ -72,6 +77,26 @@ ErrorOr<void> MainWidget::setup()
set_modified(true);
};
switch (m_automark_mode) {
case VT::TerminalWidget::AutoMarkMode::MarkNothing:
automark_off_radio.set_checked(true, GUI::AllowCallback::No);
break;
case VT::TerminalWidget::AutoMarkMode::MarkInteractiveShellPrompt:
automark_on_interactive_prompt_radio.set_checked(true, GUI::AllowCallback::No);
break;
}
automark_off_radio.on_checked = [this](bool) {
m_automark_mode = VT::TerminalWidget::AutoMarkMode::MarkNothing;
Config::write_string("Terminal"sv, "Terminal"sv, "AutoMark"sv, stringify_automark_mode(m_automark_mode));
set_modified(true);
};
automark_on_interactive_prompt_radio.on_checked = [this](bool) {
m_automark_mode = VT::TerminalWidget::AutoMarkMode::MarkInteractiveShellPrompt;
Config::write_string("Terminal"sv, "Terminal"sv, "AutoMark"sv, stringify_automark_mode(m_automark_mode));
set_modified(true);
};
m_confirm_close = Config::read_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, true);
m_orignal_confirm_close = m_confirm_close;
auto& confirm_close_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("terminal_confirm_close");
@ -106,6 +131,24 @@ ByteString MainWidget::stringify_bell(VT::TerminalWidget::BellMode bell_mode)
VERIFY_NOT_REACHED();
}
VT::TerminalWidget::AutoMarkMode MainWidget::parse_automark_mode(StringView automark_mode)
{
if (automark_mode == "MarkNothing")
return VT::TerminalWidget::AutoMarkMode::MarkNothing;
if (automark_mode == "MarkInteractiveShellPrompt")
return VT::TerminalWidget::AutoMarkMode::MarkInteractiveShellPrompt;
VERIFY_NOT_REACHED();
}
ByteString MainWidget::stringify_automark_mode(VT::TerminalWidget::AutoMarkMode automark_mode)
{
if (automark_mode == VT::TerminalWidget::AutoMarkMode::MarkNothing)
return "MarkNothing";
if (automark_mode == VT::TerminalWidget::AutoMarkMode::MarkInteractiveShellPrompt)
return "MarkInteractiveShellPrompt";
VERIFY_NOT_REACHED();
}
void MainWidget::apply_settings()
{
m_original_bell_mode = m_bell_mode;

View file

@ -29,12 +29,16 @@ private:
void write_back_settings() const;
static VT::TerminalWidget::BellMode parse_bell(StringView bell_string);
static VT::TerminalWidget::AutoMarkMode parse_automark_mode(StringView automark_mode);
static ByteString stringify_bell(VT::TerminalWidget::BellMode bell_mode);
static ByteString stringify_automark_mode(VT::TerminalWidget::AutoMarkMode automark_mode);
VT::TerminalWidget::BellMode m_bell_mode { VT::TerminalWidget::BellMode::Disabled };
VT::TerminalWidget::AutoMarkMode m_automark_mode { VT::TerminalWidget::AutoMarkMode::MarkInteractiveShellPrompt };
bool m_confirm_close { true };
VT::TerminalWidget::BellMode m_original_bell_mode;
VT::TerminalWidget::AutoMarkMode m_original_automark_mode;
bool m_orignal_confirm_close { true };
};
}

View file

@ -48,4 +48,22 @@
text: "Confirm exit when process is active"
}
}
@GUI::GroupBox {
title: "Auto-mark behavior"
preferred_height: "fit"
layout: @GUI::VerticalBoxLayout {
margins: [8]
}
@GUI::RadioButton {
name: "automark_off"
text: "Do not auto-mark"
}
@GUI::RadioButton {
name: "automark_on_interactive_prompt"
text: "Auto-mark on interactive shell prompts"
}
}
}