utils

package
v0.0.0-...-2eb1f2f Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultFlashDelay = 3 * time.Second
	Loader            = "loader"
)
View Source
const (
	ColorWhite  = tcell.ColorWhite
	ColorGray   = tcell.ColorGray
	ColorRed    = tcell.ColorRed
	ColorGreen  = tcell.ColorGreen
	ColorOrange = tcell.ColorOrange
)
View Source
const (
	ColorTOrange = "orange"
	ColorTWhite  = "white"
	ColorTBlue   = "blue"
	ColorTRed    = "red"
	ColorTGreen  = "green"
	ColorTad7c5a = "#ad7c5a"
	ColorT70d5bf = "#70d5bf"
)
View Source
const (
	DefaultDirMod  os.FileMode = 0755
	DefaultFileMod os.FileMode = 0600
)
View Source
const (
	Info    = "info"
	Warning = "warning"
	Error   = "error"
)

Variables

View Source
var (
	NtuiExitKey = NtuiKey{
		Key:            tcell.KeyCtrlC,
		KeyLabel:       "Ctrl + c",
		KeyDescription: "Control and c",
	}
	NtuiEnterKey = NtuiKey{
		Key:            tcell.KeyEnter,
		KeyLabel:       "enter",
		KeyDescription: "Enter Key",
	}
	NtuiEscKey = NtuiKey{
		Key:            tcell.KeyEsc,
		KeyLabel:       "Esc",
		KeyDescription: "Esc key",
	}
	NtuiTabKey = NtuiKey{
		Key:            tcell.KeyTAB,
		KeyLabel:       "Tab",
		KeyDescription: "Tab Key",
	}
	NtuiCtrlRKey = NtuiKey{
		Key:            tcell.KeyCtrlR,
		KeyLabel:       "Ctrl + r",
		KeyDescription: "Control and r",
	}
	NtuiCtrlVKey = NtuiKey{
		Key:            tcell.KeyCtrlV,
		KeyLabel:       "Ctrl + v",
		KeyDescription: "Control and v",
	}
	NtuiRuneKey = NtuiKey{
		Key:            tcell.KeyRune,
		KeyLabel:       "rune keys",
		KeyDescription: "Rune keys",
	}
	NtuiCtrlTKey = NtuiKey{
		Key:            tcell.KeyCtrlT,
		KeyLabel:       "ctrl + t",
		KeyDescription: "Control and T",
	}
	NtuiCtrlQKey = NtuiKey{
		Key:            tcell.KeyCtrlQ,
		KeyLabel:       "ctrl + q",
		KeyDescription: "Control and Q",
	}
	NtuiCtrlSKey = NtuiKey{
		Key:            tcell.KeyCtrlS,
		KeyLabel:       "ctrl + s",
		KeyDescription: "Control and S",
	}
	NtuiCtrlJKey = NtuiKey{
		Key:            tcell.KeyCtrlJ,
		KeyLabel:       "ctrl + j",
		KeyDescription: "Control and J",
	}
	NtuiCtrlDKey = NtuiKey{
		Key:            tcell.KeyCtrlD,
		KeyLabel:       "ctrl + d",
		KeyDescription: "Control and D",
	}
)
View Source
var AllListeners []*Listener
View Source
var NtuiKeyBindings = []NtuiKey{
	NtuiExitKey,
}

Functions

func ColorizeStatusCell

func ColorizeStatusCell(status string) (tcell.Color, string)

func DateTimeDiff

func DateTimeDiff(dateTime time.Time) string

func DateTimeToStr

func DateTimeToStr(dateTime time.Time) string

func DeactivateListeners

func DeactivateListeners()

func EnsureDirPath

func EnsureDirPath(path string, mod os.FileMode) error

func FormatMemoryUsage

func FormatMemoryUsage(value int) int

func GetID

func GetID(id string) string

func IntToStr

func IntToStr(value int) string

func IntToUint64

func IntToUint64(v int) uint64

func Log

func Log(kind, message string)

func NodeStatusCell

func NodeStatusCell(status string) (tcell.Color, string)

func SafeDeref

func SafeDeref[T any](p *T) T

func SetCellTextColor

func SetCellTextColor(text, color string) string

func SetLogLevels

func SetLogLevels()

func Split

func Split(str, sep string) []string

func StrToInt

func StrToInt(s string) int

func Stringify

func Stringify(st interface{}) string

func ToCapitalize

func ToCapitalize(str string) string

Types

type Alert

type Alert struct {
	Message   models.AlertMessage
	Duration  time.Duration
	AlertChan chan models.AlertMessage
}

func NewAlert

func NewAlert() *Alert

func (*Alert) Channel

func (a *Alert) Channel() models.AlertChan

func (*Alert) Error

func (a *Alert) Error(Msg string)

func (*Alert) Hide

func (a *Alert) Hide()

func (*Alert) Info

func (a *Alert) Info(Msg string)

func (*Alert) Loader

func (a *Alert) Loader(loading bool)

func (*Alert) SendMessage

func (a *Alert) SendMessage(Type, Msg string)

func (*Alert) Warning

func (a *Alert) Warning(Msg string)

type Listener

type Listener struct {
	Ticker      *time.Ticker
	StopChan    chan bool
	Function    func()
	RefreshRate time.Duration
}

func NewListener

func NewListener(rr int, fn func()) *Listener

func (*Listener) Listen

func (l *Listener) Listen()

func (*Listener) Stop

func (l *Listener) Stop()

type Logger

type Logger struct {
	LInfo    *log.Logger
	LWarning *log.Logger
	LError   *log.Logger
}

func NewLogger

func NewLogger(logLevel string, file *os.File) *Logger

func (*Logger) Error

func (l *Logger) Error(message string)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...any)

func (*Logger) Info

func (l *Logger) Info(message string)

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...any)

func (*Logger) Log

func (l *Logger) Log(kind, message string)

func (*Logger) Warn

func (l *Logger) Warn(message string)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...any)

func (*Logger) Warning

func (l *Logger) Warning(message string)

func (*Logger) Warningf

func (l *Logger) Warningf(format string, v ...any)

type NtuiKey

type NtuiKey struct {
	Key            tcell.Key
	KeyRune        rune
	KeyLabel       string
	KeyDescription string
}

Jump to

Keyboard shortcuts

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