Skip to content

CodeView

KeyAction
/ kScroll up one line
/ jScroll down one line
/ hScroll left
/ lScroll right
Home / gJump to top
End / GJump to bottom
PgUpPage up
PgDnPage down
cv := components.NewCodeView()
cv.SetContent(sourceCode, "go") // language hint for highlighting

The language hint drives syntax highlighting. Use standard language identifiers ("go", "json", "python", etc.).

CodeView preview

CodeView displays syntax-highlighted code

Constructor func NewCodeView() *CodeView

Usage

code := components.NewCodeView().
SetCode("package main\n\nfunc main() {}\n").
SetLanguage(components.LangGo).
SetShowLineNumbers(true).
SetTabWidth(4).
SetHighlightLine(3)
fmt.Println(code != nil)

Methods

Method Signature Description
GetFieldHeight func (c *CodeView) GetFieldHeight() int GetFieldHeight returns preferred height
GetLine func (c *CodeView) GetLine(index int) string GetLine returns a specific line (0-based)
GetLines func (c *CodeView) GetLines() []string GetLines returns the code lines
LineCount func (c *CodeView) LineCount() int LineCount returns the number of lines
ScrollTo func (c *CodeView) ScrollTo(line int) *CodeView ScrollTo scrolls to a specific line
SetCode func (c *CodeView) SetCode(code string) *CodeView SetCode sets the code content
SetHighlightLine func (c *CodeView) SetHighlightLine(line int) *CodeView SetHighlightLine sets the highlighted line (1-based, -1 to disable)
SetLanguage func (c *CodeView) SetLanguage(lang Language) *CodeView SetLanguage sets the syntax highlighting language
SetLines func (c *CodeView) SetLines(lines []string) *CodeView SetLines sets code from line slice
SetOnLineClick func (c *CodeView) SetOnLineClick(fn func(line int)) *CodeView SetOnLineClick sets callback for line clicks
SetShowLineNumbers func (c *CodeView) SetShowLineNumbers(show bool) *CodeView SetShowLineNumbers enables/disables line numbers
SetTabWidth func (c *CodeView) SetTabWidth(width int) *CodeView SetTabWidth sets the tab display width
SetWrapLines func (c *CodeView) SetWrapLines(wrap bool) *CodeView SetWrapLines enables/disables line wrapping

Types

type Language Language defines supported syntax highlighting languages
ConstantDescription
LangNone
LangGo
LangPython
LangJavaScript
LangTypeScript
LangRust
LangJSON
LangYAML
LangSQL
LangBash
LangMarkdown