config

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigFile = "config.yaml"
	LogPath    = "/tmp/vi-mongo.log"
)

Variables

This section is empty.

Functions

func ExtractStyles

func ExtractStyles() error

func GetAllStyles

func GetAllStyles() ([]string, error)

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the path to the config file

func ParseMongoDBURI

func ParseMongoDBURI(uri string) (host, port, db string, err error)

func SymbolWithColor added in v0.1.4

func SymbolWithColor(symbol Style, color Style) string

Types

type AIQuery added in v0.1.11

type AIQuery struct {
	ExitAIQuery Key `json:"exitAIQuery"`
	ClearPrompt Key `json:"clearPrompt"`
}

type AIQueryStyle added in v0.1.12

type AIQueryStyle struct {
	FormLabelColor           Style `yaml:"formLabelColor"`
	FormInputBackgroundColor Style `yaml:"formInputBackgroundColor"`
	FormInputColor           Style `yaml:"formInputColor"`
}

Styles is a struct that contains all the styles for the application

type AutocompleteStyle

type AutocompleteStyle struct {
	BackgroundColor       Style `yaml:"backgroundColor"`
	TextColor             Style `yaml:"textColor"`
	ActiveBackgroundColor Style `yaml:"activeBackgroundColor"`
	ActiveTextColor       Style `yaml:"activeTextColor"`
	SecondaryTextColor    Style `yaml:"secondaryTextColor"`
}

Styles is a struct that contains all the styles for the application

type Config

type Config struct {
	Version            string        `yaml:"version"`
	Log                LogConfig     `yaml:"log"`
	Editor             EditorConfig  `yaml:"editor"`
	ShowConnectionPage bool          `yaml:"showConnectionPage"`
	ShowWelcomePage    bool          `yaml:"showWelcomePage"`
	CurrentConnection  string        `yaml:"currentConnection"`
	Connections        []MongoConfig `yaml:"connections"`
	Styles             StylesConfig  `yaml:"styles"`
}

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the config file If the file does not exist, it will be created with the default settings

func (*Config) AddConnection

func (c *Config) AddConnection(mongoConfig *MongoConfig) error

AddConnection adds a MongoDB connection to the config file

func (*Config) AddConnectionFromUri

func (c *Config) AddConnectionFromUri(mongoConfig *MongoConfig) error

AddConnectionFromUri adds a MongoDB connection to the config file using a URI

func (*Config) DeleteConnection

func (c *Config) DeleteConnection(name string) error

DeleteConnection deletes a config from the config file by name

func (*Config) GetCurrentConnection

func (c *Config) GetCurrentConnection() *MongoConfig

GetCurrentConnection gets the current connection from the config file

func (*Config) GetEditorCmd

func (c *Config) GetEditorCmd() (string, error)

GetEditorCmd returns the editor command from the config file

func (*Config) SetCurrentConnection

func (c *Config) SetCurrentConnection(name string) error

SetCurrentConnection sets the current connection in the config file

func (*Config) UpdateConfig

func (c *Config) UpdateConfig() error

UpdateConfig updates the config file with the new settings

type ConnectionFormKeys

type ConnectionFormKeys struct {
	SaveConnection Key `json:"saveConnection"`
	FocusList      Key `json:"focusList"`
}

type ConnectionKeys

type ConnectionKeys struct {
	ToggleFocus    Key                `json:"toggleFocus"`
	ConnectionForm ConnectionFormKeys `json:"connectionForm"`
	ConnectionList ConnectionListKeys `json:"connectionList"`
}

type ConnectionListKeys

type ConnectionListKeys struct {
	FocusForm        Key `json:"focusForm"`
	DeleteConnection Key `json:"deleteConnection"`
	SetConnection    Key `json:"setConnection"`
}

type ConnectionStyle

type ConnectionStyle struct {
	FormLabelColor               Style `yaml:"formLabelColor"`
	FormInputBackgroundColor     Style `yaml:"formInputBackgroundColor"`
	FormInputColor               Style `yaml:"formInputColor"`
	ListTextColor                Style `yaml:"listTextColor"`
	ListSelectedTextColor        Style `yaml:"listSelectedTextColor"`
	ListSelectedBackgroundColor  Style `yaml:"listSelectedBackgroundColor"`
	ListSecondaryTextColor       Style `yaml:"listSecondaryTextColor"`
	ListSecondaryBackgroundColor Style `yaml:"listSecondaryBackgroundColor"`
}

ConnectionStyle is a struct that contains all the styles for the connection

type ContentKeys

