mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
Terminal+LibVT: Use LibConfig instead of Core::ConfigFile
This commit is contained in:
parent
39d9373bca
commit
82d8cd2b87
5 changed files with 21 additions and 35 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,10 +7,9 @@
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <Applications/Terminal/TerminalSettingsWindowGML.h>
|
#include <Applications/Terminal/TerminalSettingsWindowGML.h>
|
||||||
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/File.h>
|
|
||||||
#include <LibCore/Process.h>
|
#include <LibCore/Process.h>
|
||||||
#include <LibDesktop/Launcher.h>
|
#include <LibDesktop/Launcher.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
|
@ -291,9 +290,6 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Core::ConfigFile> config = Core::ConfigFile::open_for_app("Terminal", Core::ConfigFile::AllowWriting::Yes);
|
|
||||||
Core::File::ensure_parent_directories(config->filename());
|
|
||||||
|
|
||||||
int ptm_fd;
|
int ptm_fd;
|
||||||
pid_t shell_pid = forkpty(&ptm_fd, nullptr, nullptr, nullptr);
|
pid_t shell_pid = forkpty(&ptm_fd, nullptr, nullptr, nullptr);
|
||||||
if (shell_pid < 0) {
|
if (shell_pid < 0) {
|
||||||
|
@ -305,7 +301,7 @@ int main(int argc, char** argv)
|
||||||
if (command_to_execute)
|
if (command_to_execute)
|
||||||
run_command(command_to_execute, keep_open);
|
run_command(command_to_execute, keep_open);
|
||||||
else
|
else
|
||||||
run_command(config->read_entry("Startup", "Command", ""), false);
|
run_command(Config::read_string("Terminal", "Startup", "Command", ""), false);
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +315,7 @@ int main(int argc, char** argv)
|
||||||
window->set_background_color(Color::Black);
|
window->set_background_color(Color::Black);
|
||||||
window->set_double_buffering_enabled(false);
|
window->set_double_buffering_enabled(false);
|
||||||
|
|
||||||
auto& terminal = window->set_main_widget<VT::TerminalWidget>(ptm_fd, true, config);
|
auto& terminal = window->set_main_widget<VT::TerminalWidget>(ptm_fd, true);
|
||||||
terminal.on_command_exit = [&] {
|
terminal.on_command_exit = [&] {
|
||||||
app->quit(0);
|
app->quit(0);
|
||||||
};
|
};
|
||||||
|
@ -332,7 +328,7 @@ int main(int argc, char** argv)
|
||||||
terminal.apply_size_increments_to_window(*window);
|
terminal.apply_size_increments_to_window(*window);
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
||||||
auto bell = config->read_entry("Window", "Bell", "Visible");
|
auto bell = Config::read_string("Terminal", "Window", "Bell", "Visible");
|
||||||
if (bell == "AudibleBeep") {
|
if (bell == "AudibleBeep") {
|
||||||
terminal.set_bell_mode(VT::TerminalWidget::BellMode::AudibleBeep);
|
terminal.set_bell_mode(VT::TerminalWidget::BellMode::AudibleBeep);
|
||||||
} else if (bell == "Disabled") {
|
} else if (bell == "Disabled") {
|
||||||
|
@ -344,11 +340,11 @@ int main(int argc, char** argv)
|
||||||
RefPtr<GUI::Window> settings_window;
|
RefPtr<GUI::Window> settings_window;
|
||||||
RefPtr<GUI::Window> find_window;
|
RefPtr<GUI::Window> find_window;
|
||||||
|
|
||||||
auto new_opacity = config->read_num_entry("Window", "Opacity", 255);
|
auto new_opacity = Config::read_i32("Terminal", "Window", "Opacity", 255);
|
||||||
terminal.set_opacity(new_opacity);
|
terminal.set_opacity(new_opacity);
|
||||||
window->set_has_alpha_channel(new_opacity < 255);
|
window->set_has_alpha_channel(new_opacity < 255);
|
||||||
|
|
||||||
auto new_scrollback_size = config->read_num_entry("Terminal", "MaxHistorySize", terminal.max_history_size());
|
auto new_scrollback_size = Config::read_i32("Terminal", "Terminal", "MaxHistorySize", terminal.max_history_size());
|
||||||
terminal.set_max_history_size(new_scrollback_size);
|
terminal.set_max_history_size(new_scrollback_size);
|
||||||
|
|
||||||
auto open_settings_action = GUI::Action::create("&Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"),
|
auto open_settings_action = GUI::Action::create("&Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"),
|
||||||
|
@ -358,8 +354,8 @@ int main(int argc, char** argv)
|
||||||
settings_window->show();
|
settings_window->show();
|
||||||
settings_window->move_to_front();
|
settings_window->move_to_front();
|
||||||
settings_window->on_close = [&]() {
|
settings_window->on_close = [&]() {
|
||||||
config->write_num_entry("Window", "Opacity", terminal.opacity());
|
Config::write_i32("Terminal", "Window", "Opacity", terminal.opacity());
|
||||||
config->write_num_entry("Terminal", "MaxHistorySize", terminal.max_history_size());
|
Config::write_i32("Terminal", "Terminal", "MaxHistorySize", terminal.max_history_size());
|
||||||
|
|
||||||
auto bell = terminal.bell_mode();
|
auto bell = terminal.bell_mode();
|
||||||
auto bell_setting = String::empty();
|
auto bell_setting = String::empty();
|
||||||
|
@ -370,9 +366,7 @@ int main(int argc, char** argv)
|
||||||
} else {
|
} else {
|
||||||
bell_setting = "Visible";
|
bell_setting = "Visible";
|
||||||
}
|
}
|
||||||
config->write_entry("Window", "Bell", bell_setting);
|
Config::write_string("Terminal", "Window", "Bell", bell_setting);
|
||||||
|
|
||||||
config->sync();
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -383,8 +377,7 @@ int main(int argc, char** argv)
|
||||||
if (picker->exec() == GUI::Dialog::ExecOK) {
|
if (picker->exec() == GUI::Dialog::ExecOK) {
|
||||||
terminal.set_font_and_resize_to_fit(*picker->font());
|
terminal.set_font_and_resize_to_fit(*picker->font());
|
||||||
window->resize(terminal.size());
|
window->resize(terminal.size());
|
||||||
config->write_entry("Text", "Font", picker->font()->qualified_name());
|
Config::write_string("Terminal", "Text", "Font", picker->font()->qualified_name());
|
||||||
config->sync();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -468,7 +461,7 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unveil(config->filename().characters(), "rwc") < 0) {
|
if (unveil("/tmp/portal/config", "rw") < 0) {
|
||||||
perror("unveil");
|
perror("unveil");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -476,7 +469,6 @@ int main(int argc, char** argv)
|
||||||
unveil(nullptr, nullptr);
|
unveil(nullptr, nullptr);
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
config->sync();
|
|
||||||
int result = app->exec();
|
int result = app->exec();
|
||||||
dbgln("Exiting terminal, updating utmp");
|
dbgln("Exiting terminal, updating utmp");
|
||||||
utmp_update(pts_name, 0, false);
|
utmp_update(pts_name, 0, false);
|
||||||
|
|
|
@ -162,8 +162,7 @@ TerminalWrapper::TerminalWrapper(bool user_spawned)
|
||||||
{
|
{
|
||||||
set_layout<GUI::VerticalBoxLayout>();
|
set_layout<GUI::VerticalBoxLayout>();
|
||||||
|
|
||||||
RefPtr<Core::ConfigFile> config = Core::ConfigFile::open_for_app("Terminal");
|
m_terminal_widget = add<VT::TerminalWidget>(-1, false);
|
||||||
m_terminal_widget = add<VT::TerminalWidget>(-1, false, config);
|
|
||||||
|
|
||||||
if (user_spawned)
|
if (user_spawned)
|
||||||
run_command("Shell");
|
run_command("Shell");
|
||||||
|
|
|
@ -11,4 +11,4 @@ set(GENERATED_SOURCES
|
||||||
|
|
||||||
generate_state_machine(StateMachine.txt EscapeSequenceStateMachine.h)
|
generate_state_machine(StateMachine.txt EscapeSequenceStateMachine.h)
|
||||||
serenity_lib(LibVT vt)
|
serenity_lib(LibVT vt)
|
||||||
target_link_libraries(LibVT LibC LibCore LibGUI LibGfx LibDesktop)
|
target_link_libraries(LibVT LibC LibCore LibGUI LibGfx LibDesktop LibConfig)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
#include <AK/Utf32View.h>
|
#include <AK/Utf32View.h>
|
||||||
#include <AK/Utf8View.h>
|
#include <AK/Utf8View.h>
|
||||||
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibCore/MimeData.h>
|
#include <LibCore/MimeData.h>
|
||||||
#include <LibDesktop/AppFile.h>
|
#include <LibDesktop/AppFile.h>
|
||||||
|
@ -73,10 +74,9 @@ void TerminalWidget::set_pty_master_fd(int fd)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Core::ConfigFile> config)
|
TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy)
|
||||||
: m_terminal(*this)
|
: m_terminal(*this)
|
||||||
, m_automatic_size_policy(automatic_size_policy)
|
, m_automatic_size_policy(automatic_size_policy)
|
||||||
, m_config(move(config))
|
|
||||||
{
|
{
|
||||||
static_assert(sizeof(m_colors) == sizeof(xterm_colors));
|
static_assert(sizeof(m_colors) == sizeof(xterm_colors));
|
||||||
memcpy(m_colors, xterm_colors, sizeof(m_colors));
|
memcpy(m_colors, xterm_colors, sizeof(m_colors));
|
||||||
|
@ -95,8 +95,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
|
|
||||||
dbgln("Load config file from {}", m_config->filename());
|
m_cursor_blink_timer->set_interval(Config::read_i32("Terminal", "Text",
|
||||||
m_cursor_blink_timer->set_interval(m_config->read_num_entry("Text",
|
|
||||||
"CursorBlinkInterval",
|
"CursorBlinkInterval",
|
||||||
500));
|
500));
|
||||||
m_cursor_blink_timer->on_timeout = [this] {
|
m_cursor_blink_timer->on_timeout = [this] {
|
||||||
|
@ -113,7 +112,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
|
||||||
};
|
};
|
||||||
m_auto_scroll_timer->start();
|
m_auto_scroll_timer->start();
|
||||||
|
|
||||||
auto font_entry = m_config->read_entry("Text", "Font", "default");
|
auto font_entry = Config::read_string("Terminal", "Text", "Font", "default");
|
||||||
if (font_entry == "default")
|
if (font_entry == "default")
|
||||||
set_font(Gfx::FontDatabase::default_fixed_width_font());
|
set_font(Gfx::FontDatabase::default_fixed_width_font());
|
||||||
else
|
else
|
||||||
|
@ -121,7 +120,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
|
||||||
|
|
||||||
m_line_height = font().glyph_height() + m_line_spacing;
|
m_line_height = font().glyph_height() + m_line_spacing;
|
||||||
|
|
||||||
m_terminal.set_size(m_config->read_num_entry("Window", "Width", 80), m_config->read_num_entry("Window", "Height", 25));
|
m_terminal.set_size(Config::read_i32("Terminal", "Window", "Width", 80), Config::read_i32("Terminal", "Window", "Height", 25));
|
||||||
|
|
||||||
m_copy_action = GUI::Action::create("&Copy", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"), [this](auto&) {
|
m_copy_action = GUI::Action::create("&Copy", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"), [this](auto&) {
|
||||||
copy();
|
copy();
|
||||||
|
@ -146,7 +145,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
|
||||||
update_copy_action();
|
update_copy_action();
|
||||||
update_paste_action();
|
update_paste_action();
|
||||||
|
|
||||||
set_color_scheme(m_config->read_entry("Window", "ColorScheme", "Default"));
|
set_color_scheme(Config::read_string("Terminal", "Window", "ColorScheme", "Default"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalWidget::~TerminalWidget()
|
TerminalWidget::~TerminalWidget()
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
|
||||||
#include <LibCore/ElapsedTimer.h>
|
#include <LibCore/ElapsedTimer.h>
|
||||||
#include <LibCore/Notifier.h>
|
#include <LibCore/Notifier.h>
|
||||||
#include <LibCore/Timer.h>
|
#include <LibCore/Timer.h>
|
||||||
|
@ -28,7 +27,7 @@ class TerminalWidget final
|
||||||
C_OBJECT(TerminalWidget);
|
C_OBJECT(TerminalWidget);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Core::ConfigFile> config);
|
TerminalWidget(int ptm_fd, bool automatic_size_policy);
|
||||||
virtual ~TerminalWidget() override;
|
virtual ~TerminalWidget() override;
|
||||||
|
|
||||||
void set_pty_master_fd(int fd);
|
void set_pty_master_fd(int fd);
|
||||||
|
@ -54,8 +53,6 @@ public:
|
||||||
BellMode bell_mode() { return m_bell_mode; }
|
BellMode bell_mode() { return m_bell_mode; }
|
||||||
void set_bell_mode(BellMode bm) { m_bell_mode = bm; };
|
void set_bell_mode(BellMode bm) { m_bell_mode = bm; };
|
||||||
|
|
||||||
RefPtr<Core::ConfigFile> config() const { return m_config; }
|
|
||||||
|
|
||||||
bool has_selection() const;
|
bool has_selection() const;
|
||||||
bool selection_contains(const VT::Position&) const;
|
bool selection_contains(const VT::Position&) const;
|
||||||
String selected_text() const;
|
String selected_text() const;
|
||||||
|
@ -208,7 +205,6 @@ private:
|
||||||
RefPtr<Core::Timer> m_cursor_blink_timer;
|
RefPtr<Core::Timer> m_cursor_blink_timer;
|
||||||
RefPtr<Core::Timer> m_visual_beep_timer;
|
RefPtr<Core::Timer> m_visual_beep_timer;
|
||||||
RefPtr<Core::Timer> m_auto_scroll_timer;
|
RefPtr<Core::Timer> m_auto_scroll_timer;
|
||||||
RefPtr<Core::ConfigFile> m_config;
|
|
||||||
|
|
||||||
RefPtr<GUI::Scrollbar> m_scrollbar;
|
RefPtr<GUI::Scrollbar> m_scrollbar;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue