component

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentComponent  = "Content"
	JsonViewComponent = "JsonView"
)
View Source
const (
	DatabaseTreeComponent manager.Component = "DatabaseTree"
	InputModalComponent   manager.Component = "InputModal"
	ConfirmModalComponent manager.Component = "ConfirmModal"
)
View Source
const (
	DatabasesComponent manager.Component = "Databases"
	FilterBarComponent manager.Component = "FilterBar"
)
View Source
const (
	ConnectorComponent = manager.Component("Connector")
)
View Source
const (
	DeleteModalComponent = "DeleteModal"
)
View Source
const (
	DocModifierComponent manager.Component = "DocModifier"
)
View Source
const (
	DocPeekerComponent manager.Component = "DocPeeker"
)
View Source
const (
	ErrorComponent = "Error"
)
View Source
const (
	HeaderComponent manager.Component = "Header"
)
View Source
const (
	HelpComponent manager.Component = "Help"
)
View Source
const (
	HistoryModalComponent manager.Component = "HistoryModal"
)
View Source
const (
	InputBarComponent = "InputBar"
)
View Source
const (
	RootComponent manager.Component = "Root"
)
View Source
const (
	WelcomeComponent = manager.Component("Welcome")
)

Variables

This section is empty.

Functions

func NewErrorModal

func NewErrorModal(message string, err error) *tview.Modal

func ShowErrorModal

func ShowErrorModal(page *Root, message string, err error)

ShowErrorModal shows a modal with an error message and logs the error if it's passed

func ShowErrorModalAndFocus

func ShowErrorModalAndFocus(page *Root, message string, err error, setFocus func())

Types

type App

type App struct {
	*tview.Application

	Dao            *mongo.Dao
	Manager        *manager.ComponentManager
	Root           *Root
	FullScreenHelp *Help
	FooterHelp     *Help
	Styles         *config.Styles
	Config         *config.Config
	Keys           *config.KeyBindings
}

App is a main application struct

func NewApp

func NewApp(appConfig *config.Config) App

func (*App) Init

func (a *App) Init() error

Init initializes app

type BaseInfo

type BaseInfo map[order]info

type Component

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

Component is a base struct for all components. It contains all the basic fields and functions that are used by all components. It also implements the Component interface.

func NewComponent

func NewComponent(identifier manager.Component) *Component

NewComponent is a constructor for the Component struct.

func (*Component) BroadcastEvent

func (c *Component) BroadcastEvent(event manager.EventMsg)

SendEvent sends an event to the app.

func (*Component) Disable

func (c *Component) Disable()

Disable unsets the enabled flag.

func (*Component) Enable

func (c *Component) Enable()

Enable sets the enabled flag.

func (*Component) GetComponent

func (c *Component) GetComponent() *Component

GetComponent returns the component.

func (*Component) GetIdentifier

func (c *Component) GetIdentifier() manager.Component

GetIdentifier returns the identifier of the component.

func (*Component) Init

func (c *Component) Init(app *App) error

Init is a function that is called when the component is initialized. If custom initialization is needed, this function should be overriden.

func (*Component) IsEnabled

func (c *Component) IsEnabled() bool

IsEnabled returns the enabled flag.

func (*Component) SendToComponent

func (c *Component) SendToComponent(component manager.Component, event manager.EventMsg)

SendToComponent sends an event to the component.

func (*Component) SetAfterInitFunc

func (c *Component) SetAfterInitFunc(afterInitFunc func() error)

SetAfterInitFunc sets the optional function that will be run at the end of the Init function.

func (*Component) Subscribe

func (c *Component) Subscribe()

Subscribe subscribes the component to the global events.

func (*Component) Toggle

func (c *Component) Toggle()

Toggle toggles the enabled flag.

type ComponentRenderer

type ComponentRenderer interface {
	// Render is a function that renders the component.
	Render() error

	// setStyle is a function that sets the style of the component.
	SetStyle(style string)
}

every component should implement this interface it's used for managing components in the app

type Connector

type Connector struct {
	*Component
	*tview.Flex
	// contains filtered or unexported fields
}

Connector is a view for connecting to mongodb using tview package

func NewConnector

func NewConnector() *Connector

NewConnector creates a new connection view

func (*Connector) Init

func (c *Connector) Init(app *App) error

Init overrides the Init function from the Component struct

func (*Connector) Render

func (c *Connector) Render()

Render renders the Component

func (*Connector) SetOnSubmitFunc

func (c *Connector) SetOnSubmitFunc(onSubmit func())

SetOnSubmitFunc sets callback function

type Content

type Content struct {
	*Component
	*tview.Flex

	Table *tview.Table
	View  *tview.TextView
	// contains filtered or unexported fields
}

Content is a component that displays documents in a table

func NewContent

func NewContent() *Content

NewContent creates a new Content component It also initializes all subcomponents

func (*Content) RenderContent

func (c *Content) RenderContent(ctx context.Context, db, coll string, filter map[string]interface{}) error

type DatabaseTree

type DatabaseTree struct {
	*Component
	*tview.TreeView

	NodeSelectFunc func(ctx context.Context, db string, coll string, filter map[string]interface{}) error
	// contains filtered or unexported fields
}

func NewDatabaseTree

func NewDatabaseTree() *DatabaseTree

func (*DatabaseTree) Render

