diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-05-28 21:26:39 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-04 09:02:43 +0100 |
commit | acbd1d14d0ca8ea063a9acaec988913557acd22b (patch) | |
tree | c5b38b2d961a6e0dc96bce594159e8af9710ca4c /Userland/Applications | |
parent | 99033876ec6fc7484d7967d6cbd64f79669c21f7 (diff) | |
download | serenity-acbd1d14d0ca8ea063a9acaec988913557acd22b.zip |
LibVT+Terminal: Add color scheme support
This commit introduces color scheme support to Terminal. These are found
in `/res/terminal_colors` and the default color scheme can be set in
`~/.config/Terminal.ini`. Furthermore, a combo box is added for
setting the color scheme at runtime.
The previously used default color scheme has been added to
`/res/terminal-colors/Default.ini`.
To make the implementation more compatible with other color schemes,
`TerminalWidget` now supports overriding the default foreground and
background colors.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Terminal/TerminalSettingsWindow.gml | 13 | ||||
-rw-r--r-- | Userland/Applications/Terminal/main.cpp | 25 |
2 files changed, 37 insertions, 1 deletions
diff --git a/Userland/Applications/Terminal/TerminalSettingsWindow.gml b/Userland/Applications/Terminal/TerminalSettingsWindow.gml index 07b8400c56..6c906fd463 100644 --- a/Userland/Applications/Terminal/TerminalSettingsWindow.gml +++ b/Userland/Applications/Terminal/TerminalSettingsWindow.gml @@ -60,4 +60,17 @@ orientation: "Horizontal" } } + + @GUI::GroupBox { + title: "Color scheme" + shrink_to_fit: true + + layout: @GUI::VerticalBoxLayout { + margins: [6, 16, 6, 6] + } + + @GUI::ComboBox { + name: "color_scheme_combo" + } + } } diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 846b0ffdd2..dd8fc9e325 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -4,10 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/QuickSort.h> #include <AK/URL.h> #include <Applications/Terminal/TerminalSettingsWindowGML.h> #include <LibCore/ArgsParser.h> #include <LibCore/ConfigFile.h> +#include <LibCore/DirIterator.h> #include <LibCore/File.h> #include <LibDesktop/Launcher.h> #include <LibGUI/Action.h> @@ -16,9 +18,11 @@ #include <LibGUI/BoxLayout.h> #include <LibGUI/Button.h> #include <LibGUI/CheckBox.h> +#include <LibGUI/ComboBox.h> #include <LibGUI/Event.h> #include <LibGUI/FontPicker.h> #include <LibGUI/Icon.h> +#include <LibGUI/ItemListModel.h> #include <LibGUI/Menu.h> #include <LibGUI/Menubar.h> #include <LibGUI/OpacitySlider.h> @@ -105,7 +109,7 @@ static RefPtr<GUI::Window> create_settings_window(VT::TerminalWidget& terminal) window->set_window_type(GUI::WindowType::ToolWindow); window->set_title("Terminal settings"); window->set_resizable(false); - window->resize(200, 210); + window->resize(200, 240); window->center_within(*terminal.window()); auto& settings = window->set_main_widget<GUI::Widget>(); @@ -149,6 +153,25 @@ static RefPtr<GUI::Window> create_settings_window(VT::TerminalWidget& terminal) terminal.set_max_history_size(value); }; + // 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<String> color_scheme_names; + color_scheme_names.clear(); + Core::DirIterator iterator("/res/terminal-colors", Core::DirIterator::SkipParentAndBaseDir); + while (iterator.has_next()) { + auto path = iterator.next_path(); + path.replace(".ini", ""); + color_scheme_names.append(path); + } + quick_sort(color_scheme_names); + auto& color_scheme_combo = *settings.find_descendant_of_type_named<GUI::ComboBox>("color_scheme_combo"); + color_scheme_combo.set_only_allow_values_from_model(true); + color_scheme_combo.set_model(*GUI::ItemListModel<String>::create(color_scheme_names)); + color_scheme_combo.set_selected_index(color_scheme_names.find_first_index(terminal.color_scheme_name()).value()); + color_scheme_combo.on_change = [&](auto&, const GUI::ModelIndex& index) { + terminal.set_color_scheme(index.data().as_string()); + }; return window; } |