buffer

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: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInsertable

func IsInsertable(c rune) bool

IsInsertable tells whether a character is insertable into the buffer or not.

Types

type Buffer

type Buffer struct {
	Config *config.Config

	// The path to the file and its type.
	Path     string
	FileType support.FileType

	// The buffer's lines and condition.
	Lines      []Line
	IsDirty    bool
	IsReadOnly bool

	// The cursor's position. The Y value must always be decremented by one when
	// accessing buffer elements since the editor's title bar occupies the first
	// row of the screen. CursorDX is the cursor's X position, with compensation
	// for extra space introduced by rendering tabs.
	CursorX  int
	CursorDX int
	CursorY  int

	// The viewport's column and row offsets.
	OffsetX int
	OffsetY int
}

Buffer represents a text buffer corresponding to a file.

func Create

func Create(config *config.Config, path string) (Buffer, error)

Create creates a new buffer for a given path.

func FromStrings

func FromStrings(config *config.Config, name string, rawLines []string) Buffer

FromStrings creates a buffer from an array of strings rather than a file.

func (*Buffer) BreakLine

func (b *Buffer) BreakLine()

BreakLine inserts a newline character and breaks the line at the cursor.

func (*Buffer) DeleteRune

func (b *Buffer) DeleteRune()

DeleteRune deletes the rune to the left of the cursor.

func (*Buffer) FileName

func (b *Buffer) FileName() string

FileName extracts the name of the file from the buffer's file path.

func (*Buffer) FocusedLine

func (b *Buffer) FocusedLine() *Line

FocusedLine returns the buffer's focused line.

func (*Buffer) InsertLine

func (b *Buffer) InsertLine(i int, text string)

InsertLine inserts a new line to the buffer at the given index.

func (*Buffer) InsertRune

func (b *Buffer) InsertRune(c rune)

InsertRune inserts a rune at the cursor's position.

func (*Buffer) Length

func (b *Buffer) Length() int

Length returns the buffer's length (number of lines).

func (*Buffer) PreviousLine added in v0.5.3

func (b *Buffer) PreviousLine() *Line

PreviousLine returns the line above the buffer's focused line.

func (*Buffer) RemoveLine

func (b *Buffer) RemoveLine(i int)

RemoveLine removes the line at the given index from the buffer.

func (*Buffer) Write

func (b *Buffer) Write(path string) error

type Line

type Line struct {
	Buffer      *Buffer
	Text        string
	DisplayText string
	TokenTypes  []TokenType
}

Line represents a single line in a buffer.

func MakeBufferLine

func MakeBufferLine(buffer *Buffer, text string) (bl Line)

MakeBufferLine creates a new Line with the given text.

func (*Line) AdjustedX

func (l *Line) AdjustedX(x int) int

AdjustedX returns the cursor's X position compensated for tab expansion.

func (*Line) AppendString

func (l *Line) AppendString(s string)

AppendString appends a string to the line.

func (*Line) DeleteRune

func (l *Line) DeleteRune(i int)

DeleteRune deletes a rune from the line at the given index.

func (*Line) Highlight

func (l *Line) Highlight(s *syntax.Syntax)

Highlight updates the character to highlighting mapping for a line.

func (*Line) IndentLength

func (l *Line) IndentLength() (indent int)

IndentLength gets the line's level of indentation in columns.

func (*Line) InsertRune

func (l *Line) InsertRune(i int, c rune)

InsertRune inserts a rune into the line at the given index.

func (*Line) Update

func (l *Line) Update()

Update refreshes the DisplayText field.

type TokenType

type TokenType int

TokenType represents the type of token a rune belongs to.

const (

	// TokenTypeText is the default token type.
	TokenTypeText TokenType = iota

	// TokenTypeKeyword represents a language keyword.
	TokenTypeKeyword

	// TokenTypeNumber represents a number.
	TokenTypeNumber

	// TokenTypeString represents a string.
	TokenTypeString

	// TokenTypeComment represents a comment.
	TokenTypeComment
)

func (TokenType) Color

func (t TokenType) Color() termbox.Attribute

Color returns the appropriate highlighting color for a highlight type.

Jump to

Keyboard shortcuts

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