Blyx Nest Blyx language
Registry / Framework
framework · v0.1.2

Undo Cursor

Bound undo traversal by the number of applied edits and clear history at a committed savepoint.

Source repository · Package JSON

Use Undo Cursor

use vendor::undo_cursor::undo_cursor;

Run the example

nest demo undo_cursor@0.1.2
blyxc native-run undo_cursor-demo/main.blyx
Example source and expected output
use std::cli;
use std::text;
use vendor::undo_cursor::undo_cursor;

fn main() {
    let arguments = cli_args();
    if args_len(arguments) > 0 {
        if args_len(arguments) % 2 != 0 {
            stderr_line("Expected event and value pairs");
            process_exit(2);
        }
        let mut live = undo_cursor_start();
        let mut i = 0;
        while i < args_len(arguments) {
            let input = args_at(arguments, i + 1);
            if !text_is_number(input) {
                stderr_line("Expected a whole numeric event value");
                process_exit(2);
            }
            live = undo_cursor_step(live, args_at(arguments, i), text_number(input));
            let command = undo_cursor_command(live);
            println!(command);
            if command == "reject" { process_exit(1); }
            i += 2;
        }
        return;
    }
    let mut state = undo_cursor_start();
    state = undo_cursor_step(state, "open", 0.0);
    println!(undo_cursor_command(state));
    state = undo_cursor_step(state, "undo", 0.0);
    println!(undo_cursor_command(state));
    state = undo_cursor_step(state, "apply", 0.0);
    println!(undo_cursor_command(state));
    state = undo_cursor_step(state, "apply", 0.0);
    println!(undo_cursor_command(state));
    state = undo_cursor_step(state, "undo", 0.0);
    println!(undo_cursor_command(state));
    state = undo_cursor_step(state, "save", 0.0);
    println!(undo_cursor_command(state));
    state = undo_cursor_step(state, "close", 0.0);
    println!(undo_cursor_command(state));
}

Expected output

load_history
reject
push_edit
push_edit
pop_edit
reset_history
close_clean

Published versions

VersionPackageSource commitSHA-256
0.1.2Download ZIP · Browse filesc039710c401f88d436dbc34def0bc952c6906f01592c629579e3af03d165cf582220f8900e
0.1.1Download ZIP · Browse files98176fc532fb904684db46ff6a19a67fcba581c3ec250d70b5c1bf9be1f62af2fb21fae532
0.1.0Download ZIP · Browse files6349f23784eb6caf45297066453ae1567e1eacb42dc725073c346f8ad93731b483efb3cae6