Commit graph

72 commits

Author SHA1 Message Date
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
AnotherTest
510030971b LibLine: Handle history across multiple concurrent sessions better
- Store history entries as (timestamp)::(entry)\n\n
- Merge the entries together when saving to avoid loss of history
  entries

To ideally make having two concurrently open shells
(or `js` repls or whatever) not overwrite each others' history entries.
2021-01-11 21:09:36 +01:00
AnotherTest
43199e5613 LibLine: Implement support for C-V<key>
This commit adds support for inserting in a "verbatim" mode where a
single uninterpreted key is appended to the buffer.
As this allows the user to input control characters, all control
characters except \n (^M) are rendered in their caret form, with
reverse video (SGR 7) applied to it.
To not break cursor movement, the concept of "masked" characters is
introduced to the StringMetrics interface, which can be mostly ignored
by the rest of the system.

It should be noted that unlike some other line editing libraries,
LibLine does _not_ render a hard tab as a tab, but rather as '^I',
which greatly simplifies cursor handling.
2021-01-10 16:58:08 +01:00
AnotherTest
9b126a2250 LibLine: Unregister signal handlers on destruction
This fixes an issue that shows up as a nice crash when "^R<enter>^C",
which is actually the event loop trying to call into a deleted object
(the search editor).
2021-01-10 00:03:52 +01:00
AnotherTest
1c4a425bff LibLine: Don't overwrite stuff when moving origin around
This fixes an issue (mainly) with multiline prompts, where a multiline
prompt would overwrite the lines before it when libline tries to display
it.
To reproduce, set `PROMPT="a\nb\nc> "` in the shell, then press return
a few times.
2021-01-04 19:13:18 +01:00
AnotherTest
5d1425718e LibLine: Treat leftover data in buffer as a read event
Fixes #4328.
2020-12-18 19:20:37 +01:00
Linus Groh
b2e4fe1299 Shell+LibLine: Move Shell::{load,save}_history() to Line::Editor
This allows us to easily re-use history loading and saving in other
programs using Line::Editor, as well as implementing universally
recognized HISTCONTROL.
2020-10-26 11:27:54 +01:00
AnotherTest
c057225a36 LibLine: Support multi-character key callbacks 2020-10-22 23:49:51 +02:00
AnotherTest
2d7aaab897 LibLine: Add a setter for the cursor position 2020-09-26 21:28:35 +02:00
Andreas Kling
e2f32b8f9d LibCore: Make Core::Object properties more dynamic
Instead of everyone overriding save_to() and set_property() and doing
a pretty asymmetric job of implementing the various properties, let's
add a bit of structure here.

Object properties are now represented by a Core::Property. Properties
are registered with a getter and setter (optional) in constructors.
I've added some convenience macros for creating and registering
properties, but this does still feel a bit bulky. We'll have to
iterate on this and see where it goes.
2020-09-15 21:46:26 +02:00
Nico Weber
2fe127d96f LibLine: Parse CSI parameters and immediates
No behavior change, but it makes it easy to handle
page up and page down if we wanted to make them do something
in libline.
2020-09-15 09:45:13 +02:00
AnotherTest
da1b080935 LibLine: Make ^R search match the input anywhere in a given line
This is closer to what other line editors (and shells) do, and makes ^R
actually useful.
2020-09-07 11:42:56 +02:00
AnotherTest
084a5c6a90 LibLine: Reset suggestion state on any non-tab key
This fixes the following (and more!):
```sh
$ /bin/dis<tab><tab><backspace><backspace><backspace><backspace><tab>
$ /bink_benchmark
```
2020-08-31 23:06:07 +02:00
AnotherTest
f0ef283f3c LibLine: Correct weird arrow up/down behaviour
Fixes #3270.
Also removes a parameter from search(), as it had no effect.
2020-08-23 15:36:11 +02:00
AnotherTest
30554c969c LibLine: Handle interrupts/window size changes internally 2020-08-21 16:10:51 +02:00
AnotherTest
238e87de4e LibLine: Handle Ctrl-C and Ctrl-D in a way similar to other line editors
Makes C-c print "^C" and continue prompting on a new line.
Also fixes a problem where an interrupted get_line() would need more
read()'s than required to update the display.
2020-08-21 16:10:51 +02:00
AnotherTest
ae9211037e LibLine: Make actual_rendered_string_metrics() static
This function didn't depend on the editor itself.
2020-08-18 16:58:17 +02:00
AnotherTest
5b9d563b4b LibLine: Allow the user to override (or add) keybinds in the config file 2020-08-18 12:07:32 +02:00
AnotherTest
32839d40e3 LibLine: Make (almost) all key actions configurable
This moves all internal functions to a new file, and defines the old
keybinds with register_key_input_callback().
2020-08-18 12:07:32 +02:00
AnotherTest
d0aab41628 LibLine: Read configuration from a config file 2020-08-18 12:07:32 +02:00
AnotherTest
c96b9fdb0a LibLine: Add a getter for num_lines/num_cols 2020-08-17 17:44:02 +02:00
Brian Gianforcaro
c1fd41c38c LibLine: Uninitialized members in Editor, found by Coverity 2020-08-17 09:17:57 +02:00
Nico Weber
3cc9e8ba41 LibLine+Shell: Remove unused split_mechanism
It was only read in should_break_token(), which had no callers.
should_break_token() also got `foo\\ bar` and `"foo bar"` wrong.
2020-08-06 20:37:39 +02:00
Nico Weber
7f7dd3cf9c LibLine: Add binding for Alt-. 2020-08-06 20:37:17 +02:00
Nico Weber
4d9d054386 Shell: Start adding some alt shortcuts
This adds Alt-f to go forward by a word, and Alt-b to go backward
by a word (like ctrl-arrow-left / ctrl-arrow-right already do).

