Documentation
¶
Overview ¶
Package utils provides utility functions for INIQ
Index ¶
- Constants
- func BackupFile(filePath string, backupEnabled bool) (string, error)
- func BoldText(text string) string
- func ColorText(text string, colorCode string) string
- func ErrorText(text string) string
- func InfoText(text string) string
- func IsTerminal(f *os.File) bool
- func ParseBoolValue(value string) (bool, error)
- func PromptThreeState(question string, featureName string, currentState bool) string
- func PromptWithDefault(question string, defaultValue string) string
- func PromptYesNo(question string, defaultValue bool) bool
- func PromptYesNoWithFeedback(question string, defaultValue bool, featureName string, currentState bool) bool
- func SuccessText(text string) string
- func WarningText(text string) string
- type StateToggleAction
- type StateToggleConfig
- type StateToggleResult
Constants ¶
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 ¶
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 IsTerminal ¶
IsTerminal checks if the given file is a terminal
func ParseBoolValue ¶ added in v0.2.2
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
PromptThreeState asks the user a three-state question: enable/disable/keep-current Returns "enable", "disable", or "keep"
func PromptWithDefault ¶
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 ¶
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 ¶
SuccessText returns the text in success color (green)
func WarningText ¶
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