edit

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

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 16 Imported by: 2

README

edit

A text editor library PoC based on tcell, supporting Lua scripting

cmd/edit has an example of an editor built with it.

Documentation

Index

Constants

View Source
const (
	ColorBlack   = tcell.ColorBlack
	ColorMaroon  = tcell.ColorMaroon
	ColorGreen   = tcell.ColorGreen
	ColorOlive   = tcell.ColorOlive
	ColorNavy    = tcell.ColorNavy
	ColorPurple  = tcell.ColorPurple
	ColorTeal    = tcell.ColorTeal
	ColorSilver  = tcell.ColorSilver
	ColorGray    = tcell.ColorGray
	ColorRed     = tcell.ColorRed
	ColorLime    = tcell.ColorLime
	ColorYellow  = tcell.ColorYellow
	ColorBlue    = tcell.ColorBlue
	ColorFuchsia = tcell.ColorFuchsia
	ColorAqua    = tcell.ColorAqua
	ColorWhite   = tcell.ColorWhite
)

Variables

View Source
var DefaultStyle = tcell.StyleDefault

Functions

func CmdCarriageReturn

func CmdCarriageReturn(w *Window)

func CmdCursorDown

func CmdCursorDown(w *Window)

func CmdCursorLeft

func CmdCursorLeft(w *Window)

func CmdCursorRight

func CmdCursorRight(w *Window)

func CmdCursorUp

func CmdCursorUp(w *Window)

func CmdDeletePrevRune

func CmdDeletePrevRune(w *Window)

func CmdMoveToLineEnd

func CmdMoveToLineEnd(w *Window)

func CmdMoveToLineStart

func CmdMoveToLineStart(w *Window)

func CmdPageDown

func CmdPageDown(w *Window)

func CmdPageUp

func CmdPageUp(w *Window)

func CmdQuit

func CmdQuit(w *Window)

func CmdSaveBuffer

func CmdSaveBuffer(w *Window)

func CmdScrollDown

func CmdScrollDown(w *Window)

func CmdScrollUp

func CmdScrollUp(w *Window)

Types

type Action

type Action func(win *Window)

func CmdInsertRune

func CmdInsertRune(r rune) Action

func CmdMouseButtonUp

func CmdMouseButtonUp(pos Position) Action

func CmdMouseDrag

func CmdMouseDrag(pos Position) Action

func CmdMoveButtonDown

func CmdMoveButtonDown(pos Position) Action

func CmdPasteString

func CmdPasteString(s string) Action

func CmdResize

func CmdResize(w, h int) Action

type ActionMaker

type ActionMaker func([]interface{}) Action

func SimpleActionMaker

func SimpleActionMaker(f Action) ActionMaker

type App

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

func NewApp

func NewApp(win *Window) *App

func (*App) BindEvents

func (a *App) BindEvents(name, seq string, f runtime.Value) error

func (*App) CommandInput

func (a *App) CommandInput()

func (*App) CopyToClipboard

func (a *App) CopyToClipboard(s string) error

func (*App) Draw

func (a *App) Draw(screen *Screen)

func (*App) GetEventHandler

func (a *App) GetEventHandler(name string) *EventHandler

func (*App) HandleEvent

func (a *App) HandleEvent(evt Event)

func (*App) InitLuaCode

func (a *App) InitLuaCode(initfile string, luaCode []byte) error

func (*App) InitLuaFile

func (a *App) InitLuaFile(initfile string) error

func (*App) Log

func (a *App) Log(msg string)

func (*App) Logf

func (a *App) Logf(format string, args ...interface{})

func (*App) LuaActionMaker

func (a *App) LuaActionMaker(f runtime.Value) ActionMaker

func (*App) Quit

func (a *App) Quit()

func (*App) Resize

func (a *App) Resize(w, h int)

func (*App) Running

func (a *App) Running() bool

func (*App) SwitchWindow

func (a *App) SwitchWindow()

func (*App) UnbindEvents

func (a *App) UnbindEvents(name, seq string) error

func (*App) Write

func (a *App) Write(p []byte) (int, error)

type ArgType

type ArgType interface {
	FromString() interface{}
}

type Buffer

