femto

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

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 19 Imported by: 0

README

femto, an editor component for tview

femto is a text editor component for tview. The vast majority of the code is derived from the micro editor.

Note The shape of the femto API is a work-in-progress, and should not be considered stable.

Default keybindings

Up:             CursorUp
Down:           CursorDown
Right:          CursorRight
Left:           CursorLeft
ShiftUp:        SelectUp
ShiftDown:      SelectDown
ShiftLeft:      SelectLeft
ShiftRight:     SelectRight
AltLeft:        WordLeft
AltRight:       WordRight
AltUp:          MoveLinesUp
AltDown:        MoveLinesDown
AltShiftRight:  SelectWordRight
AltShiftLeft:   SelectWordLeft
CtrlLeft:       StartOfLine
CtrlRight:      EndOfLine
CtrlShiftLeft:  SelectToStartOfLine
ShiftHome:      SelectToStartOfLine
CtrlShiftRight: SelectToEndOfLine
ShiftEnd:       SelectToEndOfLine
CtrlUp:         CursorStart
CtrlDown:       CursorEnd
CtrlShiftUp:    SelectToStart
CtrlShiftDown:  SelectToEnd
Alt-{:          ParagraphPrevious
Alt-}:          ParagraphNext
Enter:          InsertNewline
CtrlH:          Backspace
Backspace:      Backspace
Alt-CtrlH:      DeleteWordLeft
Alt-Backspace:  DeleteWordLeft
Tab:            IndentSelection,InsertTab
Backtab:        OutdentSelection,OutdentLine
CtrlZ:          Undo
CtrlY:          Redo
CtrlC:          Copy
CtrlX:          Cut
CtrlK:          CutLine
CtrlD:          DuplicateLine
CtrlV:          Paste
CtrlA:          SelectAll
Home:           StartOfLine
End:            EndOfLine
CtrlHome:       CursorStart
CtrlEnd:        CursorEnd
PageUp:         CursorPageUp
PageDown:       CursorPageDown
CtrlR:          ToggleRuler
Delete:         Delete
Insert:         ToggleOverwriteMode
Alt-f:          WordRight
Alt-b:          WordLeft
Alt-a:          StartOfLine
Alt-e:          EndOfLine
Esc:            Escape
Alt-n:          SpawnMultiCursor
Alt-m:          SpawnMultiCursorSelect
Alt-p:          RemoveMultiCursor
Alt-c:          RemoveAllMultiCursors
Alt-x:          SkipMultiCursor

Example Usage

The code below (also found in cmd/femto/femto.go) creates a tview application with a single full-screen editor that operates on one file at a time. Ctrl-s saves any edits; Ctrl-q quits.

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"

	"github.com/gdamore/tcell"
	"github.com/vjega/femto"
	"github.com/vjega/femto/runtime"
	"github.com/rivo/tview"
)

func saveBuffer(b *femto.Buffer, path string) error {
	return ioutil.WriteFile(path, []byte(b.String()), 0600)
}

func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "usage: femto [filename]\n")
		os.Exit(1)
	}
	path := os.Args[1]

	content, err := ioutil.ReadFile(path)
	if err != nil {
		log.Fatalf("could not read %v: %v", path, err)
	}

	var colorscheme femto.Colorscheme
	if monokai := runtime.Files.FindFile(femto.RTColorscheme, "monokai"); monokai != nil {
		if data, err := monokai.Data(); err == nil {
			colorscheme = femto.ParseColorscheme(string(data))
		}
	}

	app := tview.NewApplication()
	buffer := femto.NewBufferFromString(string(content), path)
	root := femto.NewView(buffer)
	root.SetRuntimeFiles(runtime.Files)
	root.SetColorscheme(colorscheme)
	root.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		switch event.Key() {
		case tcell.KeyCtrlS:
			saveBuffer(buffer, path)
			return nil
		case tcell.KeyCtrlQ:
			app.Stop()
			return nil
		}
		return event
	})
	app.SetRoot(root, true)

	if err := app.Run(); err != nil {
		log.Fatalf("%v", err)
	}
}

Documentation

Index

Constants

