diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 0f6f7bea0c..43a1b5f662 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -72,19 +72,15 @@ public: { VERIFY(domain == "Terminal"); - if (group == "Window") { - if (key == "Bell") { - auto bell_mode = VT::TerminalWidget::BellMode::Visible; - if (value == "AudibleBeep") - bell_mode = VT::TerminalWidget::BellMode::AudibleBeep; - if (value == "Visible") - bell_mode = VT::TerminalWidget::BellMode::Visible; - if (value == "Disabled") - bell_mode = VT::TerminalWidget::BellMode::Disabled; - m_parent_terminal.set_bell_mode(bell_mode); - } else if (key == "ColorScheme") { - m_parent_terminal.set_color_scheme(value); - } + if (group == "Window" && key == "Bell") { + auto bell_mode = VT::TerminalWidget::BellMode::Visible; + if (value == "AudibleBeep") + bell_mode = VT::TerminalWidget::BellMode::AudibleBeep; + if (value == "Visible") + bell_mode = VT::TerminalWidget::BellMode::Visible; + if (value == "Disabled") + bell_mode = VT::TerminalWidget::BellMode::Disabled; + m_parent_terminal.set_bell_mode(bell_mode); } else if (group == "Text" && key == "Font") { auto font = Gfx::FontDatabase::the().get_by_name(value); if (font.is_null()) diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsView.gml b/Userland/Applications/TerminalSettings/TerminalSettingsView.gml index db20b83ee9..0a2eedfc00 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsView.gml +++ b/Userland/Applications/TerminalSettings/TerminalSettingsView.gml @@ -85,17 +85,4 @@ text: "Blinking cursor" } } - - @GUI::GroupBox { - title: "Color Scheme" - preferred_height: "fit" - layout: @GUI::VerticalBoxLayout { - margins: [16, 8, 8] - spacing: 16 - } - - @GUI::ComboBox { - name: "color_scheme_combo" - } - } } diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp b/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp index 178c9b2520..be38f8b819 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp +++ b/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp @@ -114,30 +114,6 @@ TerminalSettingsViewWidget::TerminalSettingsViewWidget() set_modified(true); }; - m_color_scheme = Config::read_string("Terminal"sv, "Window"sv, "ColorScheme"sv); - m_original_color_scheme = m_color_scheme; - // The settings window takes a reference to this vector, so it needs to outlive this scope. - // As long as we ensure that only one settings window may be open at a time (which we do), - // this should cause no problems. - static Vector color_scheme_names; - color_scheme_names.clear(); - Core::DirIterator iterator("/res/color-schemes", Core::DirIterator::SkipParentAndBaseDir); - while (iterator.has_next()) { - auto path = iterator.next_path(); - color_scheme_names.append(path.replace(".ini"sv, ""sv, ReplaceMode::FirstOnly)); - } - quick_sort(color_scheme_names); - auto& color_scheme_combo = *find_descendant_of_type_named("color_scheme_combo"); - color_scheme_combo.set_only_allow_values_from_model(true); - color_scheme_combo.set_model(*GUI::ItemListModel::create(color_scheme_names)); - color_scheme_combo.set_selected_index(color_scheme_names.find_first_index(m_color_scheme).value()); - color_scheme_combo.set_enabled(color_scheme_names.size() > 1); - color_scheme_combo.on_change = [&](auto&, const GUI::ModelIndex& index) { - m_color_scheme = index.data().as_string(); - Config::write_string("Terminal"sv, "Window"sv, "ColorScheme"sv, m_color_scheme); - set_modified(true); - }; - auto& font_button = *find_descendant_of_type_named("terminal_font_button"); auto& font_text = *find_descendant_of_type_named("terminal_font_label"); auto font_name = Config::read_string("Terminal"sv, "Text"sv, "Font"sv); @@ -281,7 +257,6 @@ 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(); @@ -291,7 +266,6 @@ void TerminalSettingsViewWidget::write_back_settings() const { Config::write_i32("Terminal"sv, "Window"sv, "Opacity"sv, static_cast(m_original_opacity)); Config::write_string("Terminal"sv, "Text"sv, "Font"sv, m_original_font->qualified_name()); - Config::write_string("Terminal"sv, "Window"sv, "ColorScheme"sv, m_original_color_scheme); Config::write_string("Terminal"sv, "Cursor"sv, "Shape"sv, VT::TerminalWidget::stringify_cursor_shape(m_original_cursor_shape)); Config::write_bool("Terminal"sv, "Cursor"sv, "Blinking"sv, m_original_cursor_is_blinking_set); } diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index 89b15a97cb..60a95add7e 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -148,8 +148,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy) update_copy_action(); update_paste_action(); - - set_color_scheme(Config::read_string("Terminal"sv, "Window"sv, "ColorScheme"sv, "Default"sv)); + update_color_scheme(); } Gfx::IntRect TerminalWidget::glyph_rect(u16 row, u16 column) @@ -197,7 +196,9 @@ void TerminalWidget::focusout_event(GUI::FocusEvent& event) void TerminalWidget::event(Core::Event& event) { - if (event.type() == GUI::Event::WindowBecameActive) + if (event.type() == GUI::Event::ThemeChange) + update_color_scheme(); + else if (event.type() == GUI::Event::WindowBecameActive) set_logical_focus(true); else if (event.type() == GUI::Event::WindowBecameInactive) set_logical_focus(false); @@ -1198,59 +1199,32 @@ void TerminalWidget::update_paste_action() m_paste_action->set_enabled(mime_type.starts_with("text/"sv) && !data.is_empty()); } -void TerminalWidget::set_color_scheme(StringView name) +void TerminalWidget::update_color_scheme() { - if (name.contains('/')) { - dbgln("Shenanigans! Color scheme names can't contain slashes."); - return; - } + auto const& palette = GUI::Widget::palette(); - m_color_scheme_name = name; + m_show_bold_text_as_bright = palette.bold_text_as_bright(); - constexpr StringView color_names[] = { - "Black"sv, - "Red"sv, - "Green"sv, - "Yellow"sv, - "Blue"sv, - "Magenta"sv, - "Cyan"sv, - "White"sv - }; + m_default_background_color = palette.background(); + m_default_foreground_color = palette.foreground(); - auto path = DeprecatedString::formatted("/res/color-schemes/{}.ini", name); - auto color_config_or_error = Core::ConfigFile::open(path); - if (color_config_or_error.is_error()) { - dbgln("Unable to read color scheme file '{}': {}", path, color_config_or_error.error()); - return; - } - auto color_config = color_config_or_error.release_value(); + m_colors[0] = palette.black(); + m_colors[1] = palette.red(); + m_colors[2] = palette.green(); + m_colors[3] = palette.yellow(); + m_colors[4] = palette.blue(); + m_colors[5] = palette.magenta(); + m_colors[6] = palette.cyan(); + m_colors[7] = palette.white(); + m_colors[8] = palette.bright_black(); + m_colors[9] = palette.bright_red(); + m_colors[10] = palette.bright_green(); + m_colors[11] = palette.bright_yellow(); + m_colors[12] = palette.bright_blue(); + m_colors[13] = palette.bright_magenta(); + m_colors[14] = palette.bright_cyan(); + m_colors[15] = palette.bright_white(); - m_show_bold_text_as_bright = color_config->read_bool_entry("Options", "ShowBoldTextAsBright", true); - - auto default_background = Gfx::Color::from_string(color_config->read_entry("Primary", "Background")); - if (default_background.has_value()) - m_default_background_color = default_background.value(); - else - m_default_background_color = Gfx::Color::from_rgb(m_colors[(u8)VT::Color::ANSIColor::Black]); - - auto default_foreground = Gfx::Color::from_string(color_config->read_entry("Primary", "Foreground")); - if (default_foreground.has_value()) - m_default_foreground_color = default_foreground.value(); - else - m_default_foreground_color = Gfx::Color::from_rgb(m_colors[(u8)VT::Color::ANSIColor::White]); - - for (u8 color_idx = 0; color_idx < 8; ++color_idx) { - auto rgb = Gfx::Color::from_string(color_config->read_entry("Normal", color_names[color_idx])); - if (rgb.has_value()) - m_colors[color_idx] = rgb.value().value(); - } - - for (u8 color_idx = 0; color_idx < 8; ++color_idx) { - auto rgb = Gfx::Color::from_string(color_config->read_entry("Bright", color_names[color_idx])); - if (rgb.has_value()) - m_colors[color_idx + 8] = rgb.value().value(); - } update(); } @@ -1268,11 +1242,11 @@ constexpr Gfx::Color TerminalWidget::terminal_color_to_rgb(VT::Color color) cons case VT::Color::Kind::RGB: return Gfx::Color::from_rgb(color.as_rgb()); case VT::Color::Kind::Indexed: - return Gfx::Color::from_rgb(m_colors[color.as_indexed()]); + return m_colors[color.as_indexed()]; case VT::Color::Kind::Named: { auto ansi = color.as_named(); if ((u16)ansi < 256) - return Gfx::Color::from_rgb(m_colors[(u16)ansi]); + return m_colors[(u16)ansi]; else if (ansi == VT::Color::ANSIColor::DefaultForeground) return m_default_foreground_color; else if (ansi == VT::Color::ANSIColor::DefaultBackground) diff --git a/Userland/Libraries/LibVT/TerminalWidget.h b/Userland/Libraries/LibVT/TerminalWidget.h index 1a128d484f..8f0f13847b 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.h +++ b/Userland/Libraries/LibVT/TerminalWidget.h @@ -94,7 +94,7 @@ public: void set_font_and_resize_to_fit(Gfx::Font const&); - void set_color_scheme(StringView); + void update_color_scheme(); void set_logical_focus(bool); @@ -174,7 +174,7 @@ private: // Snapshot of m_hovered_href when opening a context menu for a hyperlink. DeprecatedString m_context_menu_href; - unsigned m_colors[256]; + Gfx::Color m_colors[256]; Gfx::Color m_default_foreground_color; Gfx::Color m_default_background_color; bool m_show_bold_text_as_bright { true };