Commit graph

144 commits

Author SHA1 Message Date
Andreas Kling
f35a723f61 Everywhere: Convert a bunch of dbgprintf() to dbgln() 2021-01-10 10:02:20 +01:00
AnotherTest
d3f51ee5c3 LibLine: It's okay to be interrupted while reading the DSR response
Fixes #4855.
2021-01-10 00:03:52 +01:00
AnotherTest
7059ca9b15 LibLine: Don't clear the displayed buffer when interrupted
Since we always restart on a new line, there's no reason to clear the
previous lines.
2021-01-10 00:03:52 +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
asynts
938e5c7719 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.Everything:

The modifications in this commit were automatically made using the
following command:

    find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-09 21:11:09 +01:00
Andreas Kling
9d6198b683 Everywhere: Colour => Color
The system language is US English. :^)
2021-01-09 14:03:06 +01:00
AnotherTest
4c98d00bef LibLine: Don't ignore ^C inputs when there are no registered handlers
Some people really like their ^C's, let's not make them sad.
2021-01-06 19:20:36 +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
Linus Groh
bbe787a0af Everywhere: Re-format with clang-format-11
Compared to version 10 this fixes a bunch of formatting issues, mostly
around structs/classes with attributes like [[gnu::packed]], and
incorrect insertion of spaces in parameter types ("T &"/"T &&").
I also removed a bunch of // clang-format off/on and FIXME comments that
are no longer relevant - on the other hand it tried to destroy a couple of
neatly formatted comments, so I had to add some as well.
2020-12-31 21:51:00 +01:00
asynts
50d24e4f98 AK: Make binary_search signature more generic. 2020-12-30 02:13:30 +01:00
Lenny Maiorani
765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
AnotherTest
5d1425718e LibLine: Treat leftover data in buffer as a read event
Fixes #4328.
2020-12-18 19:20:37 +01:00
AnotherTest
5e6b9cbc91 LibLine: Be less lazy when moving prompt origin row
Fixes the issue where adding multiple lines in one refresh cycle would
break cursor positioning.
2020-12-18 19:20:37 +01:00
Andreas Kling
b9b7b2b28a LibCore: Make IODevice::read_line() return a String
Almost everyone using this API actually wanted String instead of a
ByteBuffer anyway, and there were a bunch of slightly different ways
clients would convert to String.

Let's just cut out all the confusion and make it return String. :^)
2020-12-13 11:54:11 +01:00
Linus Groh
886b43e999 LibLine: Don't make Editor::load_history() cut off a character per line
For some reason we were not considering the last *two* characters from
the line's ByteBuffer, with the comment next to it talking about \n and
\0. However the buffer doesn't contain a null-byte, so we were
effectively removing the newline and the last character from each
history line!
2020-12-06 00:06:46 +01:00
Linus Groh
d412fbdcf3 Shell+LibLine: Support HISTCONTROL environment variable
This is implemented in Line::Editor meaning not only the Shell will
respect it, but also js, Debugger etc.

Possible values are "ignorespace", "ignoredups" and "ignoreboth", as
documented in Shell-vars(7), for now.

The default value for the anon user (set in .shellrc) is "ignoreboth".
2020-10-26 11:27:54 +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
691b105885 LibLine: Support basic escaped characters in config file
Until we can figure out how shift+enter works (or an alternative), this
can be used to input literal newlines:
```ini
[keybinds]
\\\n=\n
```
2020-10-22 23:49:51 +02:00
AnotherTest
c057225a36 LibLine: Support multi-character key callbacks 2020-10-22 23:49:51 +02:00
AnotherTest
a9cee8ee02 Shell+LibLine: Record the input offset of completions
This makes the completion entry retain information about how much of the
suggestion was part of the string that caused the match.
2020-10-04 23:12:28 +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
e1c54b8a0f LibLine: Implement ctrl-del: It does the same thing as alt-d, delete-word 2020-09-15 09:45:13 +02:00
Nico Weber
d7539cf497 LibLine: Support Alt + Arrow left/right
It does the same thing as Ctrl + Arrow left/right: Wordwise movement.
2020-09-15 09:45:13 +02:00
Nico Weber
83c07be794 LibVT+LibLine: Use 1;mods CSI parameters for ctrl/alt/shift-arrow keys
xterms send a bitmask (+ 1) in the 2nd CSI parameter if "special"
keys (arrow keys, pgup/down, etc) are sent with modifiers held down.

Serenity's Terminal used to send ^[[O, which is a nonexistent
escape sequence and a misread of VT100's ^[O (ie the '[' is
replaced by 'O'). Since the xterm scheme also supports shift
and alt modifiers, switch to that.

More flexible, and makes ctrl-left/right and alt-left/right work
in SerenityOS's bash port.

Also do this for page up/down.

No behavior change for SerenityOS's Shell.
2020-09-15 09:45:13 +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
da56e208ef LibLine: Disable editing events while searching
This also makes the editor clean as many lines as the searching took,
for instance, in the case of <C-r><C-c>ls<tab>, two lines should be
cleaned, not just one.

Fixes #3413.
2020-09-07 11:42:56 +02:00
AnotherTest
39d14c22d1 LibLine: Treat ^D as EOF only when the buffer is empty
As opposed to when the cursor is at the start of the buffer.
Fixes #3421.
2020-09-07 11:21:28 +02:00
AnotherTest
521475dc01 LibLine: Do not reset suggestion state immediately when encountering esc
Some multikey binding might depend on the suggestion state, and this is
indeed the case for 'reverse tab', which is just '^[[Z'.
Fixes #3407.
2020-09-06 13:00:02 +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
cf4870c93e LibLine: Do not ignore Ctrl-C when buffer is empty
I am told that this is how people test their shells.
That's bizarre to me, but sure :^)
2020-08-21 17:09:41 +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
2c5cc189c5 LibLine: Initialize the search editor when entering search
Prior to this, no keybinding were installed on the search editor, and so
editing wasn't really possible.
Also fixes <C-r> making infinite search editors.
2020-08-20 09:34:55 +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
bda1d7fd7b LibLine: Setup the keybindings after initialisation
This makes the keybindings that depend on `m_termios` (^W, ^U, etc) work.
2020-08-18 13:40:44 +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
AnotherTest
4409cb88c9 LibLine: Only write to the standard error
This fixes `> asdf` and allows for all sorts of stdout redirections.
2020-08-09 21:50:33 +02:00
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