View Source
const (
	ActionCursorUp               = "CursorUp"
	ActionCursorDown             = "CursorDown"
	ActionCursorPageUp           = "CursorPageUp"
	ActionCursorPageDown         = "CursorPageDown"
	ActionCursorLeft             = "CursorLeft"
	ActionCursorRight            = "CursorRight"
	ActionCursorStart            = "CursorStart"
	ActionCursorEnd              = "CursorEnd"
	ActionSelectToStart          = "SelectToStart"
	ActionSelectToEnd            = "SelectToEnd"
	ActionSelectUp               = "SelectUp"
	ActionSelectDown             = "SelectDown"
	ActionSelectLeft             = "SelectLeft"
	ActionSelectRight            = "SelectRight"
	ActionWordRight              = "WordRight"
	ActionWordLeft               = "WordLeft"
	ActionSelectWordRight        = "SelectWordRight"
	ActionSelectWordLeft         = "SelectWordLeft"
	ActionDeleteWordRight        = "DeleteWordRight"
	ActionDeleteWordLeft         = "DeleteWordLeft"
	ActionSelectLine             = "SelectLine"
	ActionSelectToStartOfLine    = "SelectToStartOfLine"
	ActionSelectToEndOfLine      = "SelectToEndOfLine"
	ActionParagraphPrevious      = "ParagraphPrevious"
	ActionParagraphNext          = "ParagraphNext"
	ActionInsertNewline          = "InsertNewline"
	ActionInsertSpace            = "InsertSpace"
	ActionBackspace              = "Backspace"
	ActionDelete                 = "Delete"
	ActionInsertTab              = "InsertTab"
	ActionCenter                 = "Center"
	ActionUndo                   = "Undo"
	ActionRedo                   = "Redo"
	ActionCopy                   = "Copy"
	ActionCut                    = "Cut"
	ActionCutLine                = "CutLine"
	ActionDuplicateLine          = "DuplicateLine"
	ActionDeleteLine             = "DeleteLine"
	ActionMoveLinesUp            = "MoveLinesUp"
	ActionMoveLinesDown          = "MoveLinesDown"
	ActionIndentSelection        = "IndentSelection"
	ActionOutdentSelection       = "OutdentSelection"
	ActionOutdentLine            = "OutdentLine"
	ActionPaste                  = "Paste"
	ActionSelectAll              = "SelectAll"
	ActionStart                  = "Start"
	ActionEnd                    = "End"
	ActionPageUp                 = "PageUp"
	ActionPageDown               = "PageDown"
	ActionSelectPageUp           = "SelectPageUp"
	ActionSelectPageDown         = "SelectPageDown"
	ActionHalfPageUp             = "HalfPageUp"
	ActionHalfPageDown           = "HalfPageDown"
	ActionStartOfLine            = "StartOfLine"
	ActionEndOfLine              = "EndOfLine"
	ActionToggleRuler            = "ToggleRuler"
	ActionToggleOverwriteMode    = "ToggleOverwriteMode"
	ActionEscape                 = "Escape"
	ActionScrollUp               = "ScrollUp"
	ActionScrollDown             = "ScrollDown"
	ActionSpawnMultiCursor       = "SpawnMultiCursor"
	ActionSpawnMultiCursorSelect = "SpawnMultiCursorSelect"
	ActionRemoveMultiCursor      = "RemoveMultiCursor"
	ActionRemoveAllMultiCursors  = "RemoveAllMultiCursors"
	ActionSkipMultiCursor        = "SkipMultiCursor"
	ActionJumpToMatchingBrace    = "JumpToMatchingBrace"
	ActionInsertEnter            = "InsertEnter"
	ActionUnbindKey              = "UnbindKey"
)

Actions

View Source
const (

	// TextEventInsert represents an insertion event
	TextEventInsert = 1
	// TextEventRemove represents a deletion event
	TextEventRemove = -1
	// TextEventReplace represents a replace event
	TextEventReplace = 0
)
View Source
const LargeFileThreshold = 50000

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

Abs is a simple absolute value function for ints

func ByteOffset

func ByteOffset(pos Loc, buf *Buffer) int

ByteOffset is just like ToCharPos except it counts bytes instead of runes

func CommonSubstring

func CommonSubstring(arr ...string) string

CommonSubstring gets a common substring among the inputs

func Contains

func Contains(list []string, a string) bool

Contains returns whether or not a string array contains a given string

func Count

func Count(s string) int

Count returns the length of a string in runes This is exactly equivalent to utf8.RuneCountInString(), just less characters

func DefaultLocalSettings

func DefaultLocalSettings() map[string]interface{}

DefaultLocalSettings returns the default local settings Note that filetype is a local only option

func Diff

func Diff(a, b Loc, buf *Buffer) int

Diff returns the distance between two locations

func EscapePath

func EscapePath(path string) string

EscapePath replaces every path separator in a given path with a %

func ExecuteTextEvent

func ExecuteTextEvent(t *TextEvent, buf *Buffer)

ExecuteTextEvent runs a text event

func FSize

func FSize(f *os.File) int64

FSize gets the size of a file

func FuncName

func FuncName(i interface{}) string

FuncName returns the full name of a given function object

func GetColor

func GetColor(color string) tcell.Style

GetColor takes in a syntax group and returns the colorscheme's style for that group

func GetColor256

func GetColor256(color int) tcell.Color

GetColor256 returns the tcell color for a number between 0 and 255

func GetLeadingWhitespace

func GetLeadingWhitespace(str string) string

GetLeadingWhitespace returns the leading whitespace of the given string

func GetModTime

