editor

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Editor

type Editor struct {
	// Text contains the editor's content.
	Text []rune

	// Cursor represents the cursor position of the editor.
	Cursor int

	// Width represents the terminal's width in characters.
	Width int

	// Height represents the terminal's width in characters.
	Height int

	// ColOff is the number of columns between the start of a line and the left of the editor window
	ColOff int

	// RowOff is the number of rows between the beginning of the text and the top of the editor window
	RowOff int

	// ShowMsg acts like a switch for the status bar.
	ShowMsg bool

	// StatusMsg holds the text to be displayed in the status bar.
	StatusMsg string

	// StatusChan is used to send and receive status messages.
	StatusChan chan string

	// StatusMu protects against concurrent reads and writes to status bar info.
	StatusMu sync.Mutex

	// Users holds the names of all users connected to the server, displayed in the status bar.
	Users []string

	// ScrollEnabled determines whether or not the user can scroll past the initial editor
	// window. It is set by the EditorConfig.
	ScrollEnabled bool

	// IsConnected shows whether the editor is currently connected to the server.
	IsConnected bool

	// DrawChan is used to send and receive signals to update the terminal display.
	DrawChan chan int
	// contains filtered or unexported fields
}

Editor represents the editor's skeleton. The editor is composed of two components: 1. an editable text area; which acts as the primary interactive area. 2. a status bar; which displays messages on different events, for example, when an user joins a session, etc.

func NewEditor

func NewEditor(conf EditorConfig) *Editor

NewEditor returns a new instance of the editor.

func (*Editor) Draw

func (e *Editor) Draw()

Draw updates the UI by setting cells with the editor's content.

func (*Editor) DrawInfoBar added in v1.2.1

func (e *Editor) DrawInfoBar()

DrawInfoBar draws the editor's debug information and the names of the active users in the editing session at the bottom of the termbox window.

func (*Editor) DrawStatusBar added in v1.2.1

func (e *Editor) DrawStatusBar()

DrawStatusBar shows all status and debug information on the bottom line of the editor.

func (*Editor) DrawStatusMsg added in v1.2.1

func (e *Editor) DrawStatusMsg()

DrawStatusMsg draws the editor's status message at the bottom of the termbox window.

func (*Editor) GetColOff added in v1.2.1

func (e *Editor) GetColOff() int

GetColOff returns the horizontal offset of the editor window from the start of a line.

func (*Editor) GetHeight

func (e *Editor) GetHeight() int

GetWidth returns the editor's height (in characters).

func (*Editor) GetRowOff added in v1.2.1

func (e *Editor) GetRowOff() int

GetRowOff returns the vertical offset of the editor window from the start of the text.

func (*Editor) GetText

func (e *Editor) GetText() []rune

GetText returns the editor's content.

func (*Editor) GetWidth

func (e *Editor) GetWidth() int

GetWidth returns the editor's width (in characters).

func (*Editor) GetX

func (e *Editor) GetX() int

GetX returns the X-axis component of the current cursor position.

func (*Editor) GetY

func (e *Editor) GetY() int

GetY returns the Y-axis component of the current cursor position.

func (*Editor) IncColOff added in v1.2.1

func (e *Editor) IncColOff(inc int)

IncColOff increments the horizontal offset of the editor window from the start of a line by inc.

func (*Editor) IncRowOff added in v1.2.1

func (e *Editor) IncRowOff(inc int)

IncRowOff increments the vertical offset of the editor window from the start of the text by inc.

func (*Editor) MoveCursor

func (e *Editor) MoveCursor(x, y int)

MoveCursor updates the cursor position horizontally by a given x increment, and vertically by one line in the direction indicated by y. The positive directions are right and down, respectively. This is used by the UI layer, where it updates the cursor position on keypresses.

func (*Editor) SendDraw added in v1.2.1

func (e *Editor) SendDraw()

SendDraw sends a draw signal to the drawLoop. Use this function to ensure concurrency safety for rendering the editor.

func (*Editor) SetSize

func (e *Editor) SetSize(w, h int)

SetSize sets the editor size to the specific width and height.

func (*Editor) SetText

func (e *Editor) SetText(text string)

SetText sets the given string as the editor's content.

func (*Editor) SetX

func (e *Editor) SetX(x int)

SetX sets the X-axis component of the current cursor position to the specified X position.

type EditorConfig added in v1.2.1

type EditorConfig struct {
	ScrollEnabled bool
}

Jump to

Keyboard shortcuts

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