sketch
A Rust TUI library
Features
Key Concepts
Model::update
The update method processes events by taking a Msg as input. This could be a keyboard key, mouse input, or a custom message. Based on the message, it:
- Updates the model to its next state.
- Optionally returns another message to be processed.
For example:
Model::view
The view method is responsible for rendering your model into a string. You can use Style to apply formatting:
Message
A message is any type that implements the Message trait. The Msg type given to Model::update holds a Message. The benifet of this approach is messages can be defined by other crates like widget libraries.
A message can be defined like this:
Your message can then be sent using the app's Sender which you can get with App::sender:
let app = new;
let sender = app.sender;
sender.send;
app.run;
For example if you need to make and HTTP request you could spawn a thread to complete the request and then send a message using the sender.
Sketch includes the following messages:
Quit: Send to quit the app.Key: Keyboard input.Mouse: Mouse input.Focus: Focus changes.Paste: Clipboard pastes. Only if the paste feature is enabeld.