func GetModTime(path string) (time.Time, bool)

GetModTime returns the last modification time for a given file It also returns a boolean if there was a problem accessing the file

func GetPathAndCursorPosition

func GetPathAndCursorPosition(path string) (string, []string)

GetPathAndCursorPosition returns a filename without everything following a `:` This is used for opening files like util.go:10:5 to specify a line and column Special cases like Windows Absolute path (C:\myfile.txt:10:5) are handled correctly.

func InBounds

func InBounds(pos Loc, buf *Buffer) bool

InBounds returns whether the given location is a valid character position in the given buffer

func Insert

func Insert(str string, pos int, value string) string

Insert makes a simple insert into a string at the given position

func IsSpaces

func IsSpaces(str []byte) bool

IsSpaces checks if a given string is only spaces

func IsSpacesOrTabs

func IsSpacesOrTabs(str string) bool

IsSpacesOrTabs checks if a given string contains only spaces and tabs

func IsStrWhitespace

func IsStrWhitespace(str string) bool

IsStrWhitespace returns true if the given string is all whitespace

func IsWhitespace

func IsWhitespace(c rune) bool

IsWhitespace returns true if the given rune is a space, tab, or newline

func IsWordChar

func IsWordChar(str string) bool

IsWordChar returns whether or not the string is a 'word character' If it is a unicode character, then it does not match Word characters are defined as [A-Za-z0-9_]

func MakeRelative

func MakeRelative(path, base string) (string, error)

MakeRelative will attempt to make a relative path between path and base

func Max

func Max(a, b int) int

Max takes the max of two ints

func Min

func Min(a, b int) int

Min takes the min of two ints

func NumOccurrences

func NumOccurrences(s string, c byte) int

NumOccurrences counts the number of occurrences of a byte in a string

func ParseBool

func ParseBool(str string) (bool, error)

ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off' as 'true' and 'false' respectively

func SetDefaultColorscheme

func SetDefaultColorscheme(scheme Colorscheme)

SetDefaultColorscheme sets the current default colorscheme for new Views.

func ShortFuncName

func ShortFuncName(i interface{}) string

ShortFuncName returns the name only of a given function object

func ShowMultiCursor

func ShowMultiCursor(screen tcell.Screen, x, y, i int)

ShowMultiCursor will display a cursor at a location If i == 0 then the terminal cursor will be used Otherwise a fake cursor will be drawn at the position

func Spaces

func Spaces(n int) string

Spaces returns a string with n spaces

func StringToColor

func StringToColor(str string) tcell.Color

StringToColor returns a tcell color from a string representation of a color We accept either bright... or light... to mean the brighter version of a color

func StringToStyle

func StringToStyle(str string) tcell.Style

StringToStyle returns a style from a string The strings must be in the format "extra foregroundcolor,backgroundcolor" The 'extra' can be bold, reverse, or underline

func StringWidth

func StringWidth(str string, tabsize int) int

StringWidth returns the width of a string where tabs count as `tabsize` width

func ToCharPos

func ToCharPos(start Loc, buf *Buffer) int

ToCharPos converts from an x, y position to a character position

func UndoTextEvent

func UndoTextEvent(t *TextEvent, buf *Buffer)

UndoTextEvent undoes a text event

func WidthOfLargeRunes

func WidthOfLargeRunes(str string, tabsize int) int

WidthOfLargeRunes searches all the runes in a string and counts up all the widths of runes that have a width larger than 1 (this also counts tabs as `tabsize` width)

Types

type Buffer

type Buffer struct {
	// The eventhandler for undo/redo
	*EventHandler
	// This stores all the text in the buffer as an array of lines
	*LineArray

	// The path to the loaded file, if any
	Path string

	Cursor Cursor

	// Whether or not the buffer has been modified since it was opened
	IsModified bool

	// NumLines is the number of lines in the buffer
	NumLines int

	// Buffer local settings
	Settings map[string]interface{}
	// contains filtered or unexported fields
}

Buffer stores the text for files that are loaded into the text editor It uses a rope to efficiently store the string and contains some simple functions for saving and wrapper functions for modifying the rope

func NewBuffer

func NewBuffer(reader io.Reader, size int64, path string, cursorPosition []string) *Buffer

NewBuffer creates a new buffer from a given reader

func NewBufferFromString

func NewBufferFromString(text, path string) *Buffer

NewBufferFromString creates a new buffer containing the given string

func (*Buffer) End

func (b *Buffer) End() Loc

End returns the location of the last character in the buffer

func (*Buffer) FileType

func (b *Buffer) FileType() string

FileType returns the buffer's filetype

func (*Buffer) FindMatchingBrace

func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) Loc

FindMatchingBrace returns the location in the buffer of the matching bracket It is given a brace type containing the open and closing character, (for example '{' and '}') as well as the location to match from

func (*Buffer) GetName

