Commit graph

150 commits

Author SHA1 Message Date
Nico Weber
f008e83eae LibLine: Add Ctrl-k shortcut
Only does the 'delete to end of line' bit for now.
No yank ring support yet.
2020-08-07 09:07:30 +02:00
Nico Weber
530fb7eb82 LibLine: Add Alt-t shortcut for transposing words 2020-08-07 09:04:28 +02:00
Nico Weber
c1fb5263a5 LibLine: Add binding for Alt-backspace
It backward-deletes a word like Ctrl-W, but it has a slightly
different definition of what a word is. For example, with the
caret behind `gcc -fsanitize=address`, Ctrl-W would delete
'-fsanitize=address' but Alt-backspace would only delete 'address'.
2020-08-06 21:06:14 +02:00
Nico Weber
2051d690d5 LibLine: Fix "word" handling for alt-d/u/l/c/f/b and ctrl-left/right
All these shortcuts treat consecutive alnums as a word, not consecutive
non-spaces.

For example, `alias KILL='kill -9'` can now be written by typing it
out lowercase, then hitting ctrl-a alt-f alt-u.

Ctrl-W still treats a word as a sequence of non-spaces. Alt-backspace
in a future patch will add the ability to backward-delete a word
that's a sequence of alnums.
2020-08-06 20:55:27 +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
90efba95c1 LibLine: Add bindings for Alt-u, Alt-l, Alt-c 2020-08-06 19:48:30 +02:00
Nico Weber
5d343e1c29 LibLine: Add comments for which keys trigger VWERASE and VKILL 2020-08-06 19:03:06 +02:00
Nico Weber
f29c5c3a41 LibLine: Add Alt-d binding to forward-delete a word 2020-08-06 19:03:06 +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
Nico Weber
d0ad82f5c0 LibLine: Removed unused private field m_prompt_metrics 2020-08-04 17:42:08 +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
Muhammad Zahalqa
615ba0f368
AK: Fix overflow and mixed-signedness issues in binary_search() (#2961) 2020-08-02 21:10:35 +02:00
asynts
707d92db61 Refactor: Change the AK::binary_search signature to use AK::Span. 2020-07-26 16:49:06 +02:00
Nico Weber
0e10a92ebc LibLine: Add Ctrl-N/P as history next/previous shortcuts 2020-07-13 19:48:53 +02:00
Nico Weber
b0384bb1bb LibLine: Move search-related updates into do_cursor_left/right
This way, arrow-left and arrow-right behave consistently with ctrl-b/ctrl-f.
2020-07-13 19:48:53 +02:00
Nico Weber
6105f063cb LibLine: Add ctrl-t shortcut for transposing characters 2020-07-07 23:13:25 +02:00
Nico Weber
ad8e784938 LibEdit: Make Ctrl-d on an empty line mean EOD again 2020-07-07 18:43:09 +02:00
Nico Weber
f27e5ac68d LibLine: Support Ctrl-b/f and Ctrl-d
And make the existing cltr-h handler easier to see.
2020-07-06 22:41:35 +02:00
Nico Weber
72f8b3d185 LibLine: Extract lambdas for cursor-left, cursor-right, delete
Also move the existing backspace lambda out of the loop.

The do_delete() extraction fixes a minor bug where
InputState::ExpectTerminator wasn't entered if delete was pressed at the
very end of a line. Now that this is fixed, there's no more
"LibLine: Unhandled final: 7e (~)" when hitting delete at the end of the
line.
2020-07-06 22:41:35 +02:00
Nico Weber
8c82138b22 LibLine: Put ctrl-key handlers in alphabetical order 2020-07-06 22:41:35 +02:00
Nico Weber
4726966ad7 LibLine: Replace some magic numbers with a magic function 2020-07-06 22:41:35 +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
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +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
Emanuele Torre
5c6323c130 LibLine: Remove unused header in Span.h 2020-05-29 07:59:45 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +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
Linus Groh
4e607192c7 LibLine: Don't add empty lines to history 2020-05-26 00:50:49 +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
679a84d44c LibLine: Default to resetting styles when a cell has no styles set 2020-05-23 17:05:18 +02:00
AnotherTest
909ac2a558 LibLine: Make the comments follow the project style 2020-05-23 01:31:41 +02:00
AnotherTest
3c3edf5831 LibLine: Properly paginate suggestions in XtermSuggestionDisplay
This commit adds back suggestion pagination, and makes it 10x better.
Also adds a "< page m of n >" indicator at the bottom if there are more
suggestions than would fit in a page.
It properly handles cycling forwards and backwards :^)
2020-05-23 01:31:41 +02:00
AnotherTest
2427f3b38b LibLine: Add a constructor for CompletionSuggestions purely for comparison
`CompletionSuggestion(text, ForSearch)` creates a suggestion whose only
purpose is to be compared against.
This constructor skips initialising the views.
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
Linus Groh
fbcfc8dcd0 LibLine: Hide debug output behind SUGGESTIONS_DEBUG define 2020-05-21 22:50:14 +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
c38c2668da LibLine: Default to resolving Spans as byte offsets
This allows all the unicode processing to be internal to the line
editor.
2020-05-19 20:02:28 +02:00
AnotherTest
082cd7048e LibLine: Handle <return>s in incomplete data correctly
Previously, we would concatenate all the commands together:
```
> sleep 5
echo well
echo hello
echo friends

> echo wellecho helloecho friends
```

