Skip to content

Latest commit

 

History

History

command

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Command

Command is behavioral design pattern that converts requests or simple operations into objects.

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 "execute" method:

fn execute(&mut self, app: &mut cursive::Cursive) -> bool;

Text Editor: Commands and Undo

How to launch:

cargo run --bin command

Key points:

  • 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 cursive crate.

Text Editor screenshot

Reference

This example is inspired by Command in Java (Example).