func (b *Buffer) GetName() string

GetName returns the name that should be displayed in the statusline for this buffer

func (*Buffer) IndentString

func (b *Buffer) IndentString() string

IndentString returns a string representing one level of indentation

func (*Buffer) Len

func (b *Buffer) Len() (n int)

Len gives the length of the buffer

func (*Buffer) Line

func (b *Buffer) Line(n int) string

Line returns a single line

func (*Buffer) LineBytes

func (b *Buffer) LineBytes(n int) []byte

LineBytes returns a single line as an array of runes

func (*Buffer) LineRunes

func (b *Buffer) LineRunes(n int) []rune

LineRunes returns a single line as an array of runes

func (*Buffer) Lines

func (b *Buffer) Lines(start, end int) []string

Lines returns an array of strings containing the lines from start to end

func (*Buffer) LinesNum

func (b *Buffer) LinesNum() int

LinesNum returns the number of lines in the buffer

func (*Buffer) MergeCursors

func (b *Buffer) MergeCursors()

MergeCursors merges any cursors that are at the same position into one cursor

func (*Buffer) Modified

func (b *Buffer) Modified() bool

Modified returns if this buffer has been modified since being opened

func (*Buffer) MoveLinesDown

func (b *Buffer) MoveLinesDown(start int, end int)

MoveLinesDown moves the range of lines down one row

func (*Buffer) MoveLinesUp

func (b *Buffer) MoveLinesUp(start int, end int)

MoveLinesUp moves the range of lines up one row

func (*Buffer) RuneAt

func (b *Buffer) RuneAt(loc Loc) rune

RuneAt returns the rune at a given location in the buffer

func (*Buffer) Start

func (b *Buffer) Start() Loc

Start returns the location of the first character in the buffer

func (*Buffer) UpdateCursors

func (b *Buffer) UpdateCursors()

UpdateCursors updates all the cursors indicies

type CellView

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

func (*CellView) Draw

func (c *CellView) Draw(buf *Buffer, colorscheme Colorscheme, top, height, left, width int)

type Char

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

type Colorscheme

type Colorscheme map[string]tcell.Style

Colorscheme is a map from string to style -- it represents a colorscheme

func ParseColorscheme

func ParseColorscheme(text string) Colorscheme

ParseColorscheme parses the text definition for a colorscheme and returns the corresponding object Colorschemes are made up of color-link statements linking a color group to a list of colors For example, color-link keyword (blue,red) makes all keywords have a blue foreground and red background

func (Colorscheme) GetColor

func (colorscheme Colorscheme) GetColor(color string) tcell.Style

GetColor takes in a syntax group and returns the colorscheme's style for that group

type Cursor

type Cursor struct {
	Loc

	// Last cursor x position
	LastVisualX int

	// The current selection as a range of character numbers (inclusive)
	CurSelection [2]Loc
	// The original selection as a range of character numbers
	// This is used for line and word selection where it is necessary
	// to know what the original selection was
	OrigSelection [2]Loc

	// Which cursor index is this (for multiple cursors)
	Num int
	// contains filtered or unexported fields
}

The Cursor struct stores the location of the cursor in the view The complicated part about the cursor is storing its location. The cursor must be displayed at an x, y location, but since the buffer uses a rope to store text, to insert text we must have an index. It is also simpler to use character indicies for other tasks such as selection.

func (*Cursor) AddLineToSelection

func (c *Cursor) AddLineToSelection()

AddLineToSelection adds the current line to the selection

func (*Cursor) AddWordToSelection

func (c *Cursor) AddWordToSelection()

AddWordToSelection adds the word the cursor is currently on to the selection

func (*Cursor) CopySelection

func (c *Cursor) CopySelection(target string)

CopySelection copies the user's selection to either "primary" or "clipboard"

func (*Cursor) DeleteSelection

func (c *Cursor) DeleteSelection()

DeleteSelection deletes the currently selected text

func (*Cursor) Down

func (c *Cursor) Down()

Down moves the cursor down one line (if possible)

func (*Cursor) DownN

func (c *Cursor) DownN(amount int)

DownN moves the cursor down N lines (if possible)

func (*Cursor) End

func (c *Cursor) End()

End moves the cursor to the end of the line it is on

func (*Cursor) GetCharPosInLine

func (c *Cursor) GetCharPosInLine(lineNum, visualPos int) int

GetCharPosInLine gets the char position of a visual x y coordinate (this is necessary because tabs are 1 char but 4 visual spaces)

func (*Cursor) GetSelection

func (c *Cursor) GetSelection() string

GetSelection returns the cursor's selection

func (*Cursor) GetVisualX

func (c *Cursor) GetVisualX() int

GetVisualX returns the x value of the cursor in visual spaces

func (*Cursor) Goto

func (c *Cursor) Goto(b Cursor)

Goto puts the cursor at the given cursor's location and gives the current cursor its selection too

