| Key | Action |
|---|
↑ / k | Scroll up one line |
↓ / j | Scroll down one line |
← / h | Scroll left |
→ / l | Scroll right |
Home / g | Jump to top |
End / G | Jump to bottom |
PgUp | Page up |
PgDn | Page 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.).
Usage
code := components.NewCodeView().
SetCode("package main\n\nfunc main() {}\n").
SetLanguage(components.LangGo).
SetShowLineNumbers(true).
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
| Constant | Description |
LangNone | |
LangGo | |
LangPython | |
LangJavaScript | |
LangTypeScript | |
LangRust | |
LangJSON | |
LangYAML | |
LangSQL | |
LangBash | |
LangMarkdown | |