context

package
v0.0.0-...-344d200 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FixedLeadingSpace  = "        "
	DefaultIndicator   = "^"
	NoHighlightMessage = ""
)

Variables

View Source
var (
	EolCR   = []byte{'\r'}
	EolLF   = []byte{'\n'}
	EolCRLF = []byte{'\r', '\n'}
)

Functions

func BytesToRunes

func BytesToRunes(bs []byte) []rune

func CharWidth

func CharWidth(r rune) int

func CharWidthIn

func CharWidthIn(r rune, index int) int

func RunesToBytes

func RunesToBytes(rs []rune) []byte

func StringWidth

func StringWidth(s string) int

Types

type ByHighlight

type ByHighlight []Highlight

func (ByHighlight) Len

func (a ByHighlight) Len() int

func (ByHighlight) Less

func (a ByHighlight) Less(i, j int) bool

func (ByHighlight) Swap

func (a ByHighlight) Swap(i, j int)

type ByLineContextLine

type ByLineContextLine []*LineContext

func (ByLineContextLine) Len

func (a ByLineContextLine) Len() int

func (ByLineContextLine) Less

func (a ByLineContextLine) Less(i, j int) bool

func (ByLineContextLine) Swap

func (a ByLineContextLine) Swap(i, j int)

type Context

type Context struct {
	File      *FileContext
	PrevLines []*LineContext
	NextLines []*LineContext
	Lines     []*LineContext
}

func Join

func Join(ctxs ...*Context) *Context

func (*Context) HighlightText

func (c *Context) HighlightText(format string, args ...any) string

func (*Context) HighlightTextWith

func (c *Context) HighlightTextWith(indicator string, format string, args ...any) string

func (*Context) Join

func (c *Context) Join(ctxs ...*Context) *Context

func (*Context) Last

func (c *Context) Last() (int, int)

func (*Context) Load

func (c *Context) Load(prev int, next int)

type FileContext

type FileContext struct {
	Filename string
	Contents []*LineContent
}

func ReadFile

func ReadFile(filename string) (*FileContext, error)

func ReadFileData

func ReadFileData(filename string, data []byte) *FileContext

func (*FileContext) Line

func (f *FileContext) Line(n int) *LineContent

func (*FileContext) LineContext

func (f *FileContext) LineContext(n int) *LineContext

func (*FileContext) Lines

func (f *FileContext) Lines() int

func (*FileContext) Rune

func (f *FileContext) Rune(line int, column int) (rune, bool)

type Highlight

type Highlight struct {
	Start int
	End   int
}

func NewHighlight

func NewHighlight(start, end int) Highlight

type LineContent

type LineContent struct {
	Line    int
	EOL     []rune
	Content []rune
}

func NewLineFromBytes

func NewLineFromBytes(line int, data []byte, eol []byte) LineContent

func (*LineContent) EOLBytes

func (l *LineContent) EOLBytes() []byte

func (*LineContent) Length

func (l *LineContent) Length() int

func (*LineContent) Mark

func (l *LineContent) Mark(start int, end int) *Context

func (*LineContent) MarkLine

func (l *LineContent) MarkLine(start int, end int) *LineContext

func (*LineContent) Rune

func (l *LineContent) Rune(n int) rune

func (*LineContent) String

func (l *LineContent) String() string

func (*LineContent) ToLineContext

func (l *LineContent) ToLineContext(file *FileContext) *LineContext

type LineContext

type LineContext struct {
	Content    *LineContent
	File       *FileContext
	Highlights []Highlight
}

func FindLineContextSameLine

func FindLineContextSameLine(list []*LineContext, lctx *LineContext) *LineContext

func (*LineContext) Duplicate

func (l *LineContext) Duplicate() *LineContext

func (*LineContext) HighlighText

func (l *LineContext) HighlighText(format string, args ...any) string

func (*LineContext) HighlighTextWith

func (l *LineContext) HighlighTextWith(indicator string, format string, args ...any) string

func (*LineContext) HighlightColour

func (l *LineContext) HighlightColour(colour color.Color, format string, args ...any) string

func (*LineContext) IsSameLine

func (l *LineContext) IsSameLine(other *LineContext) bool

func (*LineContext) Join

func (l *LineContext) Join(lctxs ...*LineContext) *LineContext

func (*LineContext) Last

func (l *LineContext) Last() int

func (*LineContext) Length

func (l *LineContext) Length() int

func (*LineContext) LineNumber

func (l *LineContext) LineNumber() string

func (*LineContext) Mark

func (l *LineContext) Mark(start int, end int) *Context

func (*LineContext) MarkLine

func (l *LineContext) MarkLine(start int, end int) *LineContext

func (*LineContext) Rune

func (l *LineContext) Rune(n int) (rune, bool)

func (*LineContext) String

func (l *LineContext) String() string

func (*LineContext) StringContent

func (l *LineContext) StringContent() string

func (*LineContext) ToContext

func (l *LineContext) ToContext() *Context

Jump to

Keyboard shortcuts

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