type Buffer interface {
	LineCount() int
	GetLine(l, c int) (Line, error)
	InsertRune(r rune, l, c int) error
	InsertString(s string, l, c int) (int, int, error)
	InsertLine(l int, line Line) error
	DeleteLine(l int) error
	MergeLineWithPrevious(l int) error
	SplitLine(l, c int) error
	DeleteRuneAt(l, c int) error
	AdvancePos(l, c, dl, dc int) (int, int)
	EndPos() (int, int)
	AppendLine(Line)
	Save() error
	StyledLineIter(l, c int) StyledLineIter
	Kind() string
	StringFromRegion(l0, c0, l1, c1 int) (string, error)
}

type Command

type Command struct {
	Name        string
	Description string
	Parameters  []Parameter
	Action      CommandAction
}

type CommandAction

type CommandAction interface {
	Apply(w *App)
}

type Event

type Event struct {
	EventType
	KeyData
	Rune rune
	Modifiers
	MouseData
	Size
	PasteString string
}

func (Event) Name

func (e Event) Name() string

type EventHandler

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

func NewEventHandler

func NewEventHandler() *EventHandler

func (*EventHandler) HandleEvent

func (h *EventHandler) HandleEvent(evt Event) (Action, error)

HandleEvent transitions the state of the event handler and returns any action that may be triggered.

func (*EventHandler) RegisterAction

func (h *EventHandler) RegisterAction(seq string, action ActionMaker) error

RegisterAction associates the given action with the event sequence represented by seq. E.g. RegisterAction("x y z", action) will create the following transitions:

"" -x-> x x -y-> x:y x:y -z-> x:y:z

It will also record that the state x:y:z triggers action x:y:z triggers action

func (*EventHandler) Reset

func (h *EventHandler) Reset()

Reset the handler so any ongoing sequence is aborted.

func (*EventHandler) UnregisterAction

func (h *EventHandler) UnregisterAction(seq string) error

type EventType

type EventType int
const (
	NoEvent EventType = iota
	Rune
	Key
	Mouse
	Resize
	Paste
)

func (EventType) Name

func (t EventType) Name() string

type FileBuffer

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

A FileBuffer maintains the data for a file.

func NewBufferFromFile

func NewBufferFromFile(filename string) *FileBuffer

func NewEmptyFileBuffer

func NewEmptyFileBuffer() *FileBuffer

func (*FileBuffer) AdvancePos

func (b *FileBuffer) AdvancePos(l, c, dl, dc int) (int, int)

func (*FileBuffer) AppendLine

func (b *FileBuffer) AppendLine(line Line)

func (*FileBuffer) DeleteLine

func (b *FileBuffer) DeleteLine(l int) error

func (*FileBuffer) DeleteRuneAt

func (b *FileBuffer) DeleteRuneAt(l, c int) error

func (*FileBuffer) EndPos

func (b *FileBuffer) EndPos() (int, int)

func (*FileBuffer) GetLine

func (b *FileBuffer) GetLine(l, c int) (Line, error)

func (*FileBuffer) InsertLine

func (b *FileBuffer) InsertLine(l int, line Line) error

func (*FileBuffer) InsertRune

func (b *FileBuffer) InsertRune(r rune, l, c int) error

func (*FileBuffer) InsertString

func (b *FileBuffer) InsertString(s string, l, c int) (int, int, error)

func (*FileBuffer) Kind

func (b *FileBuffer) Kind() string

func (*FileBuffer) Line

func (b *FileBuffer) Line(l int) Line

func (*FileBuffer) LineCount

func (b *FileBuffer) LineCount() int

func (*FileBuffer) MergeLineWithPrevious

func (b *FileBuffer) MergeLineWithPrevious(l int) error

func (*FileBuffer) NearestPos

func (b *FileBuffer) NearestPos(l, c int) (int, int)

func (*FileBuffer) Save

func (b *FileBuffer) Save() error

func (*FileBuffer) SetLine

func (b *FileBuffer) SetLine(l int, line Line) error

func (*FileBuffer) SplitLine

func (b *FileBuffer) SplitLine(l, c int) error

func (*FileBuffer) StringFromRegion

func (b *FileBuffer) StringFromRegion(l0, c0, l1, c1 int) (string, error)

func (*FileBuffer) StyledLineIter

func (b *FileBuffer) StyledLineIter(l, c int) StyledLineIter

func (*FileBuffer) Truncate

