A minimal text editor written for fun in plain Ruby with no dependencies.
I wrote it from memory after watching the relevant screencast by Gary Bernhardt. It supports:
- Quitting
- Moving the cursor up/down/right/left
- Deleting the character before the cursor, like backspace
- Breaking a line (
Enter
) - Undoing!
The following are also implemented (not covered in the screencast):
- Flicker-free screen
- Ignoring non-printable characters
- Creating a file if it doesn't exist (not just editing)
- Saving
- Redoing!
- Moving left at the beginning of a line causes the cursor to jump to the end of the previous line
- Moving right at the end of a line causes the cursor to jump to the beginning of the next line
- Moving the cursor to the beginning of the line
- Moving the cursor to the end of the line
- Deleting the character before the cursor at the beginning of a line joins lines
- Deleting the character at the cursor, like delete
- Deleting the character at the cursor when at the end of a line joins lines
- Deleting the line text before the cursor
- Deleting the line text after (and including) the cursor
- Support for arrow,
Backspace
,Delete
,Home
andEnd
keys
./femto.rb myfile.txt
Ctrl-Q
quitsCtrl-S
savesCtrl-P
(previous), or theUp
arrow key, moves the cursor upCtrl-N
(next), or theDown
arrow key, moves the cursor downCtrl-F
(forward), or theRight
arrow key, moves the cursor rightCtrl-B
(backward), or theLeft
arrow key, moves the cursor leftCtrl-A
orHome
moves the cursor to the beginning of the lineCtrl-E
orEnd
moves the cursor to the end of the lineCtrl-H
orBackspace
deletes the previous characterCtrl-D
orDelete
deletes the current characterCtrl-U
deletes the line text before the cursorCtrl-K
deletes the line text after (and including) the cursorCtrl--
undoes the last changeCtrl-R
redoes the last change
- Tests
- Scroll-buffer
This is an experimental program. Do NOT use it to edit files that you don't want to lose/damage.
Angelos Orfanakos, https://agorf.gr/