Ruvim Text Editor Implementation

Implementation

Ruby + C Code.

Buffer

Bidirectional Linked List

Each character is a node in the list. A separate array can be mantained with the length, start, and end of the line.

Pros:
Cons:

User Interface

Panel Alignment

Panel alignment is done keeping a Client constant containing the coordinates of a box describing the current available space in the screen.

Window Events

Update
Called when keyboard, mouse event or when the user resizes the terminal window.
Refresh
Signal Windows to refresh.
Redraw
Called when window needs to be completely redrawn.

Cursor Movement

Possible movements are:

Character
Up, Down, Left, Right
Word
Next, Previous
Line
Beggining, End, Next, Previous
Paragraph

API

Our Editor will have an API to allow programmers to write scripts and macros.

Mappings

Ruby's blocks are the perfect way to store editor macros.

Event Handling

Editor Features

Handling TABS

Handling TABS is simple. To Move forward we can simply used the formula tabsize - x % tabsize to count the number of spaces occupied by the TAB character. Moving Backwards is a bit more complicated. We need to count the space occupied by the text from the start of the line to the previous character.

Plugin System

Plugin module keeps track of plugins. There are two kinds of plugins:

Application Plugins
Global plugins available to the application class ($ruvim).
Editor Plugins
Editor Plugins constructed everytime a new editor instance is created
Plugins can add mappings to the editors by defining a method mappings.

Crash Recovery

A copy of the file will be stored in a swap file.

Terminals

ALT/META Keys