summaryrefslogtreecommitdiffstats
path: root/src/poem/anthology.rs
Commit message (Collapse)AuthorAgeFilesLines
* Add/update doc commentsRory Dudley2024-06-301-1/+56
| | | | | This patch update a ton of the documentation comments throughout the codebase, refactoring some areas, and adding new comments to others.
* Add back spellcheckRory Dudley2024-06-141-38/+3
| | | | | | | | | | | | | | This commit reworks spellcheck() so it is more verbose about what it returns. It also re-introduces the use of spellcheck() in Poem::recite(). Spellcheck now returns a value in the enum, Spelling: FullPath -> Indicates a full path was specified as the verb OnPath -> Indicates the verb is on the $PATH BuiltIn -> Indicates the verb is a built-in command None (Option) -> The verb does not exist This commit also removes some defunct (commented-out) code.
* Updated the way built-in commands are called/usedRory Dudley2024-06-041-13/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, built-in commands were fairly primitive, merely outputting STDOUT and STDERR with the print! macros. However, we need them to behave like normal programs, that is: - Acknowledge their verse's meter (forking, piping, etc.), - Ability to capture STDOUT and STDERR (>, 2>), - and Affect the currently running environment. For these reasons, the anthology was reworked, and now contains the Anthology struct, which mimics both std::process::{Child, Command}. The AnthologyStdin helper struct was also created, for built-ins to take input on STDIN, though no built-in is currently using it. Each built-ins' incant functions were updated to return a std::process::Output. It contains output from STDOUT, output from STDERR, and the exit code of the "process". A fix was also implemented for aliases, where the STDOUT and STDERR vectors were not being copied to the newly constructed verse. Notes: There is some cleanup that needs to happen on this patch. For one, the spellcheck function is no longer being used, so there is a generic OS error if the program cannot be found in the $PATH. Also, anthology::lookup gets called twice, which shouldn't need to happen.
* Added the 'which' built-in commandRory Dudley2024-05-201-2/+4
| | | | | | Added a built-in which command (for MacOS and BSD), which can check aliases, and other shell built-in commands, in addition to bins on the $PATH.
* Capture STDOUT as bytes, and convert to string when necessaryRory Dudley2024-04-061-1/+1
| | | | | | | | | | | | | Previously, the recite() function created the 'out' variable, which was a String, that got passed to the various incant functions, in order to capture STDOUT in certain situations. In cases where STDOUT was captured, it was first converted to a String, and then appended to the 'out' variable, by means of String::from_utf8_lossy(). This works for basic text, however, does NOT work for binary data. This becomes problematic, when for example, downling a tar file with curl/wget, that is then piped ('|') to the tar program. Using from_utf8_lossy() in this case can corrupt the tar file. This patch makes it so that out is stored as bytes by default, and only converted to a String when necessary.
* Add better support for aliasesRory Dudley2024-04-041-3/+3
| | | | | | | | | | | | | | | Make sure to interpret alias values as their own poems, since aliases can be fairly complex. Notes: Previously, I was doing a simple find and replace for aliases within each verse. However, aliases can be fairly complex, containing their own range of meters, commands, and io operations. This could cause problems, since a verse should never have, for instance, a pipe (`|`) in the middle of it. This patch fixes it, so that we iterate once through the poem, generating a new poem based on aliases that are found. In order to avoid two loops in the recite() function, it might make sense to offload handling aliases to read().
* Document aliases in the docstring for lookup()Rory Dudley2024-03-311-0/+4
| | | | | Add documentation for anthology::lookup(), with a list containing all the default aliases for builtin commands.
* Add docstring comments to all the anthology functionsRory Dudley2024-03-311-1/+17
| | | | | | Add docstring comments for all the incant function throughout the anthology, documenting what each function does, and an example of it's shell command.
* Add the 'unset' built-in commandRory Dudley2024-03-301-1/+4
| | | | | Add the 'unset' command to remove global environment variable definitions from the shell.
* Add the 'alias' built-in commandRory Dudley2024-03-301-5/+8
| | | | | | | | | | | The shell now has support for aliases (via alias foo=bar). The 'unalias' command is also available to remove aliases. Finally, Environment::aliases was changed to be a HashMap<String, String>, instead of a Vec<String>. Since the verse's verb might change (for instance, it is an environment variable, or an alias), add another check in Poem::recite, which simply continues, instead of running the spellchecker, if the verb is empty.
* Fix the buildRory Dudley2024-03-301-0/+1
| | | | Need to include line to import compose::Environment.
* Add wrapper for global shell environmentRory Dudley2024-03-301-2/+2
| | | | | | | | Instead of having to pass around a bunch of different data structures for various shell functions, create the wrapper compose::Environment, which serves as a global shell state. It is configured via login/profile/rc scripts initially, but can of course be modified throughout the lifetime of the shell.
* Remove hard-coded PATHRory Dudley2024-03-281-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Use $PATH, instead of a hard-coded PATH from main(). This means that there is no longer a need to pass around PATH to repl()/recite()/path::refresh(), since path::refresh() can call env::var directly. Since the hard-coded paths were removed, there needs to be some way to define $PATH. When running the debug build, dwvsh will look in 'dist/etc/dwvshrc' for the initial environment setup. For the release target, dwvsh will look in '/etc/dwvshrc'. After the global rc file is sourced, dwvsh will try to source ~/.dwvshrc if it exists, so users can extend their environment without root access (assuming a release install). Notes: Throughout a lot of this program, we're calling `env!("HOME")`, in order to get the user's home directory. Technically, this is not correct. The env!() macro resolves environment variables during compile time, while env::var() gets environment variables for the running process (i.e. the shell). See https://users.rust-lang.org/t/env-vs-env-var/88119 for more info. In the near future, this will need to be addressed. Might be worth looking into what other shells do, though one idea I had was to invoke '/usr/bin/id', grab the user's ID, and use it to grab the rest of the info from /etc/passwd. This would be handled in an /etc/dwvlogin or /etc/dwvprofile most likely.
* The anthology moduleRory Dudley2024-03-281-0/+32
The anthology module was added to run built-in commands. The 'cd' and 'exit' built-ins were moved from the main recite() loop to this module. Additionally, the 'export' and 'source' built-ins were added.