type ContentKeys struct {
	ChangeView         Key `json:"switchView"`
	PeekDocument       Key `json:"peekDocument"`
	FullPagePeek       Key `json:"fullPagePeek"`
	AddDocument        Key `json:"addDocument"`
	EditDocument       Key `json:"editDocument"`
	DuplicateDocument  Key `json:"duplicateDocument"`
	DeleteDocument     Key `json:"deleteDocument"`
	CopyHighlight      Key `json:"copyValue"`
	CopyDocument       Key `json:"copyDocument"`
	Refresh            Key `json:"refresh"`
	ToggleQueryBar     Key `json:"toggleQueryBar"`
	NextDocument       Key `json:"nextDocument"`
	PreviousDocument   Key `json:"previousDocument"`
	NextPage           Key `json:"nextPage"`
	PreviousPage       Key `json:"previousPage"`
	ToggleSortBar      Key `json:"toggleSortBar"`
	SortByColumn       Key `json:"sortByColumn"`
	HideColumn         Key `json:"hideColumn"`
	ResetHiddenColumns Key `json:"resetHiddenColumns"`
}

type ContentStyle

type ContentStyle struct {
	StatusTextColor          Style `yaml:"statusTextColor"`
	HeaderRowBackgroundColor Style `yaml:"headerRowColor"`
	ColumnKeyColor           Style `yaml:"columnKeyColor"`
	ColumnTypeColor          Style `yaml:"columnTypeColor"`
	CellTextColor            Style `yaml:"cellTextColor"`
	SelectedRowColor         Style `yaml:"selectedRowColor"`
}

ContentStyle is a struct that contains all the styles for the content

type DatabaseKeys

type DatabaseKeys struct {
	FilterBar        Key `json:"filterBar"`
	ExpandAll        Key `json:"expandAll"`
	CollapseAll      Key `json:"collapseAll"`
	AddCollection    Key `json:"addCollection"`
	DeleteCollection Key `json:"deleteCollection"`
	RenameCollection Key `json:"renameCollection"`
}

type DatabasesStyle

type DatabasesStyle struct {
	NodeTextColor    Style `yaml:"nodeTextColor"`
	LeafTextColor    Style `yaml:"leafTextColor"`
	NodeSymbolColor  Style `yaml:"nodeSymbolColor"`
	LeafSymbolColor  Style `yaml:"leafSymbolColor"`
	OpenNodeSymbol   Style `yaml:"openNodeSymbol"`
	ClosedNodeSymbol Style `yaml:"closedNodeSymbol"`
	LeafSymbol       Style `yaml:"leafSymbol"`
}

DatabasesStyle is a struct that contains all the styles for the databases

type DocPeekerStyle

type DocPeekerStyle struct {
	KeyColor       Style `yaml:"keyColor"`
	ValueColor     Style `yaml:"valueColor"`
	BracketColor   Style `yaml:"bracketColor"`
	HighlightColor Style `yaml:"highlightColor"`
}

DocPeekerStyle is a struct that contains all the styles for the json peeker

type EditorConfig

type EditorConfig struct {
	Command string `yaml:"command"`
	Env     string `yaml:"env"`
}

type GlobalKeys

type GlobalKeys struct {
	CloseApp             Key `json:"closeApp"`
	ToggleFullScreenHelp Key `json:"toggleFullScreenHelp"`
	OpenConnection       Key `json:"openConnection"`
	ShowStyleModal       Key `json:"showStyleModal"`
}

GlobalKeys is a struct that holds the global keybindings for the application, they can be triggered from any view as keys are passed from top to bottom

type GlobalStyles

type GlobalStyles struct {
	// tview package styles
	BackgroundColor             Style `yaml:"backgroundColor"`
	ContrastBackgroundColor     Style `yaml:"contrastBackgroundColor"`
	MoreContrastBackgroundColor Style `yaml:"moreContrastBackgroundColor"`
	TextColor                   Style `yaml:"textColor"`
	SecondaryTextColor          Style `yaml:"secondaryTextColor"`
	BorderColor                 Style `yaml:"borderColor"`
	FocusColor                  Style `yaml:"focusColor"`
	TitleColor                  Style `yaml:"titleColor"`
	GraphicsColor               Style `yaml:"graphicsColor"`
}

GlobalStyles is a struct that contains all the global styles for the application

type HeaderStyle

type HeaderStyle struct {
	KeyColor       Style `yaml:"keyColor"`
	ValueColor     Style `yaml:"valueColor"`
	ActiveSymbol   Style `yaml:"activeSymbol"`
	InactiveSymbol Style `yaml:"inactiveSymbol"`
}

HeaderStyle is a struct that contains all the styles for the header

type HelpKeys

type HelpKeys struct {
	Close Key `json:"close"`
}

type HelpStyle

type HelpStyle struct {
	HeaderColor      Style `yaml:"headerColor"`
	KeyColor         Style `yaml:"keyColor"`
	DescriptionColor Style `yaml:"descriptionColor"`
}

