GithubHelp home page GithubHelp logo

abhi-infrrd / viw Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lpan/viw

0.0 1.0 0.0 128 KB

VI Worsened, a lightweight and fun VI clone.

Home Page: http://lpan.io/what-i-learnt-from-viw/

License: GNU General Public License v3.0

Makefile 1.74% C 96.62% C++ 1.64%

viw's Introduction

Viw, the ghetto editor

VI Worsened, a lightweight and fun VI clone. Inspired by the 6-domino-cascade from the React world.

DEMO

https://vimeo.com/205701269

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]

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

Supported EX mode commands

  • :q quit
  • :w save
  • :wq save then quit

Hacking

Feel free to contribute! :)

How does it work

  1. initiate the state
  • Read file to buffer.
  • Set up interface with ncurses
  1. Listen to keyboard events.
  • Each supported keybinding is mapped to a method that mutates the buffer
  1. Run update_state(st) and render_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 mutated buffer state.
  • render_update(state_t *st) will actually render everything on the screen according to the result from update_state().
  1. Goto step 2

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/or screen. 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.

viw's People

Contributors

azhng avatar lpan avatar mrkajetanp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.