orzo

package module
v0.0.0-...-c1b70a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0

README

orzo

orzo is a small terminal/screen text Editor in less than 2K lines of Go code. It uses Go's rune (unicode) machinery. Has multiple Buffers. But still single window. hope this makes it into the vault

Usage: orzo <filename>

To build: clone repo into gopath;

 $ cd cmd
 $ go get -d ./...
 $ go build -o orzo

Copy to someplace in your PATH

be sure you have https://godoc.org/github.com/nsf/termbox-go so, you may need to go get github.com/nsf/termbox-go

Key Commands:
Movement
  • CTRL-Y: HELP
  • Use ArrowKeys to move Cursor around.
  • Home, End, and PageUp & PageDown should work
  • CTRL-A: Move to beginning of current line
  • CTRL-E: Move to end of current line
  • on mac keyboards:
    • FN+ArrowUp: PageUp (screen full)
    • FN+ArrowDown: PageDown (screen full)
File/Buffer
  • CTRL-S: Save the file
  • CTRL-Q: Quit the Editor
  • CTRL-F: Find string in file (ESC to exit search mode, arrows to navigate to next/prev find)
  • CTRL-N: Next Buffer
  • CTRL-B: List all the Buffers
  • CTRL-O: (control oh) Open File into new Buffer
  • CTRL-W: kill Buffer
Cut/Copy/Paste & Deletion
  • CTRL-Space: Set Mark
  • CTRL-X: Cut region from Mark to Cursor into paste Buffer
  • CTRL-C: Copy region from Mark to Cursor into paste Buffer
  • CTRL-V: Paste copied/cut region into file at Cursor Once you've set the Mark, as you move the cursor, you should be getting underlined text showing the current selection/region.
  • Delete: to delete a rune backward
  • CTRL-K: killtoEndOfLine (once) removeLine (twice)

