output

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package output provides colored output utilities for command-line interface.

Package output provides colored output utilities for command-line interface.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Success = color.New(color.FgGreen).SprintFunc()
	Error   = color.New(color.FgRed).SprintFunc()
	Warning = color.New(color.FgYellow).SprintFunc()
	Info    = color.New(color.FgBlue).SprintFunc()
	Bold    = color.New(color.Bold).SprintFunc()
)

Color functions for different message types

Functions

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf prints an error message and exits with code 1.

func HandleError

func HandleError(err error) bool

HandleError is a convenience function to handle errors with output

func HandleFatalError

func HandleFatalError(err error)

HandleFatalError handles a fatal error and exits

func LogAndPrintError

func LogAndPrintError(log logger.Logger, err error, message string)

LogAndPrintError logs an error with context and outputs to user

func PrintError

func PrintError(err error)

PrintError prints an error to the user in appropriate format

Example
package main

import (
	"errors"

	ccmderrors "github.com/gifflet/ccmd/pkg/errors"
	"github.com/gifflet/ccmd/pkg/output"
)

func main() {
	// Printing errors with appropriate formatting
	err := errors.New("file not found")
	output.PrintError(err)

	// Using pkg/errors for better error handling
	err2 := ccmderrors.NotFound("command unknown-cmd")
	output.PrintError(err2)
}

func PrintErrorf

func PrintErrorf(format string, a ...interface{})

PrintErrorf prints a formatted error message.

func PrintInfof

func PrintInfof(format string, a ...interface{})

PrintInfof prints a formatted info message.

func PrintSuccessf

func PrintSuccessf(format string, a ...interface{})

PrintSuccessf prints a formatted success message.

func PrintWarningf

func PrintWarningf(format string, a ...interface{})

PrintWarningf prints a formatted warning message.

func Printf

func Printf(format string, a ...interface{})

Printf prints a formatted message.

Example
package main

import (
	"github.com/gifflet/ccmd/pkg/output"
)

func main() {
	// Basic output examples
	output.Printf("Regular message")
	output.PrintInfof("Information message")
	output.PrintSuccessf("Operation completed successfully")
	output.PrintWarningf("This is a warning")
	output.PrintErrorf("Something went wrong")
}

func Prompt

func Prompt(prompt string) string

Prompt asks the user for input with a colored prompt

Types

type ProgressBar

type ProgressBar struct {
	// contains filtered or unexported fields
}

ProgressBar provides a simple progress indicator

Example
package main

import (
	"time"

	"github.com/gifflet/ccmd/pkg/output"
)

func main() {
	// Using progress bar for measurable operations
	items := []string{"file1.txt", "file2.txt", "file3.txt"}
	progress := output.NewProgressBar(len(items), "Processing files")

	for _, item := range items {
		// Process item
		_ = item
		time.Sleep(500 * time.Millisecond)
		progress.Increment()
	}

	progress.Complete()
}

func NewProgressBar

func NewProgressBar(total int, message string) *ProgressBar

NewProgressBar creates a new progress bar

func (*ProgressBar) Complete

func (p *ProgressBar) Complete()

Complete marks the progress as complete

func (*ProgressBar) Increment

func (p *ProgressBar) Increment()

Increment increments the progress by 1

func (*ProgressBar) Update

func (p *ProgressBar) Update(current int)

Update updates the progress bar with the current value

type Spinner

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner provides a simple loading indicator

Example
package main

import (
	"time"

	"github.com/gifflet/ccmd/pkg/output"
)

func main() {
	// Using spinner for long operations
	spinner := output.NewSpinner("Processing files...")
	spinner.Start()

	// Simulate work
	time.Sleep(2 * time.Second)

	spinner.Success("Files processed successfully")

	// Or show error
	spinner2 := output.NewSpinner("Downloading...")
	spinner2.Start()
	time.Sleep(1 * time.Second)
	spinner2.Error("Download failed")
}

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message

func (*Spinner) Error

func (s *Spinner) Error(message string)

Error stops the spinner and shows an error message

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line

func (*Spinner) Success

func (s *Spinner) Success(message string)

Success stops the spinner and shows a success message

Jump to

Keyboard shortcuts

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