cropviewport

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

README

Crop Viewport

A component for bubbletea.

Crops view from string given position and size.
With ANSI SGR support.

ansitext

For Usage checkout examples

Keymap

Keymaps are inside the model struct, can be changed if you want to.

Default keymaps:

  • j move down 1 line
  • k move up 1 line
  • ctrl+d move down half page
  • ctrl+u move up half page
  • h move left 1 column
  • l move right 1 column
  • H move left half row
  • L move right half row
  • if not enough place for a char width over 1, the char will not display and replaced to (multiple) white space.
  • TAB(\t) will be replaced by 4 SPACE( ), and it's hard coded, not sure if processRune should be available to access from the outside

Others

So, this is actually the first time i use go to make stuffs for others to use.
Any suggestion is welcomed here

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SPACE_HODLER   = []byte(" ")
	SPACE_RUNEDATA = &RuneData{
		Byte: SPACE_HODLER,
	}
)
View Source
var NO_CONTENT_TABLE, NO_CONTENT_SUBLINES = ProcessContent("No content available")

const NO_CONTENT = "No content available" var NO_CONTENT_TABLE, NO_CONTENT_SUBLINES = process.ProcessContent("No content available")

Functions

func CropView added in v0.2.0

func CropView(atablelist *process.ANSITableList, lines []*SubLine, x, y, width, height int) string

extract certain area of the given lines, and render ansi sequence

func NewCropViewportModel

func NewCropViewportModel() tea.Model

Types

type CropViewportModel

type CropViewportModel struct {
	ANSITableList *process.ANSITableList
	KeyMap        map[string]func() tea.Cmd
	Sublines      []*SubLine
	Block         [4]int
}

func (*CropViewportModel) BackToLeft

func (c *CropViewportModel) BackToLeft()

func (*CropViewportModel) BackToTop

func (c *CropViewportModel) BackToTop()

func (*CropViewportModel) Init

func (c *CropViewportModel) Init() tea.Cmd

* returns nil

func (*CropViewportModel) NextCol

func (c *CropViewportModel) NextCol(step int)

func (*CropViewportModel) NextLine

func (c *CropViewportModel) NextLine(step int)

func (*CropViewportModel) PrevCol

func (c *CropViewportModel) PrevCol(step int)

func (*CropViewportModel) PrevLine

func (c *CropViewportModel) PrevLine(step int)

func (*CropViewportModel) SetBlock

func (c *CropViewportModel) SetBlock(x, y, width, height int)

func (*CropViewportModel) SetContent

func (c *CropViewportModel) SetContent(s string) (*process.ANSITableList, []*SubLine)

func (*CropViewportModel) SetContentGivenData

func (c *CropViewportModel) SetContentGivenData(tableList *process.ANSITableList, lines []*SubLine)

func (*CropViewportModel) Update

func (c *CropViewportModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*CropViewportModel) View

func (c *CropViewportModel) View() string

type RuneData added in v0.2.0

type RuneData struct {
	Byte  []byte
	Bound [2]int // refers to the visible width
}

func (*RuneData) GetBounds added in v0.2.0

func (r *RuneData) GetBounds() [2]int

type RuneDataList added in v0.2.0

type RuneDataList struct {
	L          []process.BoundsStruct
	TotalWidth int
}

func (*RuneDataList) Init added in v0.2.0

func (r *RuneDataList) Init(s []rune) *RuneDataList

init RuneData list given runes

RuneDataList can only be set with this function, no more process allowed afterwards

type SubLine added in v0.2.0

type SubLine struct {
	Data  *RuneDataList
	Bound [2]int
}

func ProcessContent added in v0.2.0

func ProcessContent(s string) (*process.ANSITableList, []*SubLine)

separate ansi and normal string, separate lines into RuneData list

func SplitLines added in v0.2.2

func SplitLines(raw string) []*SubLine

Jump to

Keyboard shortcuts

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