Commit Graph

26 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Daniel Bertalan
be519022c3 LibVT: Implement new ANSI escape sequence parser
This commit replaces the former, hand-written parser with a new one that
can be generated automatically according to a state change diagram.

The new `EscapeSequenceParser` class provides a more ergonomic interface
to dealing with escape sequences. This interface has been inspired by
Alacritty's [vte library](https://github.com/alacritty/vte/).

I tried to avoid changing the application logic inside the `Terminal`
class. While this code has not been thoroughly tested, I can't find
regressions in the basic command line utilities or `vttest`.

`Terminal` now displays nicer debug messages when it encounters an
unknown escape sequence. Defensive programming and bounds checks have
been added where we access parameters, and as a result, we can now
endure 4-5 seconds of `cat /dev/urandom`. :D

We generate EscapeSequenceStateMachine.h when building the in-kernel
LibVT, and we assume that the file is already in place when the userland
library is being built. This will probably cause problems later on, but
I can't find a way to do it nicely.
2021-05-16 11:50:56 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
bb6d6dce7b LibVT: Give proper names to remaining VTxxx control functions 2021-02-20 17:04:46 +01:00
Andreas Kling
a59d96e461 LibVT: Give proper names to SD and SU 2021-02-20 17:04:46 +01:00
Andreas Kling
75084d3b3f LibVT: Move control function doc comments to Terminal.h header
Putting the little documentation comment about what each VTxxx control
function does in the header allows them to be picked up by IDE's.
2021-02-20 17:04:46 +01:00
Andreas Kling
6c7c6de52b LibVT: Give proper names to SCOSC and SCORC 2021-02-20 17:04:46 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00