~vdupras/duskos

2cae7099c132e76bedbec799a65fc76fdda0ced0 — Virgil Dupras 4 months ago cfd8950
text/ged: first baby steps

Gotta take baby steps. May I remind you I'm writing this with text/ed?
3 files changed, 40 insertions(+), 1 deletions(-)

M fs/doc/text/ed.txt
A fs/doc/text/ged.txt
A fs/text/ged.fs
M fs/doc/text/ed.txt => fs/doc/text/ed.txt +1 -1
@@ 3,7 3,7 @@
Prerequisites: sys/io, sys/file, lib/alloc, lib/context

This line based text editor lives at text/ed.fs and allows the examination and
modification of text contents.
modification of text contents. The Grid-based editor is text/ged.

The central structure of this unit is Edbuf (editor buffer) and its API is
described below. You will typically only want one copy of this structure and

A fs/doc/text/ged.txt => fs/doc/text/ged.txt +23 -0
@@ 0,0 1,23 @@
# Grid Text Editor

Prerequisites: text/ed, sys/grid

TODO: work in progress. Extremely rudimentary at the moment

The Grid text editor sits on text/ed and adds a visual and interactive interface
through the Grid.

The basic idea is that text around current Edbuf selection is always displayed
using the whole grid except for the bottom line (the status line). There are
quick one letter keybindings for frequent and simple movements and
manipulations, but for fancier operations, you go in command mode with ":",
which simply prompts for a line to interpret (in which you'll probably use
commands from text/ed, but you can also use others).

To use it, you load your EdBuf with some contents and then run "ged", which
enters the grid keybindings loop.

## Keybindings

q Quit
All others: select next line down and refresh page.

A fs/text/ged.fs => fs/text/ged.fs +16 -0
@@ 0,0 1,16 @@
require /sys/grid.fs
?f<< /text/ed.fs

: nspcs ( n -- ) >r begin SPC grid :putc next ;
: _spitline ( pos line -- )
  swap grid :spiton
  dup Line cnt grid COLS min ( line n )
  dup if swap Line ptr over grid :write else nip then ( n )
  grid COLS -^ ?dup if nspcs then grid :spitoff ;

: _spitpage ( -- )
  grid LINES 1- >r 0 edbuf sel begin ( lineno line )
    dup if over grid COLS * over _spitline else over grid :clrline then
    dup if llnext then swap 1+ swap next 2drop ;

: ged begin _spitpage 1 edbuf :godown key 'q' = until ;
\ No newline at end of file