diff options
author | Liav A <liavalb@gmail.com> | 2021-04-16 22:58:51 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-16 19:58:33 +0200 |
commit | 20743e8aede1de46195dd61ad18002cd52db7d3a (patch) | |
tree | 49ea710e88949b49c136b0b3b793059c24f6daa1 /Userland/Libraries/LibVT | |
parent | dac129e10bdef313dff65b34f1fa17608d3608c2 (diff) | |
download | serenity-20743e8aede1de46195dd61ad18002cd52db7d3a.zip |
Kernel/Graphics + SystemServer: Support text mode properly
As we removed the support of VBE modesetting that was done by GRUB early
on boot, we need to determine if we can modeset the resolution with our
drivers, and if not, we should enable text mode and ensure that
SystemServer knows about it too.
Also, SystemServer should first check if there's a framebuffer device
node, which is an indication that text mode was not even if it was
requested. Then, if it doesn't find it, it should check what boot_mode
argument the user specified (in case it's self-test). This way if we
try to use bochs-display device (which is not VGA compatible) and
request a text mode, it will not honor the request and will continue
with graphical mode.
Also try to print critical messages with mininum memory allocations
possible.
In LibVT, We make the implementation flexible for kernel-specific
methods that are implemented in ConsoleImpl class.
Diffstat (limited to 'Userland/Libraries/LibVT')
-rw-r--r-- | Userland/Libraries/LibVT/Attribute.h | 65 | ||||
-rw-r--r-- | Userland/Libraries/LibVT/Line.h | 48 | ||||
-rw-r--r-- | Userland/Libraries/LibVT/Terminal.cpp | 53 | ||||
-rw-r--r-- | Userland/Libraries/LibVT/Terminal.h | 81 |
4 files changed, 173 insertions, 74 deletions
diff --git a/Userland/Libraries/LibVT/Attribute.h b/Userland/Libraries/LibVT/Attribute.h new file mode 100644 index 0000000000..c5d154e5c0 --- /dev/null +++ b/Userland/Libraries/LibVT/Attribute.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Noncopyable.h> +#include <AK/String.h> +#include <AK/Vector.h> +#include <LibVT/XtermColors.h> + +namespace VT { + +struct Attribute { + Attribute() { reset(); } + + static const u32 default_foreground_color = xterm_colors[7]; + static const u32 default_background_color = xterm_colors[0]; + + void reset() + { + foreground_color = default_foreground_color; + background_color = default_background_color; + flags = Flags::NoAttributes; + } + u32 foreground_color {}; + u32 background_color {}; + + u32 effective_background_color() const { return flags & Negative ? foreground_color : background_color; } + u32 effective_foreground_color() const { return flags & Negative ? background_color : foreground_color; } + +#ifndef KERNEL + String href; + String href_id; +#endif + + enum Flags : u8 { + NoAttributes = 0x00, + Bold = 0x01, + Italic = 0x02, + Underline = 0x04, + Negative = 0x08, + Blink = 0x10, + Touched = 0x20, + }; + + bool is_untouched() const { return !(flags & Touched); } + + // TODO: it would be really nice if we had a helper for enums that + // exposed bit ops for class enums... + u8 flags = Flags::NoAttributes; + + bool operator==(const Attribute& other) const + { + return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags; + } + bool operator!=(const Attribute& other) const + { + return !(*this == other); + } +}; + +} diff --git a/Userland/Libraries/LibVT/Line.h b/Userland/Libraries/LibVT/Line.h index ce6532b6e1..ecc9fdc19b 100644 --- a/Userland/Libraries/LibVT/Line.h +++ b/Userland/Libraries/LibVT/Line.h @@ -9,57 +9,11 @@ #include <AK/Noncopyable.h> #include <AK/String.h> #include <AK/Vector.h> +#include <LibVT/Attribute.h> #include <LibVT/XtermColors.h> namespace VT { -struct Attribute { - Attribute() { reset(); } - - static const u32 default_foreground_color = xterm_colors[7]; - static const u32 default_background_color = xterm_colors[0]; - - void reset() - { - foreground_color = default_foreground_color; - background_color = default_background_color; - flags = Flags::NoAttributes; - } - u32 foreground_color {}; - u32 background_color {}; - - u32 effective_background_color() const { return flags & Negative ? foreground_color : background_color; } - u32 effective_foreground_color() const { return flags & Negative ? background_color : foreground_color; } - - String href; - String href_id; - - enum Flags : u8 { - NoAttributes = 0x00, - Bold = 0x01, - Italic = 0x02, - Underline = 0x04, - Negative = 0x08, - Blink = 0x10, - Touched = 0x20, - }; - - bool is_untouched() const { return !(flags & Touched); } - - // TODO: it would be really nice if we had a helper for enums that - // exposed bit ops for class enums... - u8 flags = Flags::NoAttributes; - - bool operator==(const Attribute& other) const - { - return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags; - } - bool operator!=(const Attribute& other) const - { - return !(*this == other); - } -}; - class Line { AK_MAKE_NONCOPYABLE(Line); AK_MAKE_NONMOVABLE(Line); diff --git a/Userland/Libraries/LibVT/Terminal.cpp b/Userland/Libraries/LibVT/Terminal.cpp index ccd66257cf..42ee743396 100644 --- a/Userland/Libraries/LibVT/Terminal.cpp +++ b/Userland/Libraries/LibVT/Terminal.cpp @@ -9,19 +9,23 @@ #include <AK/StringBuilder.h> #include <AK/StringView.h> #include <LibVT/Terminal.h> +#ifdef KERNEL +# include <Kernel/TTY/VirtualConsole.h> +#endif namespace VT { +#ifndef KERNEL Terminal::Terminal(TerminalClient& client) +#else +Terminal::Terminal(Kernel::VirtualConsole& client) +#endif : m_client(client) , m_parser(*this) { } -Terminal::~Terminal() -{ -} - +#ifndef KERNEL void Terminal::clear() { for (size_t i = 0; i < rows(); ++i) @@ -38,6 +42,7 @@ void Terminal::clear_including_history() m_client.terminal_history_changed(); } +#endif void Terminal::alter_mode(bool should_set, Parameters params, Intermediates intermediates) { @@ -445,6 +450,7 @@ void Terminal::SD(Parameters params) scroll_down(); } +#ifndef KERNEL void Terminal::IL(Parameters params) { int count = 1; @@ -461,12 +467,14 @@ void Terminal::IL(Parameters params) m_need_full_flush = true; } +#endif void Terminal::DA(Parameters) { emit_string("\033[?1;0c"); } +#ifndef KERNEL void Terminal::DL(Parameters params) { int count = 1; @@ -511,6 +519,7 @@ void Terminal::DCH(Parameters params) line.set_dirty(true); } +#endif void Terminal::newline() { @@ -527,6 +536,7 @@ void Terminal::carriage_return() set_cursor(m_cursor_row, 0); } +#ifndef KERNEL void Terminal::scroll_up() { // NOTE: We have to invalidate the cursor first. @@ -550,6 +560,20 @@ void Terminal::scroll_down() m_need_full_flush = true; } +void Terminal::put_character_at(unsigned row, unsigned column, u32 code_point) +{ + VERIFY(row < rows()); + VERIFY(column < columns()); + auto& line = m_lines[row]; + line.set_code_point(column, code_point); + line.attribute_at(column) = m_current_attribute; + line.attribute_at(column).flags |= Attribute::Touched; + line.set_dirty(true); + + m_last_code_point = code_point; +} +#endif + void Terminal::set_cursor(unsigned a_row, unsigned a_column) { unsigned row = min(a_row, m_rows - 1u); @@ -565,19 +589,6 @@ void Terminal::set_cursor(unsigned a_row, unsigned a_column) invalidate_cursor(); } -void Terminal::put_character_at(unsigned row, unsigned column, u32 code_point) -{ - VERIFY(row < rows()); - VERIFY(column < columns()); - auto& line = m_lines[row]; - line.set_code_point(column, code_point); - line.attribute_at(column) = m_current_attribute; - line.attribute_at(column).flags |= Attribute::Touched; - line.set_dirty(true); - - m_last_code_point = code_point; -} - void Terminal::NEL() { newline(); @@ -607,6 +618,7 @@ void Terminal::DSR(Parameters params) } } +#ifndef KERNEL void Terminal::ICH(Parameters params) { int num = 0; @@ -628,6 +640,7 @@ void Terminal::ICH(Parameters params) line.set_dirty(true); } +#endif void Terminal::on_input(u8 byte) { @@ -837,6 +850,7 @@ void Terminal::execute_osc_sequence(OscParameters parameters, u8 last_byte) // Should we expose the raw OSC string from the parser? Or join by semicolon? break; case 8: +#ifndef KERNEL if (parameters.size() < 2) { dbgln("Attempted to set href but gave too few parameters"); } else if (parameters[2].is_empty()) { @@ -847,6 +861,7 @@ void Terminal::execute_osc_sequence(OscParameters parameters, u8 last_byte) // FIXME: Respect the provided ID m_current_attribute.href_id = String::number(m_next_href_id++); } +#endif break; case 9: if (parameters.size() < 2 || parameters[1].is_empty() || parameters[2].is_empty()) @@ -1034,6 +1049,7 @@ void Terminal::unimplemented_osc_sequence(OscParameters parameters, u8 last_byte dbgln("{}", builder.string_view()); } +#ifndef KERNEL void Terminal::set_size(u16 columns, u16 rows) { if (!columns) @@ -1073,7 +1089,9 @@ void Terminal::set_size(u16 columns, u16 rows) m_client.terminal_did_resize(m_columns, m_rows); } +#endif +#ifndef KERNEL void Terminal::invalidate_cursor() { m_lines[m_cursor_row].set_dirty(true); @@ -1090,5 +1108,6 @@ Attribute Terminal::attribute_at(const Position& position) const return {}; return line.attribute_at(position.column()); } +#endif } diff --git a/Userland/Libraries/LibVT/Terminal.h b/Userland/Libraries/LibVT/Terminal.h index 7198059654..853319353b 100644 --- a/Userland/Libraries/LibVT/Terminal.h +++ b/Userland/Libraries/LibVT/Terminal.h @@ -12,9 +12,18 @@ #include <AK/Vector.h> #include <Kernel/API/KeyCode.h> #include <LibVT/EscapeSequenceParser.h> -#include <LibVT/Line.h> #include <LibVT/Position.h> +#ifndef KERNEL +# include <LibVT/Attribute.h> +# include <LibVT/Line.h> +#else +namespace Kernel { +class VirtualConsole; +} +# include <LibVT/Attribute.h> +#endif + namespace VT { class TerminalClient { @@ -31,24 +40,52 @@ public: class Terminal : public EscapeSequenceExecutor { public: +#ifndef KERNEL explicit Terminal(TerminalClient&); - ~Terminal(); +#else + explicit Terminal(Kernel::VirtualConsole&); +#endif + + virtual ~Terminal() + { + } bool m_need_full_flush { false }; +#ifndef KERNEL void invalidate_cursor(); +#else + virtual void invalidate_cursor() = 0; +#endif + void on_input(u8); + void set_cursor(unsigned row, unsigned column); + +#ifndef KERNEL void clear(); void clear_including_history(); +#else + virtual void clear() = 0; + virtual void clear_including_history() = 0; +#endif +#ifndef KERNEL void set_size(u16 columns, u16 rows); - u16 columns() const { return m_columns; } +#else + virtual void set_size(u16 columns, u16 rows) = 0; +#endif + + u16 columns() const + { + return m_columns; + } u16 rows() const { return m_rows; } u16 cursor_column() const { return m_cursor_column; } u16 cursor_row() const { return m_cursor_row; } +#ifndef KERNEL size_t line_count() const { return m_history.size() + m_lines.size(); @@ -100,13 +137,16 @@ public: m_max_history_lines = value; } size_t history_size() const { return m_history.size(); } +#endif void inject_string(const StringView&); void handle_key_press(KeyCode, u32, u8 flags); +#ifndef KERNEL Attribute attribute_at(const Position&) const; +#endif -private: +protected: // ^EscapeSequenceExecutor virtual void emit_code_point(u32) override; virtual void execute_control_code(u8) override; @@ -117,14 +157,20 @@ private: virtual void receive_dcs_char(u8 byte) override; virtual void execute_dcs_sequence() override; + void carriage_return(); +#ifndef KERNEL void scroll_up(); void scroll_down(); void newline(); - void carriage_return(); - - void set_cursor(unsigned row, unsigned column); void put_character_at(unsigned row, unsigned column, u32 ch); void set_window_title(const String&); +#else + virtual void scroll_up() = 0; + virtual void scroll_down() = 0; + virtual void newline() = 0; + virtual void put_character_at(unsigned row, unsigned column, u32 ch) = 0; + virtual void set_window_title(const String&) = 0; +#endif void unimplemented_control_code(u8); void unimplemented_escape_sequence(Intermediates, u8 last_byte); @@ -192,8 +238,12 @@ private: // DSR - Device Status Reports void DSR(Parameters); +#ifndef KERNEL // ICH - Insert Character void ICH(Parameters); +#else + virtual void ICH(Parameters) = 0; +#endif // SU - Scroll Up (called "Pan Down" in VT510) void SU(Parameters); @@ -201,14 +251,18 @@ private: // SD - Scroll Down (called "Pan Up" in VT510) void SD(Parameters); +#ifndef KERNEL // IL - Insert Line void IL(Parameters); - // DCH - Delete Character void DCH(Parameters); - // DL - Delete Line void DL(Parameters); +#else + virtual void IL(Parameters) = 0; + virtual void DCH(Parameters) = 0; + virtual void DL(Parameters) = 0; +#endif // CHA - Cursor Horizontal Absolute void CHA(Parameters); @@ -225,10 +279,14 @@ private: // FIXME: Find the right names for these. void XTERM_WM(Parameters); +#ifndef KERNEL TerminalClient& m_client; +#else + Kernel::VirtualConsole& m_client; +#endif EscapeSequenceParser m_parser; - +#ifndef KERNEL size_t m_history_start = 0; NonnullOwnPtrVector<Line> m_history; void add_line_to_history(NonnullOwnPtr<Line>&& line) @@ -246,6 +304,7 @@ private: } NonnullOwnPtrVector<Line> m_lines; +#endif size_t m_scroll_region_top { 0 }; size_t m_scroll_region_bottom { 0 }; @@ -263,7 +322,9 @@ private: Attribute m_current_attribute; Attribute m_saved_attribute; +#ifndef KERNEL u32 m_next_href_id { 0 }; +#endif Vector<bool> m_horizontal_tabs; u32 m_last_code_point { 0 }; |