Setting the cursor with a mouse click should work. (and so, it should work to set the selection. but hey, you MUST SetMark for a selection to start... sorry, it's not a real mouse based Editor.)

Implementation Notes

orzo was based on Kilo, a project by Salvatore Sanfilippo at https://github.com/antirez/kilo.

It's a very simple Editor, with kinda-"Mac-Emacs"-like key bindings. It uses `go get github.com/nsf/termbox-go" for simple termio junk.

The central data structure is an array of lines (type erow struct). Each line in the file has a struct, which contains an array of rune. (If you're not familiar with Go's runes, they are Go's unicode code points (or characters))

Multiple Buffers, but no window splits. Two mini modes, one for the search modal operations, and one for opening files.

Notice the goroutine attached to events coming from termbox-go, that is pretty cool. Yet another real reason that Go routines are handy.

orzo was written in Go by K Younger and is released under the BSD 2 clause license.

Orzo interface with WindowServer

  • a Pty interface, where vt100/ansi terminal codes rule

  • a Web interface where browser/JS events flow, but only on input.

  • a light go based window server

Documentation

Index

Constants

View Source
const (
	KeyNull   = 0   /* NULL ctrl-space set mark */
	CtrlA     = 1   /* Ctrl-a BOL */
	CtrlB     = 2   /* Ctrl-b list Buffers */
	CtrlC     = 3   /* Ctrl-c  copy */
	CtrlE     = 5   /* Ctrl-e  EOL */
	CtrlD     = 4   /* Ctrl-d del forward? */
	CtrlF     = 6   /* Ctrl-f find */
	CtrlH     = 8   /* Ctrl-h del backward*/
	Tab       = 9   /* Tab */
	CtrlK     = 11  /* Ctrl+k killToEOL */
	CtrlL     = 12  /* Ctrl+l redraw */
	Enter     = 13  /* Enter */
	CtrlN     = 14  /* Ctrl-n nextBuffer */
	CtrlO     = 15  /* Ctrl-o load(open) file */
	CtrlQ     = 17  /* Ctrl-q quit*/
	CtrlS     = 19  /* Ctrl-s save*/
	CtrlU     = 21  /* Ctrl-u number of times??*/
	CtrlV     = 22  /* Ctrl-v paste */
	CtrlW     = 23  /* Ctrl-w kill Buffer */
	CtrlX     = 24  /* Ctrl-x cut */
	CtrlY     = 25  /* Help */
	CtrlZ     = 26  /* ?? */
	Esc       = 27  /* Escape */
	Space     = 32  /* Space */
	Backspace = 127 /* Backspace */
)

KEY constants

View Source
const (
	ArrowLeft  = termbox.KeyArrowLeft
	ArrowRight = termbox.KeyArrowRight
	ArrowUp    = termbox.KeyArrowUp
	ArrowDown  = termbox.KeyArrowDown
	DelKey     = termbox.KeyDelete
	HomeKey    = termbox.KeyHome
	EndKey     = termbox.KeyEnd
	PageUp     = termbox.KeyPgup
	PageDown   = termbox.KeyPgdn
)

Cursor movement keys

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

type Editor

type Editor struct {
	Buffers []*Buffer
	// contains filtered or unexported fields
}

func (*Editor) EditorDelChar

func (e *Editor) EditorDelChar()

Delete the char at the currentLine cursor position.

func (*Editor) EditorDelRow

func (e *Editor) EditorDelRow(at int)

func (*Editor) EditorFind

func (e *Editor) EditorFind()

func (*Editor) EditorInsertChar

func (e *Editor) EditorInsertChar(rch rune)

Insert the specified char at the currentLine prompt position.

func (*Editor) EditorInsertNewline

func (e *Editor) EditorInsertNewline()

Inserting a newline is slightly complex as we have to handle inserting a * newline in the middle of a line, splitting the line as needed.

func (*Editor) EditorInsertRow

func (e *Editor) EditorInsertRow(at int, s string)

Insert a row at the specified position, shifting the other rows on the bottom * if required.

func (*Editor) EditorMoveCursor

func (e *Editor) EditorMoveCursor(rch termbox.Key)

Handle cursor position change because arrow keys were pressed.

func (*Editor) EditorOpen

func (e *Editor) EditorOpen(filename string) error

=================== FILE OPS ============================== Load the specified text file into the current Buffer return any error

func (*Editor) EditorProcessEvent

func (e *Editor) EditorProcessEvent(ev termbox.Event)

Process events arriving from the standard input, which is, the user * is typing stuff on the terminal.

func (*Editor) EditorRefreshScreen

func (e *Editor) EditorRefreshScreen(drawCursor bool)

This function writes the whole screen using termbox-go

func (*Editor) EditorRowAppendString

func (e *Editor) EditorRowAppendString(row *erow, s string)

Append the string 's' at the end of a row

func (*Editor) EditorRowDelChar

func (e *Editor) EditorRowDelChar(row *erow, at int)

Delete the character at offset 'at' from the specified row.

func (*Editor) EditorRowInsertChar

func (e *Editor) EditorRowInsertChar(row *erow, at int, rch rune)

Insert a character at the specified position in a row, moving the remaining * runes on the right if needed.

func (*Editor) EditorRowsToString

func (e *Editor) EditorRowsToString() string

func (*Editor) EditorSave

func (e *Editor) EditorSave() error

Save the currentLine file on disk. Return 0 on success, 1 on error.

func (*Editor) EditorSetStatusMessage

func (e *Editor) EditorSetStatusMessage(fm string, args ...interface{})

Set an Editor status message for the second line of the status, at the * end of the screen.

func (*Editor) EditorUpdateRow

func (e *Editor) EditorUpdateRow(row *erow)

Update the rendered version and the syntax highlight of a row.

type Orzo

type Orzo struct {
	Orzo *Editor
}

orzo is the top-level exported type

func (*Orzo) Start

func (z *Orzo) Start(filename string)

Start runs an Editor

type State

type State struct {
	// contains filtered or unexported fields
}

State contains the state of a terminal.

type Terminal

type Terminal interface {
}

type TextContainer

type TextContainer interface {
	SetPoint(pt int)
	SetMark(pt int)
	Insert(s string, pt int) error
	AddRune(r rune)
	IndexOf(idx int) byte
	DeleteRune(idx int)
	Size() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL