VI Worsened, a lightweight and fun VI clone.
VI Worsened, a lightweight and fun VI clone. Inspired by the 6-domino-cascade from the React world.
# Fedora sudo dnf install ncurses-devel
sudo apt-get install libncurses5-dev
git clone https://github.com/lpan/viw cd viw/ make build ./viw [filename]
Using mingw compiler on Windows, you need to install
pacman -S mingw-w64-x86_64-ncurses mingw32-make build
0Cursor to the beginning of the line
$Cursor to the end of the line
IInsert at the beginning of the line
AInsert at the end of the line
oAppend line then insert
OPrepend line then insert
ddDelete line under the cursor
ggGo to the first line of the file
GGo the last line of the file
:wqsave then quit
Feel free to contribute! :)
update_state(state_t *st)will update all the computed properties (such as cursor position, rows to be displayed on the screen, etc) according to the new mutated
render_update(state_t *st)will actually render everything on the screen according to the result from
Viw's undo & redo functionality is based on the state machine replication principle 1. Initialization: * Deep clone the initial buffer. * Initialize two stacks (
redo stack). 2. Capture all state-mutating functions and their payloads and push it on to the
history stack. 3. When the user hits
undo: * Pop the
history stackand the push the result onto
redo stack. * Clone the initial buffer and apply all the commands saved in the
history stackon top of it. 4. When the user hits
redo: * Pop the
redo stackand apply the command immediately onto the current buffer. 5. Clear the
redo stackwhen a command gets pushed to the
history stackby the user.
See https://github.com/lpan/viw/blob/master/src/controller.c#L152 for more details
stateobject has two children states, namely
screen. This seperation makes it easier to perform unit tests against the
buffer. It also facilitates the migration to a different rendering library in the future.
screen. Those states include cursor positions, aount of space reserved for line numbers, etc.