func (b *FileBuffer) Truncate(count int)

type ILine

type ILine interface {
	Len() int
	InsertRune(r rune, c int) ILine
	DeleteAt(c int) Line
	MergeWith(l2 ILine) ILine
	String() string
	Iter(c int) LineIter
}

type Invocation

type Invocation struct {
	*Command
	Arguments []interface{}
}

type KeyData

type KeyData tcell.Key

type Line

type Line struct {
	Runes []rune
	Meta  interface{}
}

func NewLineFromString

func NewLineFromString(s string, meta interface{}) Line

func (Line) DeleteAt

func (l Line) DeleteAt(c int) Line

func (Line) InsertRune

func (l Line) InsertRune(r rune, c int) Line

func (Line) InsertString

func (l Line) InsertString(s string, c int) Line

s must not contain a '\n'

func (Line) Iter

func (l Line) Iter(c int) LineIter

func (Line) Len

func (l Line) Len() int

func (Line) MergeWith

func (l Line) MergeWith(l2 Line) Line

func (Line) SplitAt

func (l Line) SplitAt(c int) (Line, Line)

func (Line) String

func (l Line) String() string

type LineIter

type LineIter interface {
	Next() rune
	HasNext() bool
}

type Modifiers

type Modifiers int
const (
	Shift Modifiers = 1 << iota
	Control
	Alt
	Meta
)

type MouseButtons

type MouseButtons int
const (
	Button1 MouseButtons = 1 << iota
	Button2
	Button3
	WheelDown
	WheelUp
	WheelLeft
	WheelRight
)

func (MouseButtons) Empty

func (mb MouseButtons) Empty() bool

func (MouseButtons) Has

func (mb MouseButtons) Has(mb1 MouseButtons) bool

func (MouseButtons) Name

func (mb MouseButtons) Name() string

type MouseData

type MouseData struct {
	Position
	Buttons         MouseButtons
	ButtonsPressed  MouseButtons
	ButtonsReleased MouseButtons
}

type Parameter

type Parameter struct {
	Name        string
	Description string
	Type        ArgType
}

type Position

type Position struct {
	X, Y int
}

func (Position) MoveBy

func (p Position) MoveBy(q Position) Position

func (Position) MoveByX

func (p Position) MoveByX(x int) Position

type Printer

type Printer struct {
	Offset   int
	TabWidth int
}

A Printer knows how to print lines on a screen

func (Printer) LineCol

func (p Printer) LineCol(l Line, i int) int

func (Printer) LineIndex

func (p Printer) LineIndex(l Line, targetCol int) int

func (Printer) Print

func (lp Printer) Print(s ScreenWriter, p Position, iter StyledLineIter)

Print the line to the screen starting at coordinates (p.X, p.Y)

type Rectangle

type Rectangle struct {
	Position
	Size
}

func (Rectangle) BottomRight

func (r Rectangle) BottomRight() Position

func (Rectangle) Intersect

func (r Rectangle) Intersect(s Rectangle) Rectangle

type Screen

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

func NewScreen

func NewScreen() (*Screen, error)

func (*Screen) Cleanup

func (s *Screen) Cleanup()

func (*Screen) Fill

func (s *Screen) Fill(c rune)

func (*Screen) PollEvent

func (s *Screen) PollEvent() Event

func (*Screen) Reverse

func (s *Screen) Reverse(p Position)

func (*Screen) SetRune

func (s *Screen) SetRune(p Position, c rune, style tcell.Style)

func (*Screen) Show

func (s *Screen) Show()

func (*Screen) Size

func (s *Screen) Size() Size

func (*Screen) SubScreen

func (s *Screen) SubScreen(rect Rectangle) ScreenWriter

type ScreenWriter

type ScreenWriter interface {
	Size() Size
	SetRune(Position, rune, tcell.Style)
	Reverse(Position)
	SubScreen(Rectangle) ScreenWriter
}

type Size

type Size struct {
	W, H int
}

func (Size) Contains

func (s Size) Contains(p Position) bool

type Style

type Style = tcell.Style

type StyledLineIter

type StyledLineIter interface {
	Next() (rune, Style)
	HasNext() bool
}

func NewConstStyleLineIter

func NewConstStyleLineIter(iter LineIter, style Style) StyledLineIter

type SubScreen

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

