summaryrefslogtreecommitdiff
path: root/Shell/LineEditor.cpp
AgeCommit message (Collapse)Author
2020-02-02LibCore: Put all classes in the Core namespace and remove the leading CAndreas Kling
I've been wanting to do this for a long time. It's time we start being consistent about how this stuff works. The new convention is: - "LibFoo" is a userspace library that provides the "Foo" namespace. That's it :^) This was pretty tedious to convert and I didn't even start on LibGUI yet. But it's coming up next.
2020-01-19Shell: Don't crash when stdout is not a TTYAndreas Kling
Let's just pretend we have 80 columns while running non-interactively. There are definitely nicer solutions here, and we should find them.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-12-17Shell: Tab completion now gives suggestionsJesse Buhagiar
Pushing the TAB key in the shell now prints suggestions to terminal. This makes it easier to the user to actually see what files are available before executing the command they currently have typed.
2019-12-11Shell: Tab completion for pathsWilliam McPherson
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-11Shell: Improve tab completion behaviourWilliam McPherson
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-11Shell: Refactor append/insert procedureWilliam McPherson
This patch just factors out the procedure of adding characters at the cursor position. It makes tab completion code much nicer.
2019-12-11Shell: Improve readability of cache_path()William McPherson
I prefer String::format over StringBuilder here. Also simplified a weird continue statement.
2019-12-09AK: Use size_t for the length of stringsAndreas Kling
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-05Shell: Cache PATH for faster tab completionWilliam McPherson
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-11-01Shell: Exit the shell on (interactive) EOF with empty bufferAndreas Kling
In other words, if the user presses EOF (normally Ctrl+D), we now print out "<EOF>" and exit the shell without error. Fixes #701.
2019-09-15Shell: Tab completion for programs in PATHwillmcpherson2
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-02Shell: Added support for ctr-e/a.marprok
By pressing ctr-e/a the cursor goes to the end/beginning of the current line.
2019-08-18Shell: Support forward deleteConrad Pankoff
2019-07-19Shell: Implement support for terminal clearing with ^L.Andreas Kling
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-08Shell: Handle SIGWINCH to get a nice behavior when resizing.Andreas Kling
When resizing the terminal, we now clear the entire current line and reset the shell's LineEditor input state. This makes it look and feel kinda the same as xterm. Fixes #286.
2019-06-07Shell: Run clang-format on everything.Andreas Kling
2019-05-15Kernel: Add a beep() syscall that beeps the PC speaker.Andreas Kling
Hook this up in Terminal so that the '\a' character generates a beep. Finally emit an '\a' character in the shell line editing code when backspacing at the start of the line.
2019-05-07Shell: Make ^W and ^U work when cursor is not at the end of the line.Andreas Kling
2019-05-07Shell: Support home/end keys for line editing.Andreas Kling
2019-05-07Shell: Support basic line editing with left/right arrow keys.Andreas Kling
2019-05-07Shell: Ignore tab key for now.Andreas Kling
2019-05-07Shell: Allow browsing history with up/down arrow keys.Andreas Kling
2019-05-07Shell: Move line editing to a separate class.Andreas Kling
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.