lpan / Viw
Licence: gpl-3.0
VI Worsened, a lightweight and fun VI clone.
Stars: ✭ 212
Programming Languages
c
50402 projects - #5 most used programming language
Projects that are alternatives of or similar to Viw
Dte
A small, configurable console text editor (moved to https://gitlab.com/craigbarnes/dte)
Stars: ✭ 98 (-53.77%)
Mutual labels: ncurses, text-editor
Sapling
A highly experimental vi-inspired editor where you edit code, not text.
Stars: ✭ 195 (-8.02%)
Mutual labels: text-editor
Pdcursesmod
Public Domain Curses - a curses library for environments that don't fit the termcap/terminfo model, modified and extended from the 'official' version
Stars: ✭ 182 (-14.15%)
Mutual labels: ncurses
Cursive
A Text User Interface library for the Rust programming language
Stars: ✭ 2,613 (+1132.55%)
Mutual labels: ncurses
2048 Cli
The game 2048 for your Linux terminal (https://github.com/gabrielecirulli/2048)
Stars: ✭ 176 (-16.98%)
Mutual labels: ncurses
Avaloniaedit
Avalonia-based text editor (port of AvalonEdit)
Stars: ✭ 201 (-5.19%)
Mutual labels: text-editor
Slate Plugins
A set of my personal Slate editor plugins, in a monorepo.
Stars: ✭ 191 (-9.91%)
Mutual labels: text-editor
Render
UIKit a-là SwiftUI.framework [min deployment target iOS10]
Stars: ✭ 2,150 (+914.15%)
Mutual labels: unidirectional-data-flow
Qmarkdowntextedit
A C++ Qt QPlainTextEdit widget with markdown highlighting support and a lot of other extras
Stars: ✭ 182 (-14.15%)
Mutual labels: text-editor
Nib
Wysiwyg / Text editor components built using React and Prosemirror
Stars: ✭ 181 (-14.62%)
Mutual labels: text-editor
Ngx Wig
Angular(...Angular 7, Angular 8, Angular 9, Angular 10, Angular 11) WYSIWYG HTML Rich Text Editor (from ngWig - https://github.com/stevermeister/ngWig)
Stars: ✭ 178 (-16.04%)
Mutual labels: text-editor
Ci edit
A terminal text editor with mouse support and ctrl+Q to quit.
Stars: ✭ 183 (-13.68%)
Mutual labels: text-editor
Goaccess
GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.
Stars: ✭ 14,096 (+6549.06%)
Mutual labels: ncurses
Cuishark
A protocol analyzer like a wireshark on CUI. cuishark is using libwireshark to analyze packets. https://cuishark.slankdev.net
Stars: ✭ 208 (-1.89%)
Mutual labels: ncurses
Knot
Unidirectional reactive state container for Android & Kotlin
Stars: ✭ 198 (-6.6%)
Mutual labels: unidirectional-data-flow
Viw, the ghetto editor
VI Worsened, a lightweight and fun VI clone. Inspired by the 6-domino-cascade from the React world.
DEMO
Dependencies
- gcc
- ncurses
# Fedora
sudo dnf install ncurses-devel
# Debian/Ubuntu
sudo apt-get install libncurses5-dev
Installation & usage
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
Supported keybindings
-
j
Cursor down -
k
Cursor up -
h
Cursor left -
l
Cursor right -
0
Cursor to the beginning of the line -
$
Cursor to the end of the line -
i
Insert before -
I
Insert at the beginning of the line -
a
Insert after -
A
Insert at the end of the line -
o
Append line then insert -
O
Prepend line then insert -
dd
Delete line under the cursor -
gg
Go to the first line of the file -
G
Go the last line of the file -
u
Undo -
r
Redo (Unstable)
Supported EX mode commands
-
:q
quit -
:w
save -
:wq
save then quit
Hacking
Feel free to contribute! :)
How does it work
- initiate the state
- Read file to buffer.
- Set up interface with ncurses
- Listen to keyboard events.
- Each supported keybinding is mapped to a method that mutates the
buffer
- Run
update_state(st)
andrender_update(st)
- Similar to
selectors
in 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 mutatedbuffer
state. -
render_update(state_t *st)
will actually render everything on the screen according to the result fromupdate_state()
.
- Goto step 2
Undo & Redo
Viw's undo & redo functionality is based on the state machine replication principle
- Initialization:
- Deep clone the initial buffer.
- Initialize two stacks (
history stack
andredo stack
).
- Capture all state-mutating functions and their payloads and push it on to the
history stack
. - When the user hits
undo
:- Pop the
history stack
and the push the result ontoredo stack
. - Clone the initial buffer and apply all the commands saved in the
history stack
on top of it.
- Pop the
- When the user hits
redo
:- Pop the
redo stack
and apply the command immediately onto the current buffer.
- Pop the
- Clear the
redo stack
when a command gets pushed to thehistory stack
by the user.
See https://github.com/lpan/viw/blob/master/src/controller.c#L152 for more details
Hierarchy of the states
Our main state
object has two children states, namely buffer
and 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.
The State
- The parent state stores computed states that depend on the
buffer
and/orscreen
. Those states include cursor positions, aount of space reserved for line numbers, etc.
The Buffer
- The buffer is represented as a two dimensional doubly linked list. This allows conatant time line/char deletion and insertion. Go to buffer.h for more information.
- Buffer is only allowed to be modified by the methods declared in
buffer.h
The Screen
- The screen is the state of the interface between viw and GNU ncurses. It stores information such as pointers to the ncurses windows, etc. You can learn more about it at screen.h.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].