func (SubScreen) Reverse

func (s SubScreen) Reverse(p Position)

func (SubScreen) SetRune

func (s SubScreen) SetRune(p Position, c rune, style tcell.Style)

func (SubScreen) Size

func (s SubScreen) Size() Size

func (SubScreen) SubScreen

func (s SubScreen) SubScreen(rect Rectangle) ScreenWriter

type TcellEventConverter

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

func (*TcellEventConverter) EventFromTcell

func (c *TcellEventConverter) EventFromTcell(tcevt tcell.Event) Event

type Window

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

A Window is a view to a buffer. It maintains a cursor position, and a rectangle view into the buffer.

func NewWindow

func NewWindow(buf Buffer) *Window

func (*Window) App

func (w *Window) App() *App

func (*Window) Buffer

func (w *Window) Buffer() Buffer

func (*Window) CurrentLine

func (w *Window) CurrentLine() (Line, error)

CurrentLine returns the line the cursor is on currently.

func (*Window) CursorLine

func (w *Window) CursorLine() int

func (*Window) CursorPos

func (w *Window) CursorPos() (int, int)

func (*Window) DeleteRune

func (w *Window) DeleteRune() (err error)

DeleteRune deletes the character to the left of the cursor position.

func (*Window) Draw

func (w *Window) Draw(screen ScreenWriter)

Draw draws the contents of the window on the screen.

func (*Window) DrawCursor

func (w *Window) DrawCursor(screen ScreenWriter)

DrawCursor highlights the cursor if it is visible.

func (*Window) FocusCursor

func (w *Window) FocusCursor(screen ScreenWriter)

FocusCursor adjusts the visible rectangle of the window if necessary to make the cursor visible.

func (*Window) GetHighlightedString

func (w *Window) GetHighlightedString() (string, error)

func (*Window) GetLineCol

func (w *Window) GetLineCol(x, y int) (int, int)

func (*Window) HandleEvent

func (w *Window) HandleEvent(evt Event) (Action, error)

func (*Window) InsertRune

func (w *Window) InsertRune(r rune)

InsertRune inserts a character into the buffer at the cursor position.

func (*Window) MoveCursor

func (w *Window) MoveCursor(dl, dc int)

MoveCursor moves the cursor by a number of lines and columns.

func (*Window) MoveCursorTo

func (w *Window) MoveCursorTo(x, y int)

MoveCursorTo moves the cursor to a given screen position.

func (*Window) MoveCursorToEnd

func (w *Window) MoveCursorToEnd()

func (*Window) MoveCursorToLineEnd

func (w *Window) MoveCursorToLineEnd()

MoveCursorToLineEnd moves the cursor to the end of the current line.

func (*Window) MoveCursorToLineStart

func (w *Window) MoveCursorToLineStart()

MoveCursorToLineStart moves the cursor to the start of the current line.

func (*Window) MoveHighlightRegion

func (w *Window) MoveHighlightRegion(x, y int)

func (*Window) PageDown

func (w *Window) PageDown(n int)

PageDown moves the cursor down by n pages (or up by -n pages if n < 0).

func (*Window) PasteString

func (w *Window) PasteString(s string) (err error)

func (*Window) RegisterWithApp

func (w *Window) RegisterWithApp(app *App)

func (*Window) ResetHighlightRegion

func (w *Window) ResetHighlightRegion()

func (*Window) Resize

func (w *Window) Resize(width, height int)

Resize changes the size of the window.

func (*Window) ScrollDown

func (w *Window) ScrollDown(n int)

ScrollDown scrolls down by n lines, attempting to keep the cursor on the same buffer line.

func (*Window) ScrollUp

func (w *Window) ScrollUp(n int)

ScrollUp scrolls up by n lines, attempting to keep the cursor on the same buffer line.

func (*Window) SplitLine

func (w *Window) SplitLine(move bool) error

SplitLine splits the current line at the cursor position. If move is true, the cursor is moved down otherwise it stays in the same position.

func (*Window) StartHighlightRegion

func (w *Window) StartHighlightRegion(x, y int)

func (*Window) StopHightlightRegion

func (w *Window) StopHightlightRegion(x, y int) bool

func (*Window) StyledLineIter

func (w *Window) StyledLineIter(l, c int) StyledLineIter

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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