codeview

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package codeview provides a bubbletea component for displaying code. It adds line numbers and makes sure the code fits on the screen. It does not support wrapping long lines; instead, it trims them.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	Up: key.NewBinding(
		key.WithKeys("up", "k"),
		key.WithHelp("↑/k", "up"),
	),
	Down: key.NewBinding(
		key.WithKeys("down", "j"),
		key.WithHelp("↓/j", "down"),
	),
	Home: key.NewBinding(
		key.WithKeys("home", "g"),
		key.WithHelp("g/home", "top"),
	),
	End: key.NewBinding(
		key.WithKeys("end", "G"),
		key.WithHelp("G/end", "bottom"),
	),
	Back: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "back"),
	),
	Quit: key.NewBinding(
		key.WithKeys("q", "ctrl+c"),
		key.WithHelp("q", "quit"),
	),
	HalfScreenDown: key.NewBinding(
		key.WithKeys("d"),
		key.WithHelp("d", "half screen down"),
	),
	HalfScreenUp: key.NewBinding(
		key.WithKeys("u"),
		key.WithHelp("u", "half screen down"),
	),
}

DefaultKeyMap is the default KeyMap used by codeview package.

Functions

This section is empty.

Types

type KeyMap

type KeyMap struct {
	Up             key.Binding
	Down           key.Binding
	Home           key.Binding
	End            key.Binding
	Back           key.Binding
	Quit           key.Binding
	HalfScreenDown key.Binding
	HalfScreenUp   key.Binding
}

KeyMap includes codeview key mappings.

type Model

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

Model is the codeview model. Use New to create a new instance.

func New

func New(width, height int) Model

New creates a new codeview model which is rendered into the provided width and height.

func (*Model) FullHelp

func (m *Model) FullHelp() [][]key.Binding

FullHelp implements help.KeyMap interface.

func (*Model) Height

func (m *Model) Height() int

Height returns the height of the codeview.

func (*Model) SetContent

func (m *Model) SetContent(lines []string)

SetContent sets the content of the codeview.

func (*Model) SetFilteredLines added in v0.5.0

func (m *Model) SetFilteredLines(filteredLines []int)

SetFilteredLines sets the lines that should be displayed, while all other lines are hidden. If not set, everything is displayed.

func (*Model) SetHeight

func (m *Model) SetHeight(height int)

SetHeight sets the height of the codeview.

func (*Model) SetShowFullHelp

func (m *Model) SetShowFullHelp(showFullHelp bool)

SetShowFullHelp allows to view extended help section, if visible.

func (*Model) SetShowHelp

func (m *Model) SetShowHelp(showHelp bool)

SetShowHelp allows to hide or show the help section.

func (*Model) SetTitle

func (m *Model) SetTitle(title string)

SetTitle sets the title of the codeview, usually the file name.

func (*Model) SetWidth

func (m *Model) SetWidth(width int)

SetWidth sets the width of the codeview.

func (*Model) ShortHelp

func (m *Model) ShortHelp() []key.Binding

ShortHelp implements help.KeyMap interface.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update is used to update the internal model state based on the external events.

func (*Model) View

func (m *Model) View() string

View renders the model to be displayed.

func (*Model) Width

func (m *Model) Width() int

Width returns the width of the codeview.

Jump to

Keyboard shortcuts

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