Commit Graph

15 Commits

Author SHA1 Message Date
William McPherson
61f2704d58 Shell: Tab completion for paths
If the cursor is in front of a token that is not the first token, we try
to split it on the last slash. If there is a slash, the first part is
the directory to search and the second part is the token to complete.
If there is no slash, we search the current directory and use the entire
token for completion.
If we find a single match and it's a directory, we add a slash. If it's
a normal file, we add a space, unless there already is one.

Also renamed cut_mismatching_chars() parameters to be more appropriate.
2019-12-11 12:10:52 +01:00
William McPherson
4ae8d929b4 Shell: Improve tab completion behaviour
A space is added if only one match is found, but we avoid adding
redundant spaces.

We complete "empty" tokens, i.e. when the cursor is at the start of the
line or in front of a space. For example:
    mkdir test
    cd test
    touch test
    chmod +x test
    export PATH=/home/anon/test
Now if you press tab, or space and then tab, you will get "test". Notice
that you also get a space.

Completion is now done relative to the cursor. You can enter two words
and then go back and complete the first one.
2019-12-11 12:10:52 +01:00
William McPherson
244e525c73 Shell: Refactor append/insert procedure
This patch just factors out the procedure of adding characters at the
cursor position. It makes tab completion code much nicer.
2019-12-11 12:10:52 +01:00
William McPherson
bb311b970f Shell: Improve readability of cache_path()
I prefer String::format over StringBuilder here.
Also simplified a weird continue statement.
2019-12-11 12:10:52 +01:00
Andreas Kling
6f4c380d95 AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
2019-12-09 17:51:21 +01:00
William McPherson
aa8b40dce6 Shell: Cache PATH for faster tab completion
This patch reduces the O(n) tab completion to something like O(log(n)).
The cache is just a sorted vector of strings and we binary search it to
get a string matching our input, and then check the surrounding strings
to see if we need to remove any characters. Also we no longer stat each
file every time.

Also added an #include in BinarySearch since it was using size_t. Oops.

If `export` is called, we recache. Need to implement the `hash` builtin
for when an executable has been added to a directory in PATH.
2019-12-05 17:09:22 +01:00
willmcpherson2
dccab569d2 Shell: Tab completion for programs in PATH
This patch adds a function to LineEditor that takes the current shell
buffer, searches PATH for the first program that starts with that
buffer and then compares that to any other programs starting with the
buffer to remove any mismatching characters off the end. The result is
appended to the buffer.

This may be faster with a data structure but that seems overkill.
2019-09-15 19:27:44 +02:00
Andreas Kling
73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00
Conrad Pankoff
36e3e7b75a Shell: Support forward delete 2019-08-18 07:36:23 +02:00
Andreas Kling
253e391bfc Shell: Implement support for terminal clearing with ^L.
Make LineEditor::get_line() responsible for printing the prompt. That way
we can re-prompt after clearing the screen on ^L.

This makes the Serenity Terminal feel a little bit more like home :^)
2019-07-19 20:01:46 +02:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Robin Burchell
0dc9af5f7e Add clang-format file
Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
2019-05-28 17:31:20 +02:00
Andreas Kling
67108f872f Shell: Make ^W and ^U work when cursor is not at the end of the line. 2019-05-07 05:29:07 +02:00
Andreas Kling
ad1c3c748f Shell: Allow browsing history with up/down arrow keys. 2019-05-07 02:50:15 +02:00
Andreas Kling
ba7364b43b Shell: Move line editing to a separate class.
To be clear, there isn't really any line editing yet. But there is
going to be, so let's have it in its own class.
2019-05-07 01:39:41 +02:00