larzcommand
Command pattern with undo/redo.
Undo is one of the most-loved features in software, and the trick behind it is the command pattern: wrap each action as a command that knows how to do AND undo itself, and keep a history. larzcommand gives you exactly that - define commands, run them through a History, get undo/redo for free.
larzscript pkg install command
What you get
- Reversible commands (class or funcs)
- History do/undo/redo
- can_undo / can_redo + limit
- The trick behind every undo button
Try it
import "command" as command
let h = command.new(50)
let doc = {"text": ""}
fn append(doc, s) {
let before = doc["text"]
command.run(h, fn() { doc["text"] = before + s }, fn() { doc["text"] = before })
}
append(doc, "Hello")
append(doc, " World")
command.undo(h)
print(doc["text"])
command.redo(h)
print(doc["text"])Output
Hello Hello World
Why it's in the Larz Stack
larzcommand is a real Larzscript package (larzscript pkg install command) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.