func (*Cursor) GotoLoc

func (c *Cursor) GotoLoc(l Loc)

GotoLoc puts the cursor at the given cursor's location and gives the current cursor its selection too

func (*Cursor) HasSelection

func (c *Cursor) HasSelection() bool

HasSelection returns whether or not the user has selected anything

func (*Cursor) Left

func (c *Cursor) Left()

Left moves the cursor left one cell (if possible) or to the previous line if it is at the beginning

func (*Cursor) Relocate

func (c *Cursor) Relocate()

Relocate makes sure that the cursor is inside the bounds of the buffer If it isn't, it moves it to be within the buffer's lines

func (*Cursor) ResetSelection

func (c *Cursor) ResetSelection()

ResetSelection resets the user's selection

func (*Cursor) Right

func (c *Cursor) Right()

Right moves the cursor right one cell (if possible) or to the next line if it is at the end

func (*Cursor) RuneUnder

func (c *Cursor) RuneUnder(x int) rune

RuneUnder returns the rune under the given x position

func (*Cursor) SelectLine

func (c *Cursor) SelectLine()

SelectLine selects the current line

func (*Cursor) SelectTo

func (c *Cursor) SelectTo(loc Loc)

SelectTo selects from the current cursor location to the given location

func (*Cursor) SelectWord

func (c *Cursor) SelectWord()

SelectWord selects the word the cursor is currently on

func (*Cursor) SetSelectionEnd

func (c *Cursor) SetSelectionEnd(pos Loc)

SetSelectionEnd sets the end of the selection

func (*Cursor) SetSelectionStart

func (c *Cursor) SetSelectionStart(pos Loc)

SetSelectionStart sets the start of the selection

func (*Cursor) Start

func (c *Cursor) Start()

Start moves the cursor to the start of the line it is on

func (*Cursor) StartOfText

func (c *Cursor) StartOfText()

StartOfText moves the cursor to the first non-whitespace rune of the line it is on

func (*Cursor) StoreVisualX

func (c *Cursor) StoreVisualX()

StoreVisualX stores the current visual x value in the cursor

func (*Cursor) Up

func (c *Cursor) Up()

Up moves the cursor up one line (if possible)

func (*Cursor) UpN

func (c *Cursor) UpN(amount int)

UpN moves the cursor up N lines (if possible)

func (*Cursor) WordLeft

func (c *Cursor) WordLeft()

WordLeft moves the cursor one word to the left

func (*Cursor) WordRight

func (c *Cursor) WordRight()

WordRight moves the cursor one word to the right

type Delta

type Delta struct {
	Text  string
	Start Loc
	End   Loc
}

A Delta is a change to the buffer

type Element

type Element struct {
	Value *TextEvent
	Next  *Element
}

An Element which is stored in the Stack

type EventHandler

type EventHandler struct {
	UndoStack *Stack
	RedoStack *Stack
	// contains filtered or unexported fields
}

EventHandler executes text manipulations and allows undoing and redoing

func NewEventHandler

func NewEventHandler(buf *Buffer) *EventHandler

NewEventHandler returns a new EventHandler

func (*EventHandler) ApplyDiff

func (eh *EventHandler) ApplyDiff(new string)

ApplyDiff takes a string and runs the necessary insertion and deletion events to make the buffer equal to that string This means that we can transform the buffer into any string and still preserve undo/redo through insert and delete events

func (*EventHandler) Execute

func (eh *EventHandler) Execute(t *TextEvent)

Execute a textevent and add it to the undo stack

func (*EventHandler) Insert

func (eh *EventHandler) Insert(start Loc, text string)

Insert creates an insert text event and executes it

func (*EventHandler) MultipleReplace

func (eh *EventHandler) MultipleReplace(deltas []Delta)

MultipleReplace creates an multiple insertions executes them

func (*EventHandler) Redo

func (eh *EventHandler) Redo()

Redo the first event in the redo stack

func (*EventHandler) RedoOneEvent

func (eh *EventHandler) RedoOneEvent()

RedoOneEvent redoes one event

func (*EventHandler) Remove

func (eh *EventHandler) Remove(start, end Loc)

Remove creates a remove text event and executes it

func (*EventHandler) Replace

func (eh *EventHandler) Replace(start, end Loc, replace string)

Replace deletes from start to end and replaces it with the given string

func (*EventHandler) Undo

func (eh *EventHandler) Undo()

Undo the first event in the undo stack

func (*EventHandler) UndoOneEvent

func (eh *EventHandler) UndoOneEvent()

UndoOneEvent undoes one event

type KeyBindings

type KeyBindings map[keyDesc][]func(*View) bool

KeyBindings associates key presses with view actions.

var DefaultKeyBindings KeyBindings

func NewKeyBindings

func NewKeyBindings(bindings map[string]string) KeyBindings

