To make implementation easier, the different modes in Sapling are implemented as a state machine (technically a DFA). So each 'mode' should have a struct which implements editor::state::State (like editor::normal_mode::State).
The most useful part of this trait is the 'transition function', which is run every time the user presses a key. It also returns Box<dyn state::State>, which allows for state transitions on key presses (i.e. if the user presses : in normal mode, it should return the default command mode state to enter command mode).
So implementing command mode basically boils down to the following:
- Create a new
State for command mode (would make sense to put it in editor/command_mode.rs).
- Add an extra keybinding for
: in normal mode, which switches the editor into command mode (see quitting the editor with q for how to do this).
- Move
w and q from insert mode into command mode, and if you want you can also add a command to write the .dot code for the Dag to either the log or a file.
If you want more pointers, then just ask 😁 - the state transition code is quite unintuitive.
To make implementation easier, the different modes in Sapling are implemented as a state machine (technically a DFA). So each 'mode' should have a struct which implements
editor::state::State(likeeditor::normal_mode::State).The most useful part of this trait is the 'transition function', which is run every time the user presses a key. It also returns
Box<dyn state::State>, which allows for state transitions on key presses (i.e. if the user presses:in normal mode, it should return the default command mode state to enter command mode).So implementing command mode basically boils down to the following:
Statefor command mode (would make sense to put it ineditor/command_mode.rs).:in normal mode, which switches the editor into command mode (see quitting the editor withqfor how to do this).wandqfrom insert mode into command mode, and if you want you can also add a command to write the.dotcode for theDagto either the log or a file.If you want more pointers, then just ask 😁 - the state transition code is quite unintuitive.