5 releases
0.2.3 | Feb 1, 2021 |
---|---|
0.2.2 | Dec 31, 2020 |
0.2.1 | Dec 30, 2020 |
0.2.0 | Dec 29, 2020 |
0.1.0 | Dec 29, 2020 |
#322 in Text editors
18KB
223 lines
Simple Text Editor
This program implements a basic text editing protocol in which the following commands can be executed:
1 x
, where1
is the command to append text to a buffer, andx
is the arbitrary-length set of characters to append.2 n
, where2
is the command to delete text from a buffer, andn
is the number of characters from the back of the buffer to delete.3 i
, where3
is the command to print a character from the buffer, andi
is the 1-based index position of the character to print.4
, where4
is the command to undo a previously executed command (only affectinf commands1
or2
).
Note: The protocol specifies that the first line of the input read by the program is interpreted as the number of commands that follow.
Usage
To test this, build the code using the cargo
toolchain, invoking the Rust compiler. To install cargo
and Rust, see: https://www.rust-lang.org/tools/install
$ cargo build --bin editor
Then, use the provided test input file input.txt
, or create your own.
$ cat input.txt | ./target/debug/editor
This should print both the characters (one per line, per "print" command, e.g. 3
) as well as the final buffer after all commands have exectuted.
Contributions
This is just for fun! However, as someone who is always trying to improve their programming skills, I would be grateful to know where optimizations could be made. PRs are welcome. Or if a bug is encountered, file an issue and I'll take a look!