Styles is a struct that contains all the styles for the application

type HistoryKeys

type HistoryKeys struct {
	ClearHistory Key `json:"clearHistory"`
	AcceptEntry  Key `json:"acceptEntry"`
	CloseHistory Key `json:"closeHistory"`
}

type HistoryStyle

type HistoryStyle struct {
	TextColor               Style `yaml:"textColor"`
	SelectedTextColor       Style `yaml:"selectedTextColor"`
	SelectedBackgroundColor Style `yaml:"selectedBackgroundColor"`
}

Styles is a struct that contains all the styles for the application

type IndexKeys added in v0.1.9

type IndexKeys struct {
	ExitAddIndex Key `json:"exitModal"`
	AddIndex     Key `json:"addIndex"`
	DeleteIndex  Key `json:"deleteIndex"`
}

type InputBarStyle

type InputBarStyle struct {
	LabelColor   Style             `yaml:"labelColor"`
	InputColor   Style             `yaml:"inputColor"`
	Autocomplete AutocompleteStyle `yaml:"autocomplete"`
}

InputBarStyle is a struct that contains all the styles for the filter bar

type Key

type Key struct {
	Keys        []string `json:"keys,omitempty"`
	Runes       []string `json:"runes,omitempty"`
	Description string   `json:"description"`
}

Key is a lowest level of keybindings It holds the keys and runes that are used to trigger the action and a description of the action that will be displayed in the help

func (*Key) String

func (k *Key) String() string

type KeyBindings

type KeyBindings struct {
	Global     GlobalKeys     `json:"global"`
	Help       HelpKeys       `json:"help"`
	Welcome    WelcomeKeys    `json:"welcome"`
	Connection ConnectionKeys `json:"connection"`
	Main       MainKeys       `json:"main"`
	Database   DatabaseKeys   `json:"databases"`
	Content    ContentKeys    `json:"content"`
	Peeker     PeekerKeys     `json:"peeker"`
	QueryBar   QueryBar       `json:"queryBar"`
	SortBar    SortBar        `json:"sortBar"`
	Index      IndexKeys      `json:"index"`
	AIQuery    AIQuery        `json:"aiPrompt"`
	History    HistoryKeys    `json:"history"`
}

KeyBindings is a way to define keybindings for the application There are views that have only keybindings and some have nested keybindings of their children views

func LoadKeybindings

func LoadKeybindings() (*KeyBindings, error)

LoadKeybindings loads keybindings from the config file if the file does not exist it creates a new one with default keybindings

func (*KeyBindings) Contains

func (kb *KeyBindings) Contains(configKey Key, namedKey string) bool

Contains checks if the keybindings contains the key

func (*KeyBindings) ConvertStrKeyToTcellKey

func (kb *KeyBindings) ConvertStrKeyToTcellKey(key string) (tcell.Key, bool)

ConvertStrKeyToTcellKey converts string key to tcell key

func (KeyBindings) GetAvaliableKeys

func (kb KeyBindings) GetAvaliableKeys() []OrderedKeys

GetAvaliableKeys returns all keys

func (KeyBindings) GetKeysForElement

func (kb KeyBindings) GetKeysForElement(elementId string) ([]OrderedKeys, error)

GetKeysForElement returns keys for element

type LogConfig

type LogConfig struct {
	Path        string `yaml:"path"`
	Level       string `yaml:"level"`
	PrettyPrint bool   `yaml:"prettyPrint"`
}

type MainKeys

type MainKeys struct {
	FocusNext      Key `json:"focusNext"`
	FocusPrevious  Key `json:"focusPrevious"`
	HideDatabase   Key `json:"hideDatabases"`
	ShowAIQuery    Key `json:"showAIQuery"`
	ShowServerInfo Key `json:"showServerInfo"`
}

type MongoConfig

type MongoConfig struct {
	Uri      string       `yaml:"url"`
	Host     string       `yaml:"host"`
	Port     int          `yaml:"port"`
	Database string       `yaml:"database"`
	Username string       `yaml:"username"`
	Password string       `yaml:"password"`
	Name     string       `yaml:"name"`
	Timeout  int          `yaml:"timeout"`
	Options  MongoOptions `yaml:"options"`
}

func (*MongoConfig) GetOptions added in v0.1.18

func (c *MongoConfig) GetOptions() MongoOptions

GetOptions returns the options from the config file if they are not set, it returns the default values

func (*MongoConfig) GetSafeUri

func (m *MongoConfig) GetSafeUri() string

GetSafeUri returns the URI with the password replaced by asterisks

func (*MongoConfig) GetUri

func (m *MongoConfig) GetUri() string

GetUri returns the URI or builds it from the config

type MongoOptions added in v0.1.18