NewKeyBindings returns a new set of keybindings from the given set of binding descriptions.

func (KeyBindings) BindKey

func (bindings KeyBindings) BindKey(key string, actions string) KeyBindings

BindKey binds a key to a list of actions. If the key is not found or if any action is not found, this function has no effect.

func (KeyBindings) BindKeys

func (bindings KeyBindings) BindKeys(keys map[string]string) KeyBindings

BindKeys binds a set of keys to actions.

type Line

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

A Line contains the data in bytes as well as a highlight state, match and a flag for whether the highlighting needs to be updated

func Append

func Append(slice []Line, data ...Line) []Line

Append efficiently appends lines together It allocates an additional 10000 lines if the original estimate is incorrect

type LineArray

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

A LineArray simply stores and array of lines and makes it easy to insert and delete in it

func NewLineArray

func NewLineArray(size int64, reader io.Reader) *LineArray

NewLineArray returns a new line array from an array of bytes

func (*LineArray) DeleteByte

func (la *LineArray) DeleteByte(pos Loc)

DeleteByte deletes the byte at a position

func (*LineArray) DeleteFromStart

func (la *LineArray) DeleteFromStart(pos Loc)

DeleteFromStart deletes from the start of a line to the position

func (*LineArray) DeleteLine

func (la *LineArray) DeleteLine(y int)

DeleteLine deletes the line number

func (*LineArray) DeleteToEnd

func (la *LineArray) DeleteToEnd(pos Loc)

DeleteToEnd deletes from the end of a line to the position

func (*LineArray) JoinLines

func (la *LineArray) JoinLines(a, b int)

JoinLines joins the two lines a and b

func (*LineArray) NewlineBelow

func (la *LineArray) NewlineBelow(y int)

NewlineBelow adds a newline below the given line number

func (*LineArray) SaveString

func (la *LineArray) SaveString(useCrlf bool) string

SaveString returns the string that should be written to disk when the line array is saved It is the same as string but uses crlf or lf line endings depending

func (*LineArray) Split

func (la *LineArray) Split(pos Loc)

Split splits a line at a given position

func (*LineArray) String

func (la *LineArray) String() string

Returns the String representation of the LineArray

func (*LineArray) Substr

func (la *LineArray) Substr(start, end Loc) string

Substr returns the string representation between two locations

type Loc

type Loc struct {
	X, Y int
}

Loc stores a location

func FromCharPos

func FromCharPos(loc int, buf *Buffer) Loc

FromCharPos converts from a character position to an x, y position

func (Loc) GreaterEqual

func (l Loc) GreaterEqual(b Loc) bool

GreaterEqual returns true if b is greater than or equal to b

func (Loc) GreaterThan

func (l Loc) GreaterThan(b Loc) bool

GreaterThan returns true if b is bigger

func (Loc) LessEqual

func (l Loc) LessEqual(b Loc) bool

LessEqual returns true if b is less than or equal to b

func (Loc) LessThan

func (l Loc) LessThan(b Loc) bool

LessThan returns true if b is smaller

func (Loc) Move

func (l Loc) Move(n int, buf *Buffer) Loc

Move moves the cursor n characters to the left or right It moves the cursor left if n is negative

type ScrollBar

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

ScrollBar represents an optional scrollbar that can be used

func (*ScrollBar) Display

func (sb *ScrollBar) Display(screen tcell.Screen)

Display shows the scrollbar

type Stack

type Stack struct {
	Top  *Element
	Size int
}

Stack is a simple implementation of a LIFO stack for text events

func (*Stack) Len

func (s *Stack) Len() int

Len returns the stack's length

func (*Stack) Peek

func (s *Stack) Peek() *TextEvent

Peek returns the top element of the stack without removing it

func (*Stack) Pop

func (s *Stack) Pop() (value *TextEvent)

Pop removes the top element from the stack and returns its value If the stack is empty, return nil

func (*Stack) Push

func (s *Stack) Push(value *TextEvent)

Push a new element onto the stack

type TextEvent

type TextEvent struct {
	C Cursor

	EventType int
	Deltas    []Delta
	Time      time.Time
}

TextEvent holds data for a manipulation on some text that can be undone

type View

type View struct {
	*tview.Box

	// A pointer to the buffer's cursor for ease of access
	Cursor *Cursor

	// The topmost line, used for vertical scrolling
	Topline int

	// Specifies whether or not this view is readonly
	Readonly bool

	// The buffer
	Buf *Buffer
	// contains filtered or unexported fields
}

The View struct stores information about a view into a buffer. It stores information about the cursor, and the viewport that the user sees the buffer from.

func NewView

func NewView(buf *Buffer) *View

NewView returns a new view with the specified buffer.

func (*View) Backspace

func (v *View) Backspace() bool

Backspace deletes the previous character

func (*View) Bottomline

func (v *View) Bottomline() int

