Skip to content

Commit

Permalink
Terminal+TerminalSettings: Add caret customization
Browse files Browse the repository at this point in the history
  • Loading branch information
cocateh authored and AtkinsSJ committed Jun 22, 2022
1 parent e2b0f67 commit e9dae38
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Base/home/anon/.config/Terminal.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ MaxHistorySize=1024
Opacity=255
Bell=Visible
ColorScheme=Default
[Cursor]
Shape=Block
Blinking=true
11 changes: 11 additions & 0 deletions Userland/Applications/Terminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class TerminalChangeListener : public Config::Listener {
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);
}
}

Expand All @@ -88,6 +90,9 @@ class TerminalChangeListener : public Config::Listener {
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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/TerminalSettings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 28 additions & 0 deletions Userland/Applications/TerminalSettings/TerminalSettingsView.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab {
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 };
Expand All @@ -50,8 +50,12 @@ class TerminalSettingsViewWidget final : public GUI::SettingsWindow::Tab {
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;
};

0 comments on commit e9dae38

Please sign in to comment.