/* * Copyright (c) 2020, Hunter Salyer * Copyright (c) 2021, Andreas Kling * Copyright (c) 2021, Sam Atkins * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include "ConsoleWidget.h" #include #include #include #include #include #include #include #include #include #include namespace Browser { ConsoleWidget::ConsoleWidget(WebView::OutOfProcessWebView& content_view) { set_layout(); set_fill_with_background_color(true); m_output_view = add(); m_console_client = make(content_view, *m_output_view); auto& bottom_container = add(); bottom_container.set_layout(); bottom_container.set_fixed_height(22); m_input = bottom_container.add(); m_input->set_syntax_highlighter(make()); // FIXME: Syntax Highlighting breaks the cursor's position on non fixed-width fonts. m_input->set_font(Gfx::FontDatabase::default_fixed_width_font()); m_input->set_history_enabled(true); m_input->on_return_pressed = [this] { auto js_source = m_input->text(); if (js_source.is_whitespace()) return; m_input->add_current_text_to_history(); m_input->clear(); m_console_client->execute(MUST(String::from_deprecated_string(js_source))); }; set_focus_proxy(m_input); auto& clear_button = bottom_container.add(); clear_button.set_fixed_size(22, 22); clear_button.set_icon(g_icon_bag.delete_icon); clear_button.set_tooltip("Clear the console output"_string); clear_button.on_click = [this](auto) { m_console_client->clear(); }; } ConsoleWidget::~ConsoleWidget() = default; void ConsoleWidget::reset() { m_console_client->reset(); } }