Bottomline returns the line number of the lowest line in the view You might think that this is obviously just v.Topline + v.height but if softwrap is enabled things get complicated since one buffer line can take up multiple lines in the view

func (*View) Center

func (v *View) Center() bool

Center centers the view on the cursor

func (*View) Copy

func (v *View) Copy() bool

Copy the selection to the system clipboard

func (*View) CursorDown

func (v *View) CursorDown() bool

CursorDown moves the cursor down

func (*View) CursorEnd

func (v *View) CursorEnd() bool

CursorEnd moves the cursor to the end of the buffer

func (*View) CursorLeft

func (v *View) CursorLeft() bool

CursorLeft moves the cursor left

func (*View) CursorPageDown

func (v *View) CursorPageDown() bool

CursorPageDown places the cursor a page up

func (*View) CursorPageUp

func (v *View) CursorPageUp() bool

CursorPageUp places the cursor a page up

func (*View) CursorRight

func (v *View) CursorRight() bool

CursorRight moves the cursor right

func (*View) CursorStart

func (v *View) CursorStart() bool

CursorStart moves the cursor to the start of the buffer

func (*View) CursorUp

func (v *View) CursorUp() bool

CursorUp moves the cursor up

func (*View) Cut

func (v *View) Cut() bool

Cut the selection to the system clipboard

func (*View) CutLine

func (v *View) CutLine() bool

CutLine cuts the current line to the clipboard

func (*View) Delete

func (v *View) Delete() bool

Delete deletes the next character

func (*View) DeleteLine

func (v *View) DeleteLine() bool

DeleteLine deletes the current line

func (*View) DeleteWordLeft

func (v *View) DeleteWordLeft() bool

DeleteWordLeft deletes the word to the left of the cursor

func (*View) DeleteWordRight

func (v *View) DeleteWordRight() bool

DeleteWordRight deletes the word to the right of the cursor

func (*View) Draw

func (v *View) Draw(screen tcell.Screen) bool

Draw renders the view and the cursor

func (*View) DuplicateLine

func (v *View) DuplicateLine() bool

DuplicateLine duplicates the current line or selection

func (*View) End

func (v *View) End() bool

End moves the viewport to the end of the buffer

func (*View) EndOfLine

func (v *View) EndOfLine() bool

EndOfLine moves the cursor to the end of the line

func (*View) Escape

func (v *View) Escape() bool

Escape leaves current mode

func (*View) ExecuteActions

func (v *View) ExecuteActions(actions []func(*View) bool) bool

Execute actions executes the supplied actions

func (*View) GetKeybindings

func (v *View) GetKeybindings() KeyBindings

GetKeyBindings gets the keybindings for this view.

func (*View) HalfPageDown

func (v *View) HalfPageDown() bool

HalfPageDown scrolls the view down half a page

func (*View) HalfPageUp

func (v *View) HalfPageUp() bool

HalfPageUp scrolls the view up half a page

func (*View) HandleEvent

func (v *View) HandleEvent(event tcell.Event)

HandleEvent handles an event passed by the main loop

func (*View) IndentSelection

func (v *View) IndentSelection() bool

IndentSelection indents the current selection

func (*View) InputHandler

func (v *View) InputHandler() func(event *tcell.EventKey, _ func(p tview.Primitive))

InputHandler returns a handler which received key events when this view has focus,

func (*View) InsertNewline

func (v *View) InsertNewline() bool

InsertNewline inserts a newline plus possible some whitespace if autoindent is on

func (*View) InsertSpace

func (v *View) InsertSpace() bool

InsertSpace inserts a space

func (*View) InsertTab

func (v *View) InsertTab() bool

InsertTab inserts a tab or spaces

func (*View) JumpToMatchingBrace

func (v *View) JumpToMatchingBrace() bool

JumpToMatchingBrace moves the cursor to the matching brace if it is currently on a brace

func (*View) MoveLinesDown

func (v *View) MoveLinesDown() bool

MoveLinesDown moves down the current line or selected lines if any

func (*View) MoveLinesUp

func (v *View) MoveLinesUp() bool

MoveLinesUp moves up the current line or selected lines if any

func (*View) OpenBuffer

func (v *View) OpenBuffer(buf *Buffer)

OpenBuffer opens a new buffer in this view. This resets the topline, event handler and cursor.

func (*View) OutdentLine

func (v *View) OutdentLine() bool

OutdentLine moves the current line back one indentation

func (*View) OutdentSelection

func (v *View) OutdentSelection() bool

OutdentSelection takes the current selection and moves it back one indent level

func (*View) PageDown

func (v *View) PageDown() bool

PageDown scrolls the view down a page

func (*View) PageUp

func (v *View) PageUp() bool

PageUp scrolls the view up a page

func (*View) ParagraphNext

func (v *View) ParagraphNext() bool

ParagraphNext moves the cursor to the next empty line, or end of the buffer if there's none