type MongoOptions struct {
	AuthorizedDatabases   *bool `yaml:"authorizedDatabases,omitempty"`
	AuthorizedCollections *bool `yaml:"authorizedCollections,omitempty"`
}

type OrderedKeys

type OrderedKeys struct {
	Element string
	Keys    []Key
}

type OthersStyle

type OthersStyle struct {
	// buttons
	ButtonsTextColor                    Style `yaml:"buttonsTextColor"`
	ButtonsBackgroundColor              Style `yaml:"buttonsBackgroundColor"`
	DeleteButtonSelectedBackgroundColor Style `yaml:"deleteButtonSelectedBackgroundColor"`
	// modals specials
	ModalTextColor          Style `yaml:"modalTextColor"`
	ModalSecondaryTextColor Style `yaml:"modalSecondaryTextColor"`
	// table separators
	SeparatorSymbol Style `yaml:"separatorSymbol"`
	SeparatorColor  Style `yaml:"separatorColor"`
}

OthersStyle is a struct that contains all the styles shared across components

type PeekerKeys

type PeekerKeys struct {
	MoveToTop        Key `json:"moveToTop"`
	MoveToBottom     Key `json:"moveToBottom"`
	CopyHighlight    Key `json:"copyHighlight"`
	CopyValue        Key `json:"copyValue"`
	ToggleFullScreen Key `json:"toggleFullScreen"`
	Exit             Key `json:"exit"`
}

type QueryBar

type QueryBar struct {
	ShowHistory Key `json:"showHistory"`
	ClearInput  Key `json:"clearInput"`
	Paste       Key `json:"paste"`
}

type SortBar

type SortBar struct {
	ClearInput Key `json:"clearInput"`
	Paste      Key `json:"paste"`
}

type Style

type Style string

Styles is a struct that contains all the styles for the application

func (*Style) Color

func (s *Style) Color() tcell.Color

Color returns the tcell.Color of the style

func (*Style) GetWithColor

func (s *Style) GetWithColor(color tcell.Color) string

SetColor sets the color of the style

func (*Style) Rune

func (s *Style) Rune() rune

Rune returns the rune value of the style

func (*Style) String

func (s *Style) String() string

String returns the string value of the style

type StyleChangeStyle

type StyleChangeStyle struct {
	TextColor               Style `yaml:"textColor"`
	SelectedTextColor       Style `yaml:"selectedTextColor"`
	SelectedBackgroundColor Style `yaml:"selectedBackgroundColor"`
}

Styles is a struct that contains all the styles for the application

type Styles

type Styles struct {
	Global      GlobalStyles     `yaml:"global"`
	Welcome     WelcomeStyle     `yaml:"welcome"`
	Connection  ConnectionStyle  `yaml:"connection"`
	Header      HeaderStyle      `yaml:"header"`
	TabBar      TabBarStyle      `yaml:"tabBar"`
	Databases   DatabasesStyle   `yaml:"databases"`
	Content     ContentStyle     `yaml:"content"`
	AIPrompt    AIQueryStyle     `yaml:"aiQuery"`
	DocPeeker   DocPeekerStyle   `yaml:"docPeeker"`
	InputBar    InputBarStyle    `yaml:"inputBar"`
	History     HistoryStyle     `yaml:"history"`
	Help        HelpStyle        `yaml:"help"`
	Others      OthersStyle      `yaml:"others"`
	StyleChange StyleChangeStyle `yaml:"styleChange"`
}

Styles is a struct that contains all the styles for the application

func LoadStyles

func LoadStyles(styleName string, useBetterSymbols bool) (*Styles, error)

LoadStyles creates a new Styles struct with default values

func (*Styles) LoadMainStyles

func (s *Styles) LoadMainStyles()

type StylesConfig added in v0.1.4

type StylesConfig struct {
	BetterSymbols bool   `yaml:"betterSymbols"`
	CurrentStyle  string `yaml:"currentStyle"`
}

type TabBarStyle added in v0.1.5

type TabBarStyle struct {
	ActiveTextColor       Style `yaml:"activeTextColor"`
	ActiveBackgroundColor Style `yaml:"activeBackgroundColor"`
}

TabBarStyle is a struct that contains all the styles for the tab bar

type WelcomeKeys

type WelcomeKeys struct {
	MoveFocusUp   Key `json:"moveFocusUp"`
	MoveFocusDown Key `json:"moveFocusDown"`
}

type WelcomeStyle

type WelcomeStyle struct {
	FormLabelColor           Style `yaml:"formLabelColor"`
	FormInputColor           Style `yaml:"formInputColor"`
	FormInputBackgroundColor Style `yaml:"formInputBackgroundColor"`
}

WelcomeStyle is a struct that contains all the styles for the welcome screen

Jump to

Keyboard shortcuts

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