editor

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// BarForeground is the foreground color of title/status bars.
	BarForeground = termbox.ColorBlack

	// BarBackground is the background color of title/status bars.
	BarBackground = termbox.ColorWhite
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolAnswer

type BoolAnswer int

BoolAnswer represents a boolean answer choice.

const (

	// BoolAnswerCancel represents a cancelled prompt.
	BoolAnswerCancel BoolAnswer = -1

	// BoolAnswerNo represents a "No" answer.
	BoolAnswerNo BoolAnswer = 0

	// BoolAnswerYes represents a "Yes" answer.
	BoolAnswerYes BoolAnswer = 1
)

type CursorMove

type CursorMove int

CursorMove is a type of cursor movement.

const (

	// CursorMoveUp moves the cursor up one row.
	CursorMoveUp CursorMove = 0

	// CursorMoveDown moves the cursor down one row.
	CursorMoveDown CursorMove = 1

	// CursorMoveLeft moves the cursor left one column.
	CursorMoveLeft CursorMove = 2

	// CursorMoveRight moves the cursor right one column.
	CursorMoveRight CursorMove = 3

	// CursorMoveLineStart moves the cursor to the first non-whitespace
	// character of the line, or the first character of the line if the cursor
	// is already on the first non-whitespace character.
	CursorMoveLineStart CursorMove = 4

	// CursorMoveLineEnd moves the cursor to the end of the line.
	CursorMoveLineEnd CursorMove = 5

	// CursorMovePageUp moves the cursor up by the  height of the screen.
	CursorMovePageUp CursorMove = 6

	// CursorMovePageDown moves the cursor down by the  height of the screen.
	CursorMovePageDown CursorMove = 7
)

type Editor

type Editor struct {

	// The editor's buffers and the index of the focused buffer.
	Buffers    []buffer.Buffer
	FocusIndex int

	// The editor's height and width measured in rows and columns, respectively.
	Width  int
	Height int

	// The current status message and the time it was set.
	StatusMessage     string
	StatusMessageTime time.Time

	// The prompt question, answer, and whether it is active or not.
	PromptQuestion string
	PromptAnswer   string
	PromptIsActive bool

	// The user's editor configuration.
	Config config.Config
}

Editor is the editor instance and manages the UI.

func Create

func Create() (editor Editor)

Create creates a new Editor instance.

func (*Editor) Ask

func (e *Editor) Ask(question, answer string) (string, error)

Ask prompts the user to answer a question and assumes control over all input until the question is answered or the request is cancelled.

func (*Editor) AskBool

func (e *Editor) AskBool(question string) BoolAnswer

AskBool asks a yes or no question with the choice of cancelling.

func (*Editor) BufferCount

func (e *Editor) BufferCount() int

BufferCount is a shorthand for getting the number of open buffers.

func (*Editor) Close

func (e *Editor) Close(i int)

Close closes the focused buffer.

func (*Editor) DeletePromptRune

func (e *Editor) DeletePromptRune()

DeletePromptRune deletes a rune from the current prompt answer.

func (*Editor) Draw

func (e *Editor) Draw()

Draw draws the entire editor - UI, buffer, etc. - to the screen & updates the cursor's position.

func (*Editor) DrawBuffer

func (e *Editor) DrawBuffer()

DrawBuffer draws the editor's focused buffer.

func (*Editor) DrawStatusBar

func (e *Editor) DrawStatusBar()

DrawStatusBar draws the editor's status bar on the bottom of the screen.

func (*Editor) DrawTitleBar

func (e *Editor) DrawTitleBar()

DrawTitleBar draws the editor's title bar at the top of the screen.

func (*Editor) FB

func (e *Editor) FB() *buffer.Buffer

FB returns the focused buffer.

func (*Editor) HandleEvent

func (e *Editor) HandleEvent(event termbox.Event)

HandleEvent executes the appropriate code in response to an event.

func (*Editor) InsertPromptRune

func (e *Editor) InsertPromptRune(c rune)

InsertPromptRune inserts a rune into the current prompt answer.

func (*Editor) JumpToLine added in v0.5.5

func (e *Editor) JumpToLine()

JumpToLine asks the user for a line number and attempts to jump to that line.

func (*Editor) MoveCursor

func (e *Editor) MoveCursor(move CursorMove)

MoveCursor moves the cursor according to the operation provided.

func (*Editor) MovePromptCursor

func (e *Editor) MovePromptCursor(move CursorMove)

MovePromptCursor moves the cursor inside of the current prompt.

func (*Editor) Open

func (e *Editor) Open()

Open prompts the user for a path and creates a new buffer for it.

func (*Editor) Run

func (e *Editor) Run(args []string)

Run starts the editor.

func (*Editor) Save

func (e *Editor) Save()

Save writes the current buffer back to the file it was read from.

func (*Editor) ScrollView

func (e *Editor) ScrollView()

ScrollView recalculates the offsets for the view window.

func (*Editor) SetStatusMessage

func (e *Editor) SetStatusMessage(format string, args ...interface{})

SetStatusMessage sets the status message and the time it was set at.

func (*Editor) ShowHelp

func (e *Editor) ShowHelp()

func (*Editor) Shutdown

func (e *Editor) Shutdown()

Shutdown tears down the terminal screen and ends the process.

Jump to

Keyboard shortcuts

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