Also renames some variables to be more descriptive.
2020-05-19 11:59:28 +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
AnotherTest
98d25324fd LibLine: Add a hook to run when an interrupt is handled
We do not want to clog up signal handlers by putting possibly complex
logic inside them, so allow the editor to handle that.
2020-05-13 15:07:44 +02:00
AnotherTest
b64bb7a3e1 LibLine: Fix suggestion spacing regression
This patch fixes an issue where the line editor would put no spacing
between suggestions (only when there are two suggestions).
To reproduce, try on a build with no ports (starting with `pro`):
```
> pro<tab>
profilepro
```
2020-05-12 08:57:14 +02:00
AnotherTest
c88c883f44 LibLine: Show suggestions in pages if they don't fit on the screen
We can now cycle pages of suggestions when there are more suggestions
than we can fit on one screen.
This does not inculude a visual indicator that more pages exist,
however.
2020-05-11 09:33:18 +02:00
AnotherTest
c40fd3a902 LibLine: Support RGB colors
This also patches Userland/js.
2020-05-10 10:23:05 +02:00
AnotherTest
ccdef5a675 LibLine: Expose actual_rendered_string_length & accept newlines in prompt 2020-05-10 10:23:05 +02:00
AnotherTest
7f1d3f6d62 LibLine: Handle ^L while in search mode
This commit fixes the following misbehaviour:
```
> <- search prompt moves here
>
> ^R^L <- actual prompt stays here
```
2020-05-02 11:57:21 +02:00
AnotherTest
977aa3968c LibLine: Reset inline_search_cursor along with cursor
This fixes the issue where the editor would only scroll up one command
and then 'search' for it
2020-04-30 22:14:59 +02:00
AnotherTest
a80ddf584f Shell+LibLine: Handle escaped characters correctly
This patchset fixes incorrect handling of escaped tokens (`a\ b`) in
Shell autocompletion and LibLine.
The users of LibLine can now choose between two token splitting modes,
either taking into account escapes, or ignoring them.
2020-04-30 09:07:38 +02:00
Andreas Kling
86810a4b02 LibLine: Actually fix build :^) 2020-04-29 00:03:19 +02:00
AnotherTest
a6fcf70e25 LibLine: Properly mark the result of read() as ignored
Unbreaks the build.
2020-04-28 23:48:38 +02:00
AnotherTest
e83300dc27 LibLine: Drop stray input before doing vt_dsr
This patch fixes the issue where some data would be buffered while the
editor is not editing, and vt_dsr would read them, resulting in the
cursor to jump to (1,1)
2020-04-28 23:29:07 +02:00
AnotherTest
9473733d7a LibLine: Handle initialize() internally
This patch makes initialize() transparent to the users, but exposes it
publicly, as the users might need a copy of the default termios (i.e.
Shell)
2020-04-28 23:29:07 +02:00
AnotherTest
7ecf29f206 LibLine: Ignore interrupts unless actively editing
It does not make much sense to receive an interrupt and process it
*much later*.
Also patches Userland/js to only create exceptions while some code is
actually running.
2020-04-28 23:29:07 +02:00
AnotherTest
1a7af4d677 LibLine: Do not ignore ^C and do not finish() after interrupt 2020-04-22 12:12:41 +02:00
AnotherTest
730ca98698 LibLine: Avoid OOB access when one of the suggestions is the prefix 2020-04-22 11:35:53 +02:00
AnotherTest
364ca1f476 LibLine: Autocomplete already-complete suggestions
Suggesting whatever the user has input is not quite sane :^)
2020-04-20 20:23:26 +02:00
AnotherTest
f9b0490383 LibLine: Handle ctrl-{left,right}_arrow by jumping between words
Words are delimited by spaces.
Perhaps this should be a configurable behaviour?
2020-04-20 20:23:26 +02:00
AnotherTest
e578b7884b LibLine: Properly handle ^C and do not return after being interrupted
this commit fixes a...surprisingly long-standing ^C bug, where it would
return the buffer instead of voiding it and starting over :^)
2020-04-20 17:27:30 +02:00
AnotherTest
42f06fc305 LibLine: Implement searching via up/down arrow keys 2020-04-20 17:27:30 +02:00
AnotherTest
58912994ab LibLine: Implement ^R searching
This commit adds searching in the editor history with ^R.
It does so by instantiating...another Line::Editor inside the current
Line::Editor :^)
2020-04-20 17:27:30 +02:00
AnotherTest
c97ca2fecc LibLine: Clear trailing trivia when cycling if the suggestion has any 2020-04-19 19:39:50 +02:00
AnotherTest
cb3cf589ed LibLine: Allow suggestions to have trailing trivia strings
These strings would be applied when inserted into the buffer, but are
not shown as part of the suggestion.

