common

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorDefault = "\x1b[39m"
	ColorRed     = "\x1b[91m"
	ColorGreen   = "\x1b[32m"
	ColorBlue    = "\x1b[94m"
	ColorYellow  = "\x1b[33m"
)

Variables

View Source
var CurrencySymbols = map[string]string{
	"GBP": "£",
	"INR": "₹",
	"USD": "$",
}

A map of currency names to symbols

View Source
var DbConn *sql.DB
View Source
var Locales = map[string]string{
	"GBP": "en-GB",
	"INR": "en-IN",
	"USD": "en-US",
}

A map of currencies to locales

Functions

func BackupDBFile added in v0.11.0

func BackupDBFile() error

BackupDBFile creates a backup of current db file in the same dataDir location

func CheckDBFile

func CheckDBFile() error

CheckDBFile checks if db_filename is present in the viper configuration file and that it exists in the filesystem, otherwise it returns an error

func CheckDataDir

func CheckDataDir() error

CheckDataDir checks if data_directory is present in the viper configuration file and that it exists in the filesystem, otherwise it returns an error

func CleanupDBBackupFiles added in v0.11.0

func CleanupDBBackupFiles() error

CleanupDBBackupFiles deletes DB backup files older than 5 days

func ColorizeBlue

func ColorizeBlue(s string) string

ColorizeBlue returns a given string that is formatted in blue color

func ColorizeGreen

func ColorizeGreen(s string) string

ColorizeGreen returns a given string that is formatted in green color

func ColorizeRed

func ColorizeRed(s string) string

ColorizeRed returns a given string that is formatted in red color

func ColorizeYellow

func ColorizeYellow(s string) string

ColorizeYellow returns a given string that is formatted in yellow color

func Completer

func Completer(options []string) func(d prompt.Document) []prompt.Suggest

Completer returns matched suggestions from the list of options as the input is typed

func CreateLedgerTables

func CreateLedgerTables(name string, currency string) error

CreateLedgerTables creates required tables for a ledger

It adds an entry in the ledgers table It creates the below tables with ledger name prefixed

for example if name = uk

  • uk_accounts
  • uk_categories
  • uk_transactions
  • uk_split_transactions

func FormatAccountsTableTitle added in v0.13.0

func FormatAccountsTableTitle(accountName string, currency string, balance float64) string

FormatAccountsTableTitle formats the title depending on the value of account balance

func GetCashioDBPath

func GetCashioDBPath() string

GetCashioDBPath reads viper config and returns the absolute path to the cashio sqlite database file as string

func GetCurrencyNames

func GetCurrencyNames() []string

GetCurrencyNames iterates through CurrencySymbols map and returns a slice of strings that contains the currency names

func GetDateFromUser

func GetDateFromUser() time.Time

GetDateFromUser prompts the user for date input.

Date can be entered either as YYYY-MM-DD (eg: 2023-08-21) or DD (eg: 21) If DD format is used, the date will default to the day in the current month and year

func InitializeCashio

func InitializeCashio() error

InitializeCashio creates ledgers table in the cashio sqlite database

func InitializeDBConnection added in v0.4.3

func InitializeDBConnection() error

func PadLeft

func PadLeft(text string, padCount int) string

PadLeft returns the text with padCount number of spaces prefixed to it

func PrecisionRoundAFloat added in v0.10.0

func PrecisionRoundAFloat(value float64, precision int) float64

PrecisionRoundAFloat returns the given float rounded to the precision number of places

func ProcessExpression added in v0.2.0

func ProcessExpression(input string) float64

ProcessExpression returns the value of an arithmetic expression

Example: input of "3+4" will return 7.00

func RestoreTermState

func RestoreTermState()

RestoreTermState restores a previously saved terminal state

func SaveTermState

func SaveTermState()

SaveTermState saves the current terminal state which can then be restored if needed

func SliceContains added in v0.10.0

func SliceContains(slice []string, item string) bool

SliceContains returns true if the slice contains given string otherwise false

Types

This section is empty.

Jump to

Keyboard shortcuts

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