utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package utils provides utility functions for INIQ

Index

Constants

View Source
const (
	// Basic colors
	ColorReset   = "\033[0m"
	ColorGray    = "\033[90m"
	ColorGreen   = "\033[32m"
	ColorYellow  = "\033[33m"
	ColorBlue    = "\033[34m"
	ColorRed     = "\033[31m"
	ColorCyan    = "\033[36m"
	ColorMagenta = "\033[35m"

	// Bright colors
	ColorBrightGreen  = "\033[92m"
	ColorBrightYellow = "\033[93m"
	ColorBrightBlue   = "\033[94m"
	ColorBrightRed    = "\033[91m"
	ColorBrightCyan   = "\033[96m"

	// Text styles
	ColorBold      = "\033[1m"
	ColorUnderline = "\033[4m"

	// Combined styles
	ColorHeaderBlue = "\033[1;34m" // Bold Blue
	ColorHeaderCyan = "\033[1;36m" // Bold Cyan
	ColorSuccess    = "\033[32m"   // Green
	ColorWarning    = "\033[33m"   // Yellow
	ColorError      = "\033[31m"   // Red
	ColorInfo       = "\033[34m"   // Blue
	ColorDebug      = "\033[36m"   // Cyan
	ColorListItem   = "\033[90m"   // Gray
)

Colors for terminal output

Variables

This section is empty.

Functions

func BackupFile

func BackupFile(filePath string, backupEnabled bool) (string, error)

BackupFile creates a backup of a file with a timestamp If the file doesn't exist, it returns nil without creating a backup Returns the path to the backup file if successful

func BoldText

func BoldText(text string) string

BoldText returns the text in bold

func ColorText

func ColorText(text string, colorCode string) string

ColorText wraps text with the specified color code and resets the color afterward

func ErrorText

func ErrorText(text string) string

ErrorText returns the text in error color (red)

func InfoText

func InfoText(text string) string

InfoText returns the text in info color (blue)

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal checks if the given file is a terminal

func ParseBoolValue added in v0.2.2

func ParseBoolValue(value string) (bool, error)

ParseBoolValue parses various boolean value formats Supports: yes|enable|true|1|y|t|on for true values

no|disable|false|0|n|f|off for false values

func PromptThreeState added in v0.2.2

func PromptThreeState(question string, featureName string, currentState bool) string

PromptThreeState asks the user a three-state question: enable/disable/keep-current Returns "enable", "disable", or "keep"

func PromptWithDefault

func PromptWithDefault(question string, defaultValue string) string

PromptWithDefault asks the user for input with a default value and returns the user's input or the default if the user just presses Enter.

func PromptYesNo

func PromptYesNo(question string, defaultValue bool) bool

PromptYesNo asks the user a yes/no question and returns true for yes, false for no. The defaultValue parameter determines the default answer if the user just presses Enter. Shows gray placeholder text for the default value that gets replaced when user types.

func PromptYesNoWithFeedback added in v0.2.2

func PromptYesNoWithFeedback(question string, defaultValue bool, featureName string, currentState bool) bool

PromptYesNoWithFeedback asks the user a yes/no question and provides feedback when using defaults featureName and currentState are used to provide meaningful feedback about the current setting

func SuccessText

func SuccessText(text string) string

SuccessText returns the text in success color (green)

func WarningText

func WarningText(text string) string

WarningText returns the text in warning color (yellow)

Types

type StateToggleAction added in v0.2.2

type StateToggleAction string

StateToggleAction represents the action to take for a state toggle

const (
	StateToggleKeep    StateToggleAction = "keep"
	StateToggleEnable  StateToggleAction = "enable"
	StateToggleDisable StateToggleAction = "disable"
)

type StateToggleConfig added in v0.2.2

type StateToggleConfig struct {
	// Feature name (e.g., "SSH root login", "SSH password authentication")
	FeatureName string
	// Current state (true = enabled, false = disabled)
	CurrentState bool
	// Custom prompt (optional)
	AllowPrompt string // Default: "Allow {FeatureName}?"
}

StateToggleConfig holds configuration for a state toggle prompt

type StateToggleResult added in v0.2.2

type StateToggleResult struct {
	Action    StateToggleAction
	HasChange bool
}

StateToggleResult holds the result of a state toggle interaction

func PromptStateToggle added in v0.2.2

func PromptStateToggle(config StateToggleConfig) StateToggleResult

PromptStateToggle provides a user-friendly state toggle interaction using "Allow" syntax Returns the action to take and whether there's a change from current state

Jump to

Keyboard shortcuts

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