summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/Terminal/main.cpp93
1 files changed, 46 insertions, 47 deletions
diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp
index 6c28703826..1e0c8e9e6d 100644
--- a/Userland/Applications/Terminal/main.cpp
+++ b/Userland/Applications/Terminal/main.cpp
@@ -261,7 +261,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::sigaction(SIGCHLD, &act, nullptr));
- auto app = GUI::Application::construct(arguments);
+ auto app = TRY(GUI::Application::try_create(arguments));
TRY(Core::System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix", nullptr));
@@ -301,42 +301,42 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app_icon = GUI::Icon::default_icon("app-terminal");
- auto window = GUI::Window::construct();
+ auto window = TRY(GUI::Window::try_create());
window->set_title("Terminal");
window->set_background_color(Color::Black);
window->set_double_buffering_enabled(false);
- auto& terminal = window->set_main_widget<VT::TerminalWidget>(ptm_fd, true);
- terminal.on_command_exit = [&] {
+ auto terminal = TRY(window->try_set_main_widget<VT::TerminalWidget>(ptm_fd, true));
+ terminal->on_command_exit = [&] {
app->quit(0);
};
- terminal.on_title_change = [&](auto title) {
+ terminal->on_title_change = [&](auto title) {
window->set_title(title);
};
- terminal.on_terminal_size_change = [&](auto& size) {
+ terminal->on_terminal_size_change = [&](auto& size) {
window->resize(size);
};
- terminal.apply_size_increments_to_window(*window);
+ terminal->apply_size_increments_to_window(*window);
window->set_icon(app_icon.bitmap_for_size(16));
auto bell = Config::read_string("Terminal", "Window", "Bell", "Visible");
if (bell == "AudibleBeep") {
- terminal.set_bell_mode(VT::TerminalWidget::BellMode::AudibleBeep);
+ terminal->set_bell_mode(VT::TerminalWidget::BellMode::AudibleBeep);
} else if (bell == "Disabled") {
- terminal.set_bell_mode(VT::TerminalWidget::BellMode::Disabled);
+ terminal->set_bell_mode(VT::TerminalWidget::BellMode::Disabled);
} else {
- terminal.set_bell_mode(VT::TerminalWidget::BellMode::Visible);
+ terminal->set_bell_mode(VT::TerminalWidget::BellMode::Visible);
}
RefPtr<GUI::Window> settings_window;
RefPtr<GUI::Window> find_window;
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);
- auto new_scrollback_size = Config::read_i32("Terminal", "Terminal", "MaxHistorySize", terminal.max_history_size());
- terminal.set_max_history_size(new_scrollback_size);
+ auto new_scrollback_size = Config::read_i32("Terminal", "Terminal", "MaxHistorySize", terminal->max_history_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").release_value_but_fixme_should_propagate_errors(),
[&](const GUI::Action&) {
@@ -345,10 +345,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
settings_window->show();
settings_window->move_to_front();
settings_window->on_close = [&]() {
- Config::write_i32("Terminal", "Window", "Opacity", terminal.opacity());
- Config::write_i32("Terminal", "Terminal", "MaxHistorySize", terminal.max_history_size());
+ Config::write_i32("Terminal", "Window", "Opacity", terminal->opacity());
+ 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();
if (bell == VT::TerminalWidget::BellMode::AudibleBeep) {
bell_setting = "AudibleBeep";
@@ -361,59 +361,58 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
};
});
- terminal.context_menu().add_separator();
+ TRY(terminal->context_menu().try_add_separator());
auto pick_font_action = GUI::Action::create("&Terminal Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png").release_value_but_fixme_should_propagate_errors(),
[&](auto&) {
- auto picker = GUI::FontPicker::construct(window, &terminal.font(), true);
+ auto picker = GUI::FontPicker::construct(window, &terminal->font(), true);
if (picker->exec() == GUI::Dialog::ExecOK) {
- terminal.set_font_and_resize_to_fit(*picker->font());
- window->resize(terminal.size());
+ terminal->set_font_and_resize_to_fit(*picker->font());
+ window->resize(terminal->size());
Config::write_string("Terminal", "Text", "Font", picker->font()->qualified_name());
}
});
- terminal.context_menu().add_action(pick_font_action);
-
- terminal.context_menu().add_separator();
- terminal.context_menu().add_action(open_settings_action);
+ TRY(terminal->context_menu().try_add_action(pick_font_action));
+ TRY(terminal->context_menu().try_add_separator());
+ TRY(terminal->context_menu().try_add_action(open_settings_action));
- auto& file_menu = window->add_menu("&File");
- file_menu.add_action(GUI::Action::create("Open New &Terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-terminal.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
+ auto file_menu = TRY(window->try_add_menu("&File"));
+ TRY(file_menu->try_add_action(GUI::Action::create("Open New &Terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-terminal.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
Core::Process::spawn("/bin/Terminal");
- }));
+ })));
- file_menu.add_action(open_settings_action);
- file_menu.add_separator();
- file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
+ TRY(file_menu->try_add_action(open_settings_action));
+ TRY(file_menu->try_add_separator());
+ TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
dbgln("Terminal: Quit menu activated!");
GUI::Application::the()->quit();
- }));
+ })));
- auto& edit_menu = window->add_menu("&Edit");
- edit_menu.add_action(terminal.copy_action());
- edit_menu.add_action(terminal.paste_action());
- edit_menu.add_separator();
- edit_menu.add_action(GUI::Action::create("&Find...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png").release_value_but_fixme_should_propagate_errors(),
+ auto edit_menu = TRY(window->try_add_menu("&Edit"));
+ TRY(edit_menu->try_add_action(terminal->copy_action()));
+ TRY(edit_menu->try_add_action(terminal->paste_action()));
+ TRY(edit_menu->try_add_separator());
+ TRY(edit_menu->try_add_action(GUI::Action::create("&Find...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png").release_value_but_fixme_should_propagate_errors(),
[&](auto&) {
if (!find_window)
find_window = create_find_window(terminal);
find_window->show();
find_window->move_to_front();
- }));
+ })));
- auto& view_menu = window->add_menu("&View");
- view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) {
+ auto view_menu = TRY(window->try_add_menu("&View"));
+ TRY(view_menu->try_add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) {
window->set_fullscreen(!window->is_fullscreen());
- }));
- view_menu.add_action(terminal.clear_including_history_action());
- view_menu.add_separator();
- view_menu.add_action(pick_font_action);
+ })));
+ TRY(view_menu->try_add_action(terminal->clear_including_history_action()));
+ TRY(view_menu->try_add_separator());
+ TRY(view_menu->try_add_action(pick_font_action));
- auto& help_menu = window->add_menu("&Help");
- help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) {
+ auto help_menu = TRY(window->try_add_menu("&Help"));
+ TRY(help_menu->try_add_action(GUI::CommonActions::make_help_action([](auto&) {
Desktop::Launcher::open(URL::create_with_file_protocol("/usr/share/man/man1/Terminal.md"), "/bin/Help");
- }));
- help_menu.add_action(GUI::CommonActions::make_about_action("Terminal", app_icon, window));
+ })));
+ TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Terminal", app_icon, window)));
window->on_close = [&]() {
if (find_window)