Behind the scenes, alt-key is implemented by sending <esc> followed
by that key, and typing <esc> f/b for moving by a word hence works
too (in all other shells too, not just in Serenity's).

While here, rename some InputState enum values to make the slightly
expanded use of <esc> clearer, and expand a few comments.
2020-08-06 17:45:31 +02:00
Nico Weber
ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber
19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
AnotherTest
70eb7aa627 LibLine: Check if operating on a TTY before using TTY features
This makes the line editor behave well when input is passed in from
pipes as well.
2020-08-05 17:30:31 +02:00
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
AnotherTest
5fedf90bf9 LibLine: Avoid refreshing the display when resizing
This allows was_resized() to be called while the editor is not active
(i.e. get_line() is not in frame).
2020-07-06 22:39:32 +02:00
AnotherTest
f20becf71b LibLine: Correctly display suggestions on multiline prompts 2020-06-30 18:21:44 +02:00
AnotherTest
a6fd969d93 LibLine: Support multiline editing
This commit also updates Shell, which uses actual_rendered_length.
2020-06-27 15:39:03 +02:00
AnotherTest
492df51e70 LibLine: Correctly handle line content overflow when on last line
Fixes #2525
2020-06-07 23:54:21 +02:00
AnotherTest
aa3e440a58 LibLine: Use more descriptive names for row/column
The names x and y caused confusion because of their typical use as
horiz/vert.
2020-06-07 23:54:21 +02:00
AnotherTest
889a8e7d0f LibLine: Handle interrupts again
This commit makes LibLine handle interrupts (as reported via
interrupted() and resized()) again.
There is a little catch with the shell:
```
$     ls |
pipe> <C-c> (prompt stays here until a key is pressed)
```
2020-06-01 19:52:20 +02:00
AnotherTest
e75f7ddb1b LibLine: Send over some properties when being inspected 2020-05-27 11:13:02 +02:00
AnotherTest
70a213a6ec LibLine: Use Core::EventLoop for outer read loop
This commit changes LibLine's internal structure to work in an event
loop, and as a result, also switches it to being a Core::Object.
2020-05-27 11:13:02 +02:00
AnotherTest
8b3eb4535d LibLine: Use LibC's getline() when the terminal claims no support for escape sequences
We just look at $TERM and refuse to emit any escape sequences if it
doesn't start with "xterm".
This could be made much better, at detecting, and at not caling
getline().
2020-05-26 21:09:59 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
AnotherTest
bc9013f706 LibLine: Change get_line to return a Result<String, Error>
This fixes a bunch of FIXME's in LibLine.
Also handles the case where read() would read zero bytes in vt_dsr() and
effectively block forever by erroring out.

Fixes #2370
2020-05-25 21:36:51 +02:00
AnotherTest
909ac2a558 LibLine: Make the comments follow the project style 2020-05-23 01:31:41 +02:00
AnotherTest
f0862cf2b7 LibLine: Refactor suggestion handling and display logic out 2020-05-23 01:31:41 +02:00
AnotherTest
65adf2aea2 LibLine: Correctly handle multibyte codepoints in suggestions 2020-05-23 01:31:41 +02:00
AnotherTest
e2886aabcd LibLine: Make suggest() utf8-aware 2020-05-23 01:31:41 +02:00
AnotherTest
0751592a18 LibLine: Correctly track the completion start and end
To achieve this, the API was tweaked a bit to allow for easier tracking
of completions.
This API change is non-disruptive to any application that does not use
anchored styles.
2020-05-21 10:52:11 +02:00
AnotherTest
88f542dc30 LibLine: Support applying styles to suggestions
This commit also adds the concept of "anchored" styles, which are
applied to a specific part of the line, and are tracked to always stay
applied to that specific part.

Inserting text in the middle of an anchored style extends it, and
removing the styled substring causes the style to be removed as well.
2020-05-21 01:37:19 +02:00
AnotherTest
7fba21aefc LibLine: Unify completion hooks and adapt its users
LibLine should ultimately not care about what a "token" means in the
context of its user, so force the user to split the buffer itself.
This also allows the users to pick up contextual clues as well, since
they have to lex the line themselves.

This commit pacthes Shell and the JS repl to better handle completions,
so certain wrong behaviours are now corrected as well:
- JS repl can now complete "Object . getOw<tab>"
- Shell can now complete "echo | ca<tab>" and paths inside strings
2020-05-20 13:41:37 +02:00
AnotherTest
3bc3f36cfe LibLine: Handle unicode correctly
This commit also fixes a problem with us throwing out data that was
inserted while a command was running.
2020-05-18 11:31:43 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00