func (*View) ParagraphPrevious

func (v *View) ParagraphPrevious() bool

ParagraphPrevious moves the cursor to the previous empty line, or beginning of the buffer if there's none

func (*View) Paste

func (v *View) Paste() bool

Paste whatever is in the system clipboard into the buffer Delete and paste if the user has a selection

func (*View) Redo

func (v *View) Redo() bool

Redo redoes the last action

func (*View) Relocate

func (v *View) Relocate() bool

Relocate moves the view window so that the cursor is in view This is useful if the user has scrolled far away, and then starts typing

func (*View) RemoveAllMultiCursors

func (v *View) RemoveAllMultiCursors() bool

RemoveAllMultiCursors removes all cursors except the base cursor

func (*View) RemoveMultiCursor

func (v *View) RemoveMultiCursor() bool

RemoveMultiCursor removes the latest multiple cursor

func (*View) Retab

func (v *View) Retab() bool

Retab changes all tabs to spaces or all spaces to tabs depending on the user's settings

func (*View) ScrollDown

func (v *View) ScrollDown(n int)

ScrollDown scrolls the view down n lines (if possible)

func (*View) ScrollDownAction

func (v *View) ScrollDownAction() bool

ScrollDownAction scrolls the view up

func (*View) ScrollUp

func (v *View) ScrollUp(n int)

ScrollUp scrolls the view up n lines (if possible)

func (*View) ScrollUpAction

func (v *View) ScrollUpAction() bool

ScrollUpAction scrolls the view up

func (*View) SelectAll

func (v *View) SelectAll() bool

SelectAll selects the entire buffer

func (*View) SelectDown

func (v *View) SelectDown() bool

SelectDown selects down one line

func (*View) SelectLeft

func (v *View) SelectLeft() bool

SelectLeft selects the character to the left of the cursor

func (*View) SelectLine

func (v *View) SelectLine() bool

SelectLine selects the entire current line

func (*View) SelectPageDown

func (v *View) SelectPageDown() bool

SelectPageDown selects down one page

func (*View) SelectPageUp

func (v *View) SelectPageUp() bool

SelectPageUp selects up one page

func (*View) SelectRight

func (v *View) SelectRight() bool

SelectRight selects the character to the right of the cursor

func (*View) SelectToEnd

func (v *View) SelectToEnd() bool

SelectToEnd selects the text from the cursor to the end of the buffer

func (*View) SelectToEndOfLine

func (v *View) SelectToEndOfLine() bool

SelectToEndOfLine selects to the end of the current line

func (*View) SelectToStart

func (v *View) SelectToStart() bool

SelectToStart selects the text from the cursor to the start of the buffer

func (*View) SelectToStartOfLine

func (v *View) SelectToStartOfLine() bool

SelectToStartOfLine selects to the start of the current line

func (*View) SelectUp

func (v *View) SelectUp() bool

SelectUp selects up one line

func (*View) SelectWordLeft

func (v *View) SelectWordLeft() bool

SelectWordLeft selects the word to the left of the cursor

func (*View) SelectWordRight

func (v *View) SelectWordRight() bool

SelectWordRight selects the word to the right of the cursor

func (*View) SetCursor

func (v *View) SetCursor(c *Cursor) bool

SetCursor sets the view's and buffer's cursor

func (*View) SetKeybindings

func (v *View) SetKeybindings(bindings KeyBindings)

SetKeybindings sets the keybindings for this view.

func (*View) SetRect

func (v *View) SetRect(x, y, width, height int)

SetRect sets a new position for the view.

func (*View) SkipMultiCursor

func (v *View) SkipMultiCursor() bool

SkipMultiCursor moves the current multiple cursor to the next available position

func (*View) SpawnMultiCursor

func (v *View) SpawnMultiCursor() bool

SpawnMultiCursor creates a new multiple cursor at the next occurrence of the current selection or current word

func (*View) SpawnMultiCursorSelect

func (v *View) SpawnMultiCursorSelect() bool

SpawnMultiCursorSelect adds a cursor at the beginning of each line of a selection

func (*View) Start

func (v *View) Start() bool

Start moves the viewport to the start of the buffer

func (*View) StartOfLine

func (v *View) StartOfLine() bool

StartOfLine moves the cursor to the start of the line

func (*View) ToggleOverwriteMode

func (v *View) ToggleOverwriteMode() bool

ToggleOverwriteMode lets the user toggle the text overwrite mode

func (*View) ToggleRuler

func (v *View) ToggleRuler() bool

ToggleRuler turns line numbers off and on

func (*View) Undo

func (v *View) Undo() bool

Undo undoes the last action

func (*View) WordLeft

func (v *View) WordLeft() bool

WordLeft moves the cursor one word to the left

func (*View) WordRight

func (v *View) WordRight() bool

WordRight moves the cursor one word to the right

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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