viewer

package
v0.0.0-...-f106031 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HiddenTmpDirectoryName = ".termdbms"
	SQLSnippetsFile        = "snippets.termdbms"
)
View Source
const (
	QueryResultsTableName = "results"
)

Variables

View Source
var (
	HeaderAssembly TableAssembly
	FooterAssembly TableAssembly
	Message        string

	MIP bool
)
View Source
var (
	Program          *tea.Program
	FormatModeOffset int
	TUIWidth         int
	TUIHeight        int
)
View Source
var (
	HeaderHeight       = 2
	FooterHeight       = 1
	MaxInputLength     int
	HeaderStyle        lipgloss.Style
	FooterStyle        lipgloss.Style
	HeaderDividerStyle lipgloss.Style
	InitialModel       *TuiModel
)
View Source
var (
	GlobalCommands = make(map[string]Command)
)
View Source
var (
	InputBlacklist = []string{
		"alt+",
		"ctrl+",
		"up",
		"down",
		"tab",
		"left",
		"enter",
		"right",
		"pgdown",
		"pgup",
	}
)

Functions

func Abs

func Abs(a int) int

func AssembleTable

func AssembleTable(m *TuiModel) string

AssembleTable shows either the selection text or the table

func CopyFile

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

func CreateEmptyBuffer

func CreateEmptyBuffer(m *TuiModel, original *interface{})

func CreatePopulatedBuffer

func CreatePopulatedBuffer(m *TuiModel, original *interface{}, str string)

func DisplayFormatText

func DisplayFormatText(m *TuiModel) string

func DisplaySelection

func DisplaySelection(m *TuiModel) string

DisplaySelection does that or writes it to a file if the selection is over a limit

func DisplayTable

func DisplayTable(m *TuiModel) string

DisplayTable does some fancy stuff to get a table rendered in text

func EditEnter

func EditEnter(m *TuiModel)

func Exists

func Exists(path string) (bool, error)

func ExitToDefaultView

func ExitToDefaultView(m *TuiModel)

func FileExists

func FileExists(name string) (bool, error)

func FormatJson

func FormatJson(str string) (string, error)

FormatJson is some more code I stole off stackoverflow

func GetFormattedTextBuffer

func GetFormattedTextBuffer(m *TuiModel) []string

func GetHelpText

func GetHelpText() (help string)

func GetInterfaceFromString

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

func GetOffsetForLineNumber

func GetOffsetForLineNumber(a int) int

func GetScrollDownMaximumForSelection

func GetScrollDownMaximumForSelection(m *TuiModel) int

func GetStringRepresentationOfInterface

func GetStringRepresentationOfInterface(val interface{}) string

func HandleClipboardEvents

func HandleClipboardEvents(m *TuiModel, str string, command *tea.Cmd, msg tea.Msg)

func HandleEditInput

func HandleEditInput(m *TuiModel, str, val string) (ret bool)

func HandleEditMode

func HandleEditMode(m *TuiModel, str string)

HandleEditMode implementation is kind of jank, but we can clean it up later

func HandleEditMovement

func HandleEditMovement(m *TuiModel, str, val string) (ret bool)

func HandleFormatInput

func HandleFormatInput(m *TuiModel, str string) bool

func HandleFormatMode

func HandleFormatMode(m *TuiModel, str string)

func HandleFormatMovement

func HandleFormatMovement(m *TuiModel, str string) (ret bool)

func HandleKeyboardEvents

func HandleKeyboardEvents(m *TuiModel, msg *tea.KeyMsg) tea.Cmd

HandleKeyboardEvents does that

func HandleMouseEvents

func HandleMouseEvents(m *TuiModel, msg *tea.MouseMsg)

HandleMouseEvents does that

func HandleWindowSizeEvents

func HandleWindowSizeEvents(m *TuiModel, msg *tea.WindowSizeMsg) tea.Cmd

HandleWindowSizeEvents does that

func Hash

func Hash(s string) uint32

func InsertCharacter

func InsertCharacter(m *TuiModel, newlineOrTab string)

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 MoveCursorWithinBounds

func MoveCursorWithinBounds(m *TuiModel)

func PrepareFormatMode

func PrepareFormatMode(m *TuiModel)

func ScrollDown

