code

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package code provides retained, read-only syntax highlighting for MyGo text, ported from the code view of the onevra component library (MIT). Parse outside the frame builder and retain the document until the source changes. Render joins its parent's selection; call Selectable on the returned element for an independent code view. Applications own scrolling and background work.

doc := code.Parse(source, "go")
doc.Render(c).Padding(12)

Index

Constants

View Source
const (
	MaxHighlightBytes = 64 * 1024
	MaxHighlightRuns  = 4096
)

Highlighting limits bound lexer input and retained styling. Larger or more fragmented inputs remain readable as plain text; no source is truncated.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

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

Document is an immutable highlighted source, which several views can share. Its zero value is empty. It holds no UI handles and no global source cache. Both palettes are prepared once, so Render performs neither tokenization nor span allocation on theme changes.

func Parse

func Parse(source, language string) (d *Document)

Parse highlights source in the named language, case-insensitively, accepting the aliases Chroma does (js, ts, py, sh and so on). Empty or unknown languages, invalid UTF-8, lexer failures and inputs beyond the limits use plain text. It never guesses the language, reads files or starts goroutines. Source bytes, tabs and line endings are preserved. Parsing is safe outside the UI thread; it is synchronous and makes no promise about its time for regex-based lexers.

func (*Document) Highlighted

func (d *Document) Highlighted() bool

Highlighted reports whether tokenization completed within the limits.

func (*Document) Render

func (d *Document) Render(c *ui.Context) ui.Element

Render builds one wrapping monospace text element. It inherits the selection of its parent and adds no background or scroll container; apply Element methods for size, padding, NoWrap or an independent selection.

func (*Document) Text

func (d *Document) Text() string

Text returns the exact input, including trailing newlines.

Jump to

Keyboard shortcuts

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