| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
If, for whatever reason, the autocomplete() functions fails, don't panic
and quit. Instead, return an empty string.
Signed-off-by: Rory Dudley <rory@netc.lu>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch expands upon the last one, by providing a filepath
autcomplete routine, which works more similarly to that of zsh or bash.
It works for:
- Any paths containing the current directory (`.`)
- Any paths containing the parent directory (`..`)
- Any paths containing the root directory (`/`)
- Any paths that don't contain any explicit directory (defaults to the
current directory, i.e. `.`)
In order to achieve this, the pwd (present working directory) was broken
out from the autocomplete() function, and is now recomputed every time a
character is typed (in the getline() function). pwd always starts off as
the current directory, but may change based off of user input. If the
current directory cannot be read (likely due to a permissions issue),
dwvsh defaults to the user's home directory for now.
The filepath autocomplete also works for paths with mutliple directories
now (i.e. /etc/mail/xxx), will still allow you to autocomplete files and
directories beginning with 'xxx' inside the '/etc/mail' directory.
It is also possible to use the tilda character (`~`) with the filepath
autocomplete now (it denotes the user's home directory, for instance,
autocomplete works for '~/.config/').
Finally, some logic for Shift+Tab was added to autocomplete. It works
the same as Tab, except runs backwards through the files and directories
(as opposed to forwards).
Signed-off-by: Rory Dudley <rory@netc.lu>
|
|
|
|
|
|
|
|
|
| |
This patch adds a fairly rudimentary form of autocomplete. For starters,
it only works for filepaths, not for programs. Additionally, it
currently only works for the present working directory. You cannot yet
autocomplete even one more level deep.
Signed-off-by: Rory Dudley <rory@netc.lu>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The getchar() function was changed so that it is able to detect some
ANSI escape sequences. To better handle this, getchar() now returns a
value from the Key enum, indicating whether or not an escape sequence
was found. Currently, the only escape sequences the function deals with
are arrow keys.
Handling of the left and right arrow keys were added to the getline()
function, in order to allow a user to go back and edit their command
inplace. Up and down arrow keys are also handled, but they are just
ignored for now (i.e. they do not move the cursor around anymore). The
local 'pos' variable became an Arc<Mutex<usize>>, since it needs to be
reset to 0 if ctrl-c is pressed (the handler for which is outside the
scope of getline()).
Signed-off-by: Rory Dudley <rory@netc.lu>
|
|
|
|
|
|
|
| |
Keep track of the cursor position in getline(), this way it is not
possible to backspace the prompt.
Signed-off-by: Rory Dudley <rory@netc.lu>
|
|
Added the termios crate to facilitate the changing of certain terminal
options. It is a wrapper around the termios C library, so 'man 3
termios' for more details.
Added the custom getchar() function, with retrieves characters from
STDIN as they are typed by the user (as opposed to waiting for a
newline, like io::stdin().read_line()). This is necessary, since keys
like <tab> and <up> have special functionality, which needs to be acted
on before command submission.
Added the custom getline() function, which uses getchar() to read
characters as they are typed. The getline() function contains the logic
for the various key presses. For most characters, we simply push the
byte to a buffer, and print it out to the screen (since getline()
assumes ECHO is off).
Signed-off-by: Rory Dudley <rory@netc.lu>
|