cfmt

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

README

CFMT

A simple and modern colored formatting package for Go console output.

Features

  • Colored console output with ANSI escape codes
  • Support for different message types (Info, Success, Warning, Error)
  • Formatted string support (Printf-style)
  • Customizable output writer
  • Thread-safe operations

Installation

go get github.com/dracory/base/cfmt

Usage

package main

import "github.com/dracory/base/cfmt"

func main() {
    // Basic usage
    cfmt.Info("This is an info message")
    cfmt.Success("Operation completed successfully")
    cfmt.Warning("This is a warning message")
    cfmt.Error("An error occurred")

    // With newline
    cfmt.Infoln("This is an info message with newline")
    cfmt.Errorln("This is an error message with newline")

    // Formatted output
    cfmt.Infof("Hello, %s!", "World")
    cfmt.Errorf("Error: %s", "Something went wrong")

    // Custom output writer
    var buf bytes.Buffer
    cfmt.SetOutput(&buf)
    cfmt.Info("This will be written to the buffer")
}

Available Functions

Basic Print Functions
  • Print(color string, a ...interface{})
  • Println(color string, a ...interface{})
  • Printf(color string, format string, a ...interface{})
Info Functions (Blue)
  • Info(a ...interface{})
  • Infoln(a ...interface{})
  • Infof(format string, a ...interface{})
Success Functions (Green)
  • Success(a ...interface{})
  • Successln(a ...interface{})
  • Successf(format string, a ...interface{})
Warning Functions (Yellow)
  • Warning(a ...interface{})
  • Warningln(a ...interface{})
  • Warningf(format string, a ...interface{})
Error Functions (Red)
  • Error(a ...interface{})
  • Errorln(a ...interface{})
  • Errorf(format string, a ...interface{})
Configuration
  • SetOutput(w io.Writer)

Color Codes

The package provides the following color constants:

  • Reset
  • Bold
  • Red, Green, Yellow, Blue, Magenta, Cyan, White
  • BoldRed, BoldGreen, BoldYellow, BoldBlue

License

This package is part of the dracory/base project and is licensed under the same terms.

Documentation

Index

Constants

View Source
const (
	Reset      = "\033[0m"
	Bold       = "\033[1m"
	Red        = "\033[31m"
	Green      = "\033[32m"
	Yellow     = "\033[33m"
	Blue       = "\033[34m"
	Magenta    = "\033[35m"
	Cyan       = "\033[36m"
	White      = "\033[37m"
	BoldRed    = Bold + Red
	BoldGreen  = Bold + Green
	BoldYellow = Bold + Yellow
	BoldBlue   = Bold + Blue
)

Colors for terminal output

Variables

This section is empty.

Functions

func Error

func Error(a ...interface{})

Error prints error message in red

func Errorf

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

Errorf prints formatted error message in red

func Errorln

func Errorln(a ...interface{})

Errorln prints error message in red with a newline

func Info

func Info(a ...interface{})

Info prints information in blue

func Infof

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

Infof prints formatted information in blue

func Infoln

func Infoln(a ...interface{})

Infoln prints information in blue with a newline

func Print

func Print(color string, a ...interface{})

Print prints the arguments with the given color

func Printf

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

Printf prints a formatted string with the given color

func Println

func Println(color string, a ...interface{})

Println prints the arguments with the given color and adds a newline

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output writer for the package

func Success

func Success(a ...interface{})

Success prints success message in green

func Successf

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

Successf prints formatted success message in green

func Successln

func Successln(a ...interface{})

Successln prints success message in green with a newline

func Warning

func Warning(a ...interface{})

Warning prints warning message in yellow

func Warningf

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

Warningf prints formatted warning message in yellow

func Warningln

func Warningln(a ...interface{})

Warningln prints warning message in yellow with a newline

Types

This section is empty.

Jump to

Keyboard shortcuts

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