func (t *DatabaseTree) Render(ctx context.Context, dbsWitColls []mongo.DBsWithCollections, expand bool)

type Databases

type Databases struct {
	*Component
	*tview.Flex
	// contains filtered or unexported fields
}

Databases is flex container for DatabaseTree and InputBar

func NewDatabases

func NewDatabases() *Databases

type DeleteModal

type DeleteModal struct {
	*Component
	*tview.Modal
	// contains filtered or unexported fields
}

func NewDeleteModal

func NewDeleteModal() *DeleteModal

type DocModifier

type DocModifier struct {
	*Component
}

DocModifier is a component that allows editing JSON documents

func NewDocModifier

func NewDocModifier() *DocModifier

func (*DocModifier) Duplicate

func (d *DocModifier) Duplicate(ctx context.Context, db, coll string, rawDocument string) (primitive.ObjectID, error)

Duplicate opens the editor with the document and saves it as a new document

func (*DocModifier) Edit

func (d *DocModifier) Edit(ctx context.Context, db, coll string, rawDocument string) (string, error)

Edit opens the editor with the document and saves it if it was changed

func (*DocModifier) Insert

func (d *DocModifier) Insert(ctx context.Context, db, coll string) (primitive.ObjectID, error)

type DocPeeker

type DocPeeker struct {
	*Component
	*primitives.ModalView
	// contains filtered or unexported fields
}

DocPeeker is a component that provides a modal view for peeking at a document

func NewDocPeeker

func NewDocPeeker() *DocPeeker

NewDocPeeker creates a new DocPeeker component

func (*DocPeeker) Peek

func (dc *DocPeeker) Peek(ctx context.Context, db, coll string, jsonString string) error
type Header struct {
	*Component
	*tview.Table
	// contains filtered or unexported fields
}

Header is a component that displays information about the database in the header of the application

func NewHeader

func NewHeader() *Header

NewHeader creates a new header component

type Help

type Help struct {
	*Component
	*tview.Table
	// contains filtered or unexported fields
}

Help is a component that provides a help screen for keybindings

func NewHelp

func NewHelp() *Help

NewHelp creates a new Help component

func (*Help) AddKeySection

func (h *Help) AddKeySection(name string, keys []config.Key, pos *int, col int)

func (*Help) Render

func (h *Help) Render() error

type HistoryModal

type HistoryModal struct {
	*Component
	*primitives.ListModal
	// contains filtered or unexported fields
}

HistoryModal is a modal with history of queries

func NewHistoryModal

func NewHistoryModal() *HistoryModal

func (*HistoryModal) GetText

func (h *HistoryModal) GetText() string

GetText returns text from selected item

func (*HistoryModal) Render

func (h *HistoryModal) Render() error

Render loads history from file and renders it

func (*HistoryModal) SaveToHistory

func (h *HistoryModal) SaveToHistory(text string) error

SaveToHistory saves text to history file, if it's not already there. It will overwrite oldest entry if history is full.

type InputBar

type InputBar struct {
	*Component
	*tview.InputField
	// contains filtered or unexported fields
}

func NewInputBar

func NewInputBar(label string) *InputBar

func (*InputBar) DoneFuncHandler

func (i *InputBar) DoneFuncHandler(accept func(string), reject func())

DoneFuncHandler sets DoneFunc for the input bar It accepts two functions: accept and reject which are called when user accepts or rejects the input

func (*InputBar) EnableAutocomplete

func (i *InputBar) EnableAutocomplete()

EnableAutocomplete enables autocomplete

func (*InputBar) EnableHistory

func (i *InputBar) EnableHistory()

EnableHistory enables history modal

func (*InputBar) LoadNewKeys

func (i *InputBar) LoadNewKeys(keys []string)

LoadNewKeys loads new keys for autocomplete It is used when switching databases or collections

func (*InputBar) SetDefaultText

func (i *InputBar) SetDefaultText(text string)

SetDefaultText sets default text for the input bar

func (*InputBar) Toggle

func (i *InputBar) Toggle()

Draws default text if input is empty

type Root

type Root struct {
	*Component
	*tview.Pages
	// contains filtered or unexported fields
}

Root is a component that manages visaibility of other components

func NewRoot

func NewRoot() *Root

func (*Root) AddPage

func (r *Root) AddPage(component manager.Component, page tview.Primitive, resize, visable bool) *tview.Pages

AddPage is a wrapper for tview.Pages.AddPage

func (*Root) HasPage added in v0.1.1

func (r *Root) HasPage(component manager.Component) bool

HasPage is a wrapper for tview.Pages.HasPage

func (*Root) Init

func (r *Root) Init() error

Init initializes root component and initializes all subcomponents asynchronically

func (*Root) RemovePage

func (r *Root) RemovePage(component manager.Component) *tview.Pages

RemovePage is a wrapper for tview.Pages.RemovePage

type Welcome

type Welcome struct {
	*Component
	*tview.Flex
	// contains filtered or unexported fields
}

func NewWelcome

func NewWelcome() *Welcome

func (*Welcome) Init

func (w *Welcome) Init(app *App) error

func (*Welcome) Render

func (w *Welcome) Render()

func (*Welcome) SetOnSubmitFunc

func (w *Welcome) SetOnSubmitFunc(onSubmit func())

Jump to

Keyboard shortcuts

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