Commit Graph

80 Commits

Author SHA1 Message Date
Hendiadyoin1
ed46d52252 Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
2021-07-19 16:34:21 +04:30
Andreas Kling
234d53a324 Terminal: Put debug spam in unimplemented_control_code() behind a flag 2021-07-10 16:13:34 +02:00
Daniel Bertalan
05c174b45a LibVT: Reset scrollbar after switching to/from the alternate buffer
We did not call the history change callback after switching to the
alternate screen buffer, which caused the scrollbar to not change its
maximum value. If we already had lines in the scrollback buffer, this
meant that we could drag the scrollbar, which then tried to access
non-existent lines from the scrollback.

Fixes #8581
2021-07-10 01:23:23 +02:00
Daniel Bertalan
0e04f7cf1e LibVT: Always check intermediate bytes in CSI sequences
Previously, we only checked the intermediate bytes for those escape
sequences that performed different operations based on their
intermediate bytes. This lead to a crash when `CSI ?1001 r` was
incorrectly parsed as `CSI Pt ; Pb r` (note the missing question mark),
as seen in #8559.
2021-07-09 20:28:17 +04:30
pancake
390d3e9fbe
LibVT: Ignore DECSTBM with invalid values (#8559)
Co-authored-by: pancake <pancake@nopcode.org>
2021-07-08 22:41:55 +04:30
Max Wipfli
fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00
Xavier Defrang
04fc7d708c LibVT: Paste full path when dropping file on widget
Prioritize URLs over plain text content in order to
insert absolute path instead of basename
2021-06-29 00:23:40 +04:30
Ali Mohammad Pur
7c88caf99f LibVT: Only resize the line after all rewrapping is done
Otherwise we would end up inserting empty cells into the wrapped lines.
Fixes #8227.
2021-06-24 18:50:45 +02:00
Ali Mohammad Pur
fcef84c461 LibVT: Rewrap the terminal history along with the normal buffer 2021-06-23 19:04:08 +02:00
Ali Mohammad Pur
2f2b7814d1 LibVT+Terminal: Implement line wrapping
This commit implements line wrapping in the terminal, and tries its best
to move the cursor to the "correct" position.
2021-06-23 19:04:08 +02:00
Ali Mohammad Pur
424965954f LibVT: Keep track of the 'true' line endings 2021-06-23 19:04:08 +02:00
Gunnar Beutner
21ee0ad6fc LibVT: Don't crash when clicking outside of the terminal's buffer area
When resizing a terminal window the number of columns may change.
Previously we assumed that this also affects lines which were in the
terminal's buffer while that is not necessarily true.
2021-06-23 16:26:40 +02:00
Daniel Bertalan
3752775a1e LibVT: Implement DECIC/DECDC
This commit adds support for these escape sequences that are used for
scrolling multiple lines at once. In the current, unoptimized
implementation, these just call the `scroll_left` and `scroll_right`
APIs multiple times.

It's a VT420 feature.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
ce9460de59 Kernel+LibVT: Fix selection with scrollback wrap-around
If lines are removed from the tail of the scrollback buffer, the
previous line indices will refer to different lines; therefore we need
to offset them.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
13991eade7 LibVT: Implement DECFI and DECBI
These escape sequences are the horizontal scrolling equivalents of `IND`
and `RI`. Normally, they move the cursor forward or backward. But if
they hit the margins (which we just treat as the first and last
columns), they scroll the line.

Another VT420 feature done.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
89843cd692 Kernel+LibVT: Implement left-right scrolling
This commit implements the left/right scrolling used in the `ICH`/`DCH`
escape sequences for `VirtualConsole`. This brings us one step closer to
VT420/xterm compatibility.

We can now finally remove the last escape sequence related `ifdef`s.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
7419569a2b Kernel+LibVT: Add function for deleting a range of characters
Previously, this was done by telling the client to put a space at each
character in the range. This was inefficient, because a large number of
function calls took place and incorrect, as the ANSI standard dictates
that character attributes should be cleared as well.

The newly added `clear_in_line` function solves this issue. It performs
just one bounds check when it's called and can be implemented as a
pretty tight loop.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
8f8fd9c5a8 LibVT+Kernel: Support clearing the scrollback buffer
As per the `xterm ctlseqs` documentation, `\e3J` should clear the
scrollback buffer, and leave the visible lines unchanged.

This commit fixes a FIXME.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
221ba1aac8 LibVT: Improve scrolling performance
Previously, we would remove lines from the buffer, create new lines and
insert them into the buffer when we scrolled. Since scrolling does not
always happen at the last line, this meant `Line` objects were
pointlessly moved forwards, and then immediately backwards.

We now swap them in-place and clear those lines that are "inserted". As
a result, performance is better and scrolling is smoother in `vim` and
`nano`.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
fe58d15b5b LibVT: Fix ECH not clearing lines
The `num` parameter should be treated as an offset from the cursor
position, not from the beginning of the line. The previous behavior
caused fragments of previous lines to be visible when moving the entire
buffer in vim (e.g. with `gg` and `G`).

The debug messages I used while fixing it are also included in this
commit. These will help diagnose further issues if they arise.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
ae6bdc4e29 LibVT+Kernel: Clean up scroll API
This commit cleans up some of the `#ifdef`-ed code smell in
`Terminal`, by extending the scroll APIs to take a range of lines as a
parameter. This makes it possible to use the same code for `IL`/`DL` as
for scrolling.

Note that the current scrolling implementation is very naive, and does
many insertions/deletions in the middle of arrays, whereas swaps should
be enough. This optimization will come in a later commit.

The `linefeed` override was removed from `VirtualConsole`. Previously,
it exhibited incorrect behavior by moving to column 0. Now that we use
the method defined in `Terminal`, code which relied on this behavior
stopped working. We go instead go through the TTY layer which handles
the various output flags. Passing the input character-by-character
seems a bit excessive, so a fix for it will come in another PR.
2021-06-10 17:18:02 +02:00
Daniel Bertalan
5f92790489 LibVT: Fix out-of-bounds reads in ICH/DCH escape sequences
Previously, entering too big counts for these commands could cause a
wrap-around with the cell indices.

Also, we are now correctly copying the cell attributes as well as the
code point.
2021-06-10 17:18:02 +02:00
Tim Schumacher
1618cffb75 LibVT: Don't return a history size if alternate buffer is used
The line history is unavailable if the alternate screen buffer is
currently enabled. However, since TerminalWidget uses the history size
to offset its line numbers when rendering, it will try to render
inaccessible lines once the history is not empty anymore.
2021-06-05 22:12:18 +02:00
Daniel Bertalan
99a79a364a LibVT: Fix underlines incorrectly rendering in red
Previously, `href` attributes weren't checked for not being empty when
drawing their underlines. This caused any underline to be treated as an
active `href`, hence the red color.
2021-06-04 09:02:43 +01:00
Daniel Bertalan
53099b216c LibVT: Implement bright color support
Previously, we only used bright colors when the bold attribute was set.
We now have the option to set it via escape sequences. We also needed to
make the bold text behavior optional, as some color schemes do weird
things with it. For example, Solarized uses it for various shades of
gray, so bold green would turn into a light shade of gray.

The following new escape sequences are supported:
- `CSI 90;m` to `CSI 97;m`: set bright foreground color
- `CSI 100;m` to `CSI 107;m`: set bright background color
2021-06-04 09:02:43 +01:00
Daniel Bertalan
acbd1d14d0 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.
2021-06-04 09:02:43 +01:00
Daniel Bertalan
99033876ec LibVT+Kernel: Create Color class
Previously, we converted colors to their RGB values immediately when
they were set. This meant that their semantic meaning was lost, we could
not tell a precise RGB value apart from a named/indexed color.

The new way of storing colors will allow us to retain this information,
so we can change a color scheme on the fly, and previously emitted text
will also be affected.
2021-06-04 09:02:43 +01:00
Andreas Kling
12a42edd13 Everywhere: codepoint => code point 2021-06-01 10:01:11 +02:00
Daniel Bertalan
4cf6963a1c LibVT: Add missing cursor movement escape sequences
This commit adds support for the following ANSI escape sequences:
- `CNL` - Cursor Next Line
- `CPL` - Cursor Previous Line
- `VPR` - Line Position Relative
- `HPA` - Character Position Absolute
- `HPR` - Character Position Relative
2021-05-29 15:50:24 +02:00
Daniel Bertalan
0c6f019285 LibVT: Fix out-of bounds line insert
Unless DECOM mode is enabled, the cursor positions are measured from the
top left corner of the screen. We counted from the top margin, causing
line inserts in `vim` to go out-of-bounds and crash the terminal.
2021-05-24 22:26:54 +04:30
Daniel Bertalan
6465f87827 LibVT: Fix issues running nano
This commit fixes 3 correctness issues with the ANSI escape sequence
handling logic:
1. Default parameters were not handled correctly: the specification says
   that 0-valued CSI escape sequence parameters should take their
   default values.
2. We did not call `scroll_{up, down}` when encountering RI/IND commands
   that reached the scroll margins. This caused nano to only scroll the
   first line.
2021-05-24 22:26:54 +04:30
Daniel Bertalan
146bd794eb LibVT: Add Alternate Screen Buffer support
The Alternate Screen Buffer is used by full-screen terminal applications
(like `vim` and `nano`). Its data is stored separately from the normal
buffer, therefore after applications using it exit, everything looks
like it was before, the bottom of their interfaces isn't visible. An
interesting feature is that it does not support scrollback, so it
consumes less memory by not having to allocate lines for history.

Because of the need to save and restore state between the switches, some
correctness issues relating to it were also fixed in this commit.
2021-05-24 22:26:54 +04:30
Daniel Bertalan
708f835477 LibVT: Implement Bracketed Paste Mode
This mode allow us to escape any data that was not directly typed by the
user. `vim` currently uses this. If we implement it in the shell, we
could prevent newlines from being injected into the shell by pasting
text or dragging files into it (see #7276).
2021-05-24 16:58:57 +04:30
Daniel Bertalan
ee24f2eb2d LibVT: Add title stack support
This feature allows applications to reset the window title once they
exited. It is used by `vim` if `set title` is enabled.
2021-05-24 16:58:57 +04:30
Daniel Bertalan
875a2cbb71 LibVT+Kernel: Add support for setting cursor styles
This commit introduces support for 3 new escape sequences:
1. Stop blinking cursor mode
2. `DECTCEM` mode (enable/disable cursor)
3. `DECSCUSR` (set cursor style)

`TerminalWidget` now supports the following cursor types: block,
underline and vertical bar. Each of these can blink or be steady.
`VirtualConsole` ignores these (just as we were doing before).
2021-05-24 11:27:58 +02:00
Daniel Bertalan
282d0ebbec LibVT: Fix UTF-8 handling in OSC sequences
Previously, we would ignore bytes in the `0x80..0xff` range when parsing
OSC strings. This caused terminal titles and hyperlinks containing
non-ASCII characters to fail. Also added is extending the UTF-8 fail
functionality for C1 control codes, since we do not handle those.

Fixes #7377
2021-05-22 23:23:08 +02:00
Andreas Kling
ee5cf92b3d LibVT: Don't cache bold variant of VT font in a member variable
Remove some leftovers from back when we had to resolve a bold variant
of the terminal font manually. Now we can just use bold_variant().
2021-05-22 10:21:52 +02:00
Max Wipfli
229414b002 Applications: Use titlecase and distinct underlined characters in menus
This changes (context) menus across the system to conform to titlecase
capitalization and to not underline the same character twice (for
accessing actions with Alt).
2021-05-21 18:41:28 +01:00
Linus Groh
d60ebbbba6 Revert "Userland: static vs non-static constexpr variables"
This reverts commit 800ea8ea96.

Booting the system no longer worked after these changes.
2021-05-21 10:30:52 +01:00
Lenny Maiorani
800ea8ea96 Userland: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
  optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
  every time the function is run.

Solution:
- If a global `static` variable is only used in a single function then
  move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
  `constexpr`.
2021-05-21 10:07:06 +01:00
Andreas Kling
8a6c37deef LibGfx: Remove Gfx::FontDatabase::default_bold_fixed_width_font()
Ask for a bold_variant() of the default_fixed_width_font() instead.
2021-05-20 20:55:29 +02:00
Ali Mohammad Pur
c6b12841ee Meta: Make generate_state_machine() generate a proper target
And use GENERATED_SOURCES (or add_dependencies) to make LibVT depend on
that target.
Fixes a FIXME.
2021-05-20 12:11:27 +01:00
Daniel Bertalan
c1e292e5bc LibVT: Correct color handling
VT100's documentation says that more than one SGR (Set Graphics
Rendition) parameters may be included in a single escape sequence.
However, we treated those with more than 3 parameters as color
sequences, so this behavior was not replicated.
2021-05-17 18:19:49 +02:00
Daniel Bertalan
507ace5174 LibVT: Fix progress bars not getting reset 2021-05-17 18:19:49 +02:00
Daniel Bertalan
5d80debc1f LibVT: Fix newline handling
Before this commit, we would jump to the first column after receiving
the '\n' line feed character. This is not the correct behavior, as it
should only move the cursor now. Translating the typed Return key into
the correct CR LF ("\r\n") is the TTY's job, which was fixed in #7184.

Fixes #6820
Fixes #6960
2021-05-17 18:19:49 +02:00
Liav A
20743e8aed 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.
2021-05-16 19:58:33 +02:00
Linus Groh
7ec8cb97e9 LibVT: Run clang-format on Terminal.cpp
Some trailing whitespace is causing the CI to fail. :^)
2021-05-16 15:16:50 +01:00
Daniel Bertalan
26953c2be1 LibVT: Implement ST (ESC \) escape sequence
Closes #7175
2021-05-16 15:53:02 +02:00
Daniel Bertalan
7b9051afe5 LibVT: Fix 8-bit control codes clobbering UTF-8
Bytes in the 0x80..0x9F range were treated as C1 control codes,
which prevented them from being parsed as UTF-8 bytes.

This caused some characters (like U+DF, encoded as 0xC3 0x9F)
from being recognized as printable characters.
2021-05-16 14:17:04 +02:00
Daniel Bertalan
e0b6cfec1a LibVT: fix SM/RM not respecting private markers
Since we now store intermediate characters separately, the intermediates
should be checked for the presence of the '?' DEC private marker, not
the first parameter.
2021-05-16 11:50:56 +02:00