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.
https://vimeo.com/205701269
# Fedora sudo dnf install ncurses-develDebian/Ubuntu
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
mingw-w64-x86_64-ncurses
pacman -S mingw-w64-x86_64-ncurses mingw32-make build
jCursor down
kCursor up
hCursor left
lCursor right
0Cursor to the beginning of the line
$Cursor to the end of the line
iInsert before
IInsert at the beginning of the line
aInsert after
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
uUndo
rRedo (Unstable)
:qquit
:wsave
:wqsave then quit
Feel free to contribute! :)
buffer
update_state(st)and
render_update(st)
selectorsin redux,
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
bufferstate.
render_update(state_t *st)will actually render everything on the screen according to the result from
update_state().
Viw's undo & redo functionality is based on the state machine replication principle 1. Initialization: * Deep clone the initial buffer. * Initialize two stacks (
history stackand
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
Our main
stateobject has two children states, namely
bufferand
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.
bufferand/or
screen. Those states include cursor positions, aount of space reserved for line numbers, etc.
buffer.h