Command is behavioral design pattern that converts requests or simple operations into objects.
The conversion allows deferred or remote execution of commands, storing command history, etc.
In Rust, a command instance should NOT hold a permanent reference to global context, instead the latter should be passed from top to down as a mutable parameter of the “
Text Editor: Commands and Undo
- Each button runs a separate command.
- Because a command is represented as an object, it can be pushed into a
history array in order to be undone later.
- TUI is created with
command.rs: Command Inteface
command/copy.rs: Copy Command
command/cut.rs: Cut Command
command/paste.rs: Paste Command
main.rs: Client code