mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-01 20:10:28 +00:00
Terminal+TerminalSettings: Add caret customization
This commit is contained in:
parent
e2b0f6795f
commit
e9dae38f38
Notes:
sideshowbarker
2024-07-17 10:02:14 +09:00
Author: https://github.com/cocateh Commit: https://github.com/SerenityOS/serenity/commit/e9dae38f38 Pull-request: https://github.com/SerenityOS/serenity/pull/14012 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/BertalanD
6 changed files with 103 additions and 2 deletions
|
@ -7,3 +7,6 @@ MaxHistorySize=1024
|
|||
Opacity=255
|
||||
Bell=Visible
|
||||
ColorScheme=Default
|
||||
[Cursor]
|
||||
Shape=Block
|
||||
Blinking=true
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
m_parent_terminal.set_show_scrollbar(value);
|
||||
else if (key == "ConfirmClose" && on_confirm_close_changed)
|
||||
on_confirm_close_changed(value);
|
||||
} else if (group == "Cursor" && key == "Blinking") {
|
||||
m_parent_terminal.set_cursor_blinking(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +90,9 @@ public:
|
|||
font = Gfx::FontDatabase::default_fixed_width_font();
|
||||
m_parent_terminal.set_font_and_resize_to_fit(*font);
|
||||
m_parent_terminal.window()->resize(m_parent_terminal.size());
|
||||
} else if (group == "Cursor" && key == "Shape") {
|
||||
auto cursor_shape = VT::TerminalWidget::parse_cursor_shape(value).value_or(VT::CursorShape::Block);
|
||||
m_parent_terminal.set_cursor_shape(cursor_shape);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,6 +319,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
terminal->set_bell_mode(VT::TerminalWidget::BellMode::Visible);
|
||||
}
|
||||
|
||||
auto cursor_shape = VT::TerminalWidget::parse_cursor_shape(Config::read_string("Terminal", "Cursor", "Shape", "Block")).value_or(VT::CursorShape::Block);
|
||||
terminal->set_cursor_shape(cursor_shape);
|
||||
|
||||
auto cursor_blinking = Config::read_bool("Terminal", "Cursor", "Blinking", true);
|
||||
terminal->set_cursor_blinking(cursor_blinking);
|
||||
|
||||
auto find_window = TRY(create_find_window(terminal));
|
||||
|
||||
auto new_opacity = Config::read_i32("Terminal", "Window", "Opacity", 255);
|
||||
|
|
|
@ -15,4 +15,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_app(TerminalSettings ICON app-terminal)
|
||||
target_link_libraries(TerminalSettings LibGUI LibConfig LibMain)
|
||||
target_link_libraries(TerminalSettings LibGUI LibConfig LibMain LibVT)
|
||||
|
|
|
@ -59,6 +59,34 @@
|
|||
}
|
||||
}
|
||||
|
||||
@GUI::GroupBox {
|
||||
title: "Cursor settings"
|
||||
shrink_to_fit: true
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [16, 8, 8]
|
||||
}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "terminal_cursor_block"
|
||||
text: "Block cursor"
|
||||
}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "terminal_cursor_underline"
|
||||
text: "Underline cursor"
|
||||
}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "terminal_cursor_bar"
|
||||
text: "Bar cursor"
|
||||
}
|
||||
|
||||
@GUI::CheckBox {
|
||||
name: "terminal_cursor_blinking"
|
||||
text: "Blinking cursor"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::GroupBox {
|
||||
title: "Color Scheme"
|
||||
fixed_height: 70
|
||||
|
|
|
@ -181,6 +181,57 @@ TerminalSettingsViewWidget::TerminalSettingsViewWidget()
|
|||
// whether that was filled in by the above defaulting code or by the user.
|
||||
use_default_font_button.set_checked(m_font == Gfx::FontDatabase::the().default_fixed_width_font(), GUI::AllowCallback::No);
|
||||
font_selection.set_enabled(!use_default_font_button.is_checked());
|
||||
|
||||
auto& terminal_cursor_block = *find_descendant_of_type_named<GUI::RadioButton>("terminal_cursor_block");
|
||||
auto& terminal_cursor_underline = *find_descendant_of_type_named<GUI::RadioButton>("terminal_cursor_underline");
|
||||
auto& terminal_cursor_bar = *find_descendant_of_type_named<GUI::RadioButton>("terminal_cursor_bar");
|
||||
|
||||
auto& terminal_cursor_blinking = *find_descendant_of_type_named<GUI::CheckBox>("terminal_cursor_blinking");
|
||||
|
||||
m_cursor_shape = VT::TerminalWidget::parse_cursor_shape(Config::read_string("Terminal", "Cursor", "Shape")).value_or(VT::CursorShape::Block);
|
||||
m_original_cursor_shape = m_cursor_shape;
|
||||
|
||||
m_cursor_is_blinking_set = Config::read_bool("Terminal", "Cursor", "Blinking", true);
|
||||
m_original_cursor_is_blinking_set = m_cursor_is_blinking_set;
|
||||
|
||||
switch (m_cursor_shape) {
|
||||
case VT::CursorShape::Underline:
|
||||
terminal_cursor_underline.set_checked(true);
|
||||
break;
|
||||
case VT::CursorShape::Bar:
|
||||
terminal_cursor_bar.set_checked(true);
|
||||
break;
|
||||
default:
|
||||
terminal_cursor_block.set_checked(true);
|
||||
}
|
||||
|
||||
terminal_cursor_blinking.on_checked = [&](bool is_checked) {
|
||||
set_modified(true);
|
||||
m_cursor_is_blinking_set = is_checked;
|
||||
Config::write_bool("Terminal", "Cursor", "Blinking", is_checked);
|
||||
};
|
||||
terminal_cursor_blinking.set_checked(Config::read_bool("Terminal", "Cursor", "Blinking", true));
|
||||
|
||||
terminal_cursor_block.on_checked = [&](bool) {
|
||||
set_modified(true);
|
||||
m_cursor_shape = VT::CursorShape::Block;
|
||||
Config::write_string("Terminal", "Cursor", "Shape", "Block");
|
||||
};
|
||||
terminal_cursor_block.set_checked(Config::read_string("Terminal", "Cursor", "Shape") == "Block");
|
||||
|
||||
terminal_cursor_underline.on_checked = [&](bool) {
|
||||
set_modified(true);
|
||||
m_cursor_shape = VT::CursorShape::Underline;
|
||||
Config::write_string("Terminal", "Cursor", "Shape", "Underline");
|
||||
};
|
||||
terminal_cursor_underline.set_checked(Config::read_string("Terminal", "Cursor", "Shape") == "Underline");
|
||||
|
||||
terminal_cursor_bar.on_checked = [&](bool) {
|
||||
set_modified(true);
|
||||
m_cursor_shape = VT::CursorShape::Bar;
|
||||
Config::write_string("Terminal", "Cursor", "Shape", "Bar");
|
||||
};
|
||||
terminal_cursor_bar.set_checked(Config::read_string("Terminal", "Cursor", "Shape") == "Bar");
|
||||
}
|
||||
|
||||
VT::TerminalWidget::BellMode TerminalSettingsMainWidget::parse_bell(StringView bell_string)
|
||||
|
@ -231,6 +282,8 @@ void TerminalSettingsViewWidget::apply_settings()
|
|||
m_original_opacity = m_opacity;
|
||||
m_original_font = m_font;
|
||||
m_original_color_scheme = m_color_scheme;
|
||||
m_original_cursor_shape = m_cursor_shape;
|
||||
m_original_cursor_is_blinking_set = m_cursor_is_blinking_set;
|
||||
write_back_settings();
|
||||
}
|
||||
|
||||
|
@ -239,6 +292,8 @@ void TerminalSettingsViewWidget::write_back_settings() const
|
|||
Config::write_i32("Terminal", "Window", "Opacity", static_cast<i32>(m_original_opacity));
|
||||
Config::write_string("Terminal", "Text", "Font", m_original_font->qualified_name());
|
||||
Config::write_string("Terminal", "Window", "ColorScheme", m_original_color_scheme);
|
||||
Config::write_string("Terminal", "Cursor", "Shape", VT::TerminalWidget::stringify_cursor_shape(m_original_cursor_shape));
|
||||
Config::write_bool("Terminal", "Cursor", "Blinking", m_original_cursor_is_blinking_set);
|
||||
}
|
||||
|
||||
void TerminalSettingsViewWidget::cancel_settings()
|
||||
|
|
|
@ -26,7 +26,7 @@ private:
|
|||
static VT::TerminalWidget::BellMode parse_bell(StringView bell_string);
|
||||
static String stringify_bell(VT::TerminalWidget::BellMode bell_mode);
|
||||
|
||||
VT::TerminalWidget::BellMode m_bell_mode = VT::TerminalWidget::BellMode::Disabled;
|
||||
VT::TerminalWidget::BellMode m_bell_mode { VT::TerminalWidget::BellMode::Disabled };
|
||||
size_t m_max_history_size;
|
||||
bool m_show_scrollbar { true };
|
||||
bool m_confirm_close { true };
|
||||
|
@ -50,8 +50,12 @@ private:
|
|||
RefPtr<Gfx::Font> m_font;
|
||||
float m_opacity;
|
||||
String m_color_scheme;
|
||||
VT::CursorShape m_cursor_shape { VT::CursorShape::Block };
|
||||
bool m_cursor_is_blinking_set { true };
|
||||
|
||||
RefPtr<Gfx::Font> m_original_font;
|
||||
float m_original_opacity;
|
||||
String m_original_color_scheme;
|
||||
VT::CursorShape m_original_cursor_shape;
|
||||
bool m_original_cursor_is_blinking_set;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue