viewer

package
v0.0.0-...-a6b3c9b Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HiddenTmpDirectoryName = ".termdbms"
)

Variables

This section is empty.

Functions

func Abs

func Abs(a int) int

func CopyFile

func CopyFile(src string) (string, int64, error)

func Exists

func Exists(path string) (bool, error)

func FileExists

func FileExists(name string) (bool, error)

func GetDatabaseForFile

func GetDatabaseForFile(database string) *sql.DB

GetDatabaseForFile does what you think it does

func GetHelpText

func GetHelpText() (help string)

func GetInterfaceFromString

func GetInterfaceFromString(str string, original *interface{}) interface{}

func GetStringRepresentationOfInterface

func GetStringRepresentationOfInterface(val interface{}) string

func Hash

func Hash(s string) uint32

func IsUrl

func IsUrl(fp string) bool

IsUrl is some code I stole off stackoverflow to validate paths

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func SplitLines

func SplitLines(s string) []string

func Sync

func Sync(m ViewportModel) tea.Cmd

Sync tells the renderer where the viewport will be located and requests a render of the current state of the viewport. It should be called for the first render and after a window resize.

For high performance rendering only.

func TruncateIfApplicable

func TruncateIfApplicable(m *TuiModel, conv string) (s string)

func ViewDown

func ViewDown(m ViewportModel, lines []string) tea.Cmd

ViewDown is a high performance command that moves the viewport up by a given numer of lines. Use ViewportModel.ViewDown to get the lines that should be rendered. For example:

lines := model.ViewDown(1)
cmd := ViewDown(m, lines)

func ViewUp

func ViewUp(m ViewportModel, lines []string) tea.Cmd

ViewUp is a high performance command the moves the viewport down by a given number of lines height. Use ViewportModel.ViewUp to get the lines that should be rendered.

func WriteTextFile

func WriteTextFile(m *TuiModel, text string) (string, error)

Types

type Database

type Database interface {
	Update(q *Update)
	GetFileName() string
	GetDatabaseReference() *sql.DB
	CloseDatabaseReference()
	SetDatabaseReference(dbPath string)
}

type Query

type Query interface {
	GenerateQuery(db Database) (string, []string)
}

type SQLite

type SQLite struct {
	FileName string
	// contains filtered or unexported fields
}

func (*SQLite) CloseDatabaseReference

func (s *SQLite) CloseDatabaseReference()

func (*SQLite) GetDatabaseReference

func (s *SQLite) GetDatabaseReference() *sql.DB

func (*SQLite) GetFileName

func (s *SQLite) GetFileName() string

func (*SQLite) SetDatabaseReference

func (s *SQLite) SetDatabaseReference(dbPath string)

func (*SQLite) Update

func (s *SQLite) Update(q *Update)

type TableState

type TableState struct {
	Database Database
	Data     map[string]interface{}
}

type TuiModel

type TuiModel struct {
	Table             TableState          // all non destructive changes are TableStates getting passed around
	TableHeaders      map[string][]string // keeps track of which schema has which headers
	TableHeadersSlice []string
	DataSlices        map[string][]interface{}
	TableIndexMap     map[int]string // keeps the schemas in order
	TableSelection    int
	InitialFileName   string // used if saving destructively

	UndoStack []TableState
	RedoStack []TableState
	// contains filtered or unexported fields
}

TuiModel holds all the necessary state for this app to work the way I designed it to

func GetNewModel

func GetNewModel(baseFileName string, db *sql.DB) TuiModel

GetNewModel returns a TuiModel struct with some fields set

func (*TuiModel) CellWidth

func (m *TuiModel) CellWidth() int

CellWidth gets the current cell width for schema

func (*TuiModel) CopyMap

func (m *TuiModel) CopyMap() (to map[string]interface{})

func (*TuiModel) DisplayMessage

func (m *TuiModel) DisplayMessage(msg string)

func (*TuiModel) GetBaseStyle

func (m *TuiModel) GetBaseStyle() lipgloss.Style

GetBaseStyle returns a new style that is used everywhere

func (*TuiModel) GetColumn

func (m *TuiModel) GetColumn() int

GetColumn gets the column the mouse cursor is in

func (*TuiModel) GetColumnData

func (m *TuiModel) GetColumnData() []interface{}

func (*TuiModel) GetHeaders

func (m *TuiModel) GetHeaders() []string

GetHeaders does just that for the current schema

func (*TuiModel) GetRow

func (m *TuiModel) GetRow() int

GetRow does math to get a valid row that's helpful

func (*TuiModel) GetRowData

func (m *TuiModel) GetRowData() map[string]interface{}

func (*TuiModel) GetSchemaData

func (m *TuiModel) GetSchemaData() map[string][]interface{}

GetSchemaData is a helper function to get the data of the current schema

func (*TuiModel) GetSchemaName

func (m *TuiModel) GetSchemaName() string

GetSchemaName gets the current schema name

func (*TuiModel) GetSelectedColumnName

func (m *TuiModel) GetSelectedColumnName() string

func (*TuiModel) GetSelectedOption

func (m *TuiModel) GetSelectedOption() (*interface{}, int, []interface{})

func (TuiModel) Init

func (m TuiModel) Init() tea.Cmd

Init currently doesn't do anything but necessary for interface adherence

func (*TuiModel) NumHeaders

func (m *TuiModel) NumHeaders() int

NumHeaders gets the number of columns for the current schema

func (*TuiModel) ProcessSqlQueryForDatabaseType

func (m *TuiModel) ProcessSqlQueryForDatabaseType(q Query)

func (*TuiModel) Serialize

func (m *TuiModel) Serialize() string

func (*TuiModel) SerializeOverwrite

func (m *TuiModel) SerializeOverwrite()

func (*TuiModel) SetModel

func (m *TuiModel) SetModel(c *sql.Rows, db *sql.DB)

SetModel creates a model to be used by bubbletea using some golang wizardry

func (*TuiModel) SetViewSlices

func (m *TuiModel) SetViewSlices()

func (TuiModel) Update

func (m TuiModel) Update(message tea.Msg) (tea.Model, tea.Cmd)

Update is where all commands and whatnot get processed

func (TuiModel) View

func (m TuiModel) View() string

View is where all rendering happens

type Update

type Update struct {
	Values    map[string]interface{} // these are anchors to ensure the right row/col gets updated
	Column    string                 // this is the header
	Update    interface{}            // this is the new cell value
	TableName string
}

func (*Update) GenerateQuery

func (u *Update) GenerateQuery(db Database) (string, []string)

type ViewportModel

type ViewportModel struct {
	Width  int
	Height int

	// YOffset is the vertical scroll position.
	YOffset int

	// YPosition is the position of the viewport in relation to the terminal
	// window. It's used in high performance rendering.
	YPosition int

	// HighPerformanceRendering bypasses the normal Bubble Tea renderer to
	// provide higher performance rendering. Most of the time the normal Bubble
	// Tea rendering methods will suffice, but if you're passing content with
	// a lot of ANSI escape codes you may see improved rendering in certain
	// terminals with this enabled.
	//
	// This should only be used in program occupying the entire terminal,
	// which is usually via the alternate screen buffer.
	HighPerformanceRendering bool
	// contains filtered or unexported fields
}

ViewportModel is the Bubble Tea model for this viewport element.

func (ViewportModel) AtBottom

func (m ViewportModel) AtBottom() bool

AtBottom returns whether or not the viewport is at or past the very bottom position.

func (ViewportModel) AtTop

func (m ViewportModel) AtTop() bool

AtTop returns whether or not the viewport is in the very top position.

func (*ViewportModel) GotoBottom

func (m *ViewportModel) GotoBottom() (lines []string)

GotoBottom sets the viewport to the bottom position.

func (*ViewportModel) GotoTop

func (m *ViewportModel) GotoTop() (lines []string)

GotoTop sets the viewport to the top position.

func (*ViewportModel) HalfViewDown

func (m *ViewportModel) HalfViewDown() (lines []string)

HalfViewDown moves the view down by half the height of the viewport.

func (*ViewportModel) HalfViewUp

func (m *ViewportModel) HalfViewUp() (lines []string)

HalfViewUp moves the view up by half the height of the viewport.

func (*ViewportModel) LineDown

func (m *ViewportModel) LineDown(n int) (lines []string)

LineDown moves the view down by the given number of lines.

func (*ViewportModel) LineUp

func (m *ViewportModel) LineUp(n int) (lines []string)

LineUp moves the view down by the given number of lines. Returns the new lines to show.

func (ViewportModel) PastBottom

func (m ViewportModel) PastBottom() bool

PastBottom returns whether or not the viewport is scrolled beyond the last line. This can happen when adjusting the viewport height.

func (ViewportModel) ScrollPercent

func (m ViewportModel) ScrollPercent() float64

ScrollPercent returns the amount scrolled as a float between 0 and 1.

func (*ViewportModel) SetContent

func (m *ViewportModel) SetContent(s string)

SetContent set the pager's text content. For high performance rendering the Sync command should also be called.

func (ViewportModel) Update

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

Update runs the update loop with default keybindings similar to popular pagers. To define your own keybindings use the methods on ViewportModel (i.e. ViewportModel.LineDown()) and define your own update function.

func (ViewportModel) View

func (m ViewportModel) View() string

View renders the viewport into a string.

func (*ViewportModel) ViewDown

func (m *ViewportModel) ViewDown() []string

ViewDown moves the view down by the number of lines in the viewport. Basically, "page down".

func (*ViewportModel) ViewUp

func (m *ViewportModel) ViewUp() []string

ViewUp moves the view up by one height of the viewport. Basically, "page up".

Jump to

Keyboard shortcuts

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