This commit also patches up Userland/js and Shell to use this
functionality
2020-04-19 17:21:55 +02:00
AnotherTest
7ef48171ce LibLine: Complete only common prefixes, and tweak suggestion logic
On the first tab, only complete the token without suggesting extra
stuff, and on further tabs, show suggestions.
Except in one case where the completion is all in the buffer, then
we show the suggestions, but do no completion.
2020-04-19 17:21:55 +02:00
AnotherTest
6b513ca97e LibLine: Avoid crashing if given empty suggestions 2020-04-15 16:38:25 +02:00
AnotherTest
32276cba7a LibLine: Properly handle multiline suggestions 2020-04-15 08:46:42 +02:00
AnotherTest
8ebee4bce6 LibLine: Update display when deleting forward 2020-04-13 12:26:43 +02:00
AnotherTest
364dbe28d6 LibLine: Remove unused cut_mismatching_chars() function
This is superceded by the suggest() mechanism
2020-04-13 00:49:24 +02:00
AnotherTest
fa0525b8bf LibLine: Autocomplete single suggestions
`cd /h<tab>` -> `cd /home/`, pressing tab after that would
descend into `/home/' and show `/home/anon/`
2020-04-13 00:49:24 +02:00
Linus Groh
c106451daf LibLine: Cycle backward through suggestions using Shift+Tab 2020-04-11 20:42:17 +02:00
AnotherTest
2fdce695d6 LibLine: Display suggestions and cycle between them
With extra color (tm)
This commit also patches the users of LibLine to properly use the new
API
2020-04-11 17:15:19 +02:00
AnotherTest
b59a391a78 LibLine: Ask for cursor position once and handle the rest internally
Prior to this, writing to stdin while a display refresh was happening
corrupted the input and displayed garbage.
2020-04-11 17:15:19 +02:00
AnotherTest
f946d6ce79 LibLine: Properly handle window resize by not spamming DSRs
We have all the information necessary to find our new origin when a
window size change occurs.
2020-04-11 14:29:25 +02:00
AnotherTest
173c65660a LibLine: Properly show and cleanup suggestions
Prior to this, we would display them and never clean then up.
2020-04-11 14:29:25 +02:00
Andreas Kling
c06d5ef114 Kernel+LibC: Remove ESUCCESS
There's no official ESUCCESS==0 errno code, and it keeps breaking the
Lagom build when we use it, so let's just say 0 instead.
2020-04-10 13:09:35 +02:00
AnotherTest
2315f789cc LibLine: Appropriately react to window size changes 2020-04-10 11:26:44 +02:00
AnotherTest
1b422315fa LibLine: Fix regression with moving around in history misplacing cursor
This commit fixes a regression where the prompt would not be cleared
upon substitution of lines from the history
2020-04-10 11:26:44 +02:00
AnotherTest
da9335dbec LibLine: Implement multiline editing
This commit also adds the ability to change the prompt mid-edit :^)
2020-04-10 00:58:59 +02:00
AnotherTest
c2f8a5fffa LibLine: Add live styling support
This patchset adds an stylization interface to LibLine, and breaks
multiline editing.
With the most adorable Style constructor I've ever seen :^)
2020-04-05 16:11:13 +02:00
AnotherTest
8f08ec5038 LibLine: Restore previous state only if initialized
This makes the library safe to construct/destruct without actually using
it.
2020-04-02 08:49:11 +02:00
Andreas Kling
296f87fa7f LibLine: Fix Shell crashing (due to write() EFAULT) on <tab><tab>
Use a StringBuilder instead of blindly passing a bunch of potentially
empty/null strings to the kernel. StringBuilder is more lenient and
generally more pleasant to use anyway.
2020-04-01 11:25:53 +02:00
Andreas Kling
28edafbfa6 LibLine: Fix build in Linux environment
My host compiler was complaining about "%b" in format strings and about
ignoring the return value from a bunch of write() calls.
2020-03-31 18:59:15 +02:00
Andreas Kling
c7257ed827 LibLine: Rename on_char_input() => register_character_input_callback()
The "on_foo" format is our convention for public callback members.
2020-03-31 13:37:01 +02:00
Andreas Kling
8ab576308f LibLine: Rename LineEditor.{cpp,h} => Editor.{cpp,h} 2020-03-31 13:34:57 +02:00
Andreas Kling
6595469de1 LibLine: Rename LineEditor to Line::Editor 2020-03-31 13:34:06 +02:00
Andreas Kling
a30a3277a3 LibLine: Rename from LibLineEdit 2020-03-31 13:32:11 +02:00