func ScrollDown(m *TuiModel)

ScrollDown is a simple function to move the Viewport down

func ScrollUp

func ScrollUp(m *TuiModel)

ScrollUp is a simple function to move the Viewport up

func SelectOption

func SelectOption(m *TuiModel)

func Serialize

func Serialize(m *TuiModel) (string, error)

func SerializeOverwrite

func SerializeOverwrite(m *TuiModel) error

func SerializeOverwriteSQLiteDB

func SerializeOverwriteSQLiteDB(db *database.SQLite, m *TuiModel)

func SerializeSQLiteDB

func SerializeSQLiteDB(db *database.SQLite, m *TuiModel) string

func SetStyles

func SetStyles()

func ShowClipboard

func ShowClipboard(m *TuiModel) string

func SplitLines

func SplitLines(s string) []string

func ToggleColumn

func ToggleColumn(m *TuiModel)

func TruncateIfApplicable

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

func WriteCSV

func WriteCSV(m *TuiModel)

func WriteTextFile

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

Types

type Command

type Command func(m *TuiModel) tea.Cmd

type EnterFunction

type EnterFunction func(m *TuiModel, selectedInput *tuiutil.TextInputModel, input string)

type FormatState

type FormatState struct {
	EditSlices     []*string // the bit to show
	Text           []string  // the master collection of lines to edit
	RunningOffsets []int     // this is a LUT for where in the original EditTextBuffer each line starts
	CursorX        int
	CursorY        int
}

type LineEdit

type LineEdit struct {
	Model    tuiutil.TextInputModel
	Original *interface{}
}

type SQLSnippet

type SQLSnippet struct {
	Query string `json:"Query"`
	Name  string `json:"Name"`
}

func (SQLSnippet) Description

func (s SQLSnippet) Description() string

func (SQLSnippet) FilterValue

func (s SQLSnippet) FilterValue() string

func (SQLSnippet) Title

func (s SQLSnippet) Title() string

type ScrollData

type ScrollData struct {
	PreScrollYOffset   int
	PreScrollYPosition int
	ScrollXOffset      int
}

type TableAssembly

type TableAssembly func(m *TuiModel, s *string, c *chan bool)

type TableState

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

TableState holds everything needed to save/serialize state

type TuiModel

type TuiModel struct {
	DefaultTable    TableState // all non-destructive changes are TableStates getting passed around
	DefaultData     UIData
	QueryResult     *TableState
	QueryData       *UIData
	Format          FormatState
	UI              UIState
	Scroll          ScrollData
	Ready           bool
	InitialFileName string // used if saving destructively
	Viewport        viewport.Model
	ClipboardList   list.Model
	Clipboard       []list.Item
	TableStyle      lipgloss.Style
	MouseData       tea.MouseEvent
	TextInput       LineEdit
	FormatInput     LineEdit
	UndoStack       []TableState
	RedoStack       []TableState
}

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) Data

func (m *TuiModel) Data() *UIData

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) GetSelectedLineEdit

func (m *TuiModel) GetSelectedLineEdit() *LineEdit

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) PopulateDataForResult

func (m *TuiModel) PopulateDataForResult(c *sql.Rows, indexMap *int, schemaName string)

func (*TuiModel) SetModel

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

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

func (*TuiModel) SetViewSlices

func (m *TuiModel) SetViewSlices()

func (*TuiModel) SwapTableValues

func (m *TuiModel) SwapTableValues(f, t *TableState)

func (*TuiModel) Table

func (m *TuiModel) Table() *TableState

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

func (*TuiModel) WriteMessage

func (m *TuiModel) WriteMessage(s string)

type UIData

type UIData struct {
	TableHeaders      map[string][]string // keeps track of which schema has which headers
	TableHeadersSlice []string
	TableSlices       map[string][]interface{}
	TableIndexMap     map[int]string // keeps the schemas in order
	EditTextBuffer    string
}

type UIState

type UIState struct {
	CanFormatScroll   bool
	RenderSelection   bool // render mode
	EditModeEnabled   bool // edit mode
	FormatModeEnabled bool
	BorderToggle      bool
	SQLEdit           bool
	ShowClipboard     bool
	ExpandColumn      int
	CurrentTable      int
}

Jump to

Keyboard shortcuts

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