notify

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

pkg/ui/notify

This package provides notification utilities for KSail's CLI interface.

Purpose

Contains utilities for sending user notifications through the command-line interface. This package provides consistent messaging, status updates, and user feedback throughout KSail's CLI operations.

Features

  • Colored Output: Uses fatih/color for colored terminal output
  • Status Symbols: Provides consistent symbols for different message types:
    • - Success messages (SuccessSymbol)
    • - Error messages (ErrorSymbol)
    • - Warning messages (WarningSymbol)
    • - Activity messages (ActivitySymbol)
  • Consistent Messaging: Standardized format for CLI notifications
  • Writer Abstraction: Supports custom output writers for testing

Usage

import "github.com/devantler-tech/ksail-go/pkg/ui/notify"

// Send different types of notifications
notify.Success("Cluster created successfully")
notify.Error("Failed to create cluster")
notify.Warning("Cluster already exists")
notify.Activity("Creating cluster...")

This package ensures consistent and visually clear communication between KSail and users through the command-line interface, improving the overall user experience.


⬅️ Go Back

Documentation

Overview

Package notify provides utilities for sending notifications to the user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTiming

func FormatTiming(total, stage time.Duration, isMultiStage bool) string

FormatTiming formats timing durations into a display string using Go's Duration.String() method. Returns "[stage: X|total: Y]" for multi-stage commands when isMultiStage is true. Returns "[stage: X]" for single-stage commands. Uses Go's standard Duration.String() which provides appropriate precision automatically.

func WriteMessage

func WriteMessage(msg Message)

WriteMessage writes a formatted message based on the message configuration. It handles message styling, optional timing information, and proper output formatting.

Types

type Message

type Message struct {
	// Type determines the message styling (color, symbol).
	Type MessageType
	// Content is the main message text to display.
	Content string
	// Timer is optional. If provided, timing information will be appended to the message.
	Timer timer.Timer
	// MultiStage MUST be set to true for multi-stage timers (i.e., when the command advances through stages).
	// If false, the timing output will be rendered in single-stage form regardless of internal durations.
	MultiStage bool
	// Emoji is used only for TitleType messages to customize the title icon.
	Emoji string
	// Writer is the output destination. If nil, defaults to os.Stdout.
	Writer io.Writer
	// Args are format arguments for Content if it contains format specifiers.
	Args []any
}

Message represents a notification message to be displayed to the user.

type MessageType

type MessageType int

MessageType defines the type of notification message.

const (
	// ErrorType represents an error message (red, with ✗ symbol).
	ErrorType MessageType = iota
	// WarningType represents a warning message (yellow, with ⚠ symbol).
	WarningType
	// ActivityType represents an activity/progress message (default color, with ► symbol).
	ActivityType
	// GenerateType represents a file generation message (default color, with ✚ symbol).
	GenerateType
	// SuccessType represents a success message (green, with ✔ symbol).
	SuccessType
	// InfoType represents an informational message (blue, with ℹ symbol).
	InfoType
	// TitleType represents a title/header message (bold, with emoji (custom or default)).
	TitleType
)

Jump to

Keyboard shortcuts

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