utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package utils provides utility functions for pgcopy

Index

Constants

View Source
const (
	ColorReset   = "\033[0m"
	ColorRed     = "\033[31m"
	ColorGreen   = "\033[32m"
	ColorYellow  = "\033[33m"
	ColorBlue    = "\033[34m"
	ColorMagenta = "\033[35m"
	ColorCyan    = "\033[36m"
	ColorWhite   = "\033[37m"
	ColorBold    = "\033[1m"
	ColorDim     = "\033[2m"
)

ANSI color codes

Variables

This section is empty.

Functions

func Colorize

func Colorize(color, text string) string

Colorize adds color to text if output supports it

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration without decimal parts

func FormatLogDuration

func FormatLogDuration(d time.Duration) string

FormatLogDuration formats duration for log files with rounded values

func FormatLogLevel

func FormatLogLevel(level string) string

FormatLogLevel formats log levels with colors and icons

func FormatNumber

func FormatNumber(n int64) string

FormatNumber formats large numbers with K/M suffixes

func HighlightFKName

func HighlightFKName(fkName string) string

HighlightFKName highlights foreign key constraint names

func HighlightNumber

func HighlightNumber(number any) string

HighlightNumber highlights numbers in brackets and standalone numbers

func HighlightTableName

func HighlightTableName(schema, table string) string

HighlightTableName highlights table names in log messages

func IsColorSupported

func IsColorSupported() bool

IsColorSupported checks if the terminal supports colors

func MatchesAnyPattern

func MatchesAnyPattern(text string, patterns []string) bool

MatchesAnyPattern checks if a string matches any of the given patterns

func MatchesPattern

func MatchesPattern(text, pattern string) bool

MatchesPattern checks if a string matches a wildcard pattern Supports * wildcard for matching any sequence of characters

Types

type Logger

type Logger interface {
	Logf(format string, args ...interface{})
	LogSuccess(format string, args ...interface{})
	LogWarn(format string, args ...interface{})
	LogError(format string, args ...interface{})
	LogProgress(format string, args ...interface{})
}

Logger interface for colorized logging

type SimpleLogger

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

SimpleLogger provides basic logging functionality

func NewSilentLogger

func NewSilentLogger() *SimpleLogger

NewSilentLogger creates a new silent logger that suppresses all output

func NewSimpleLogger

func NewSimpleLogger(logger *log.Logger) *SimpleLogger

NewSimpleLogger creates a new simple logger

func (*SimpleLogger) LogError

func (l *SimpleLogger) LogError(format string, args ...interface{})

LogError logs an error message with red color and error icon

func (*SimpleLogger) LogProgress

func (l *SimpleLogger) LogProgress(format string, args ...interface{})

LogProgress logs a progress message with cyan color and progress icon

func (*SimpleLogger) LogSuccess

func (l *SimpleLogger) LogSuccess(format string, args ...interface{})

LogSuccess logs a success message with green color and checkmark

func (*SimpleLogger) LogWarn

func (l *SimpleLogger) LogWarn(format string, args ...interface{})

LogWarn logs a warning message with yellow color and warning icon

func (*SimpleLogger) Logf

func (l *SimpleLogger) Logf(format string, args ...interface{})

Logf logs a message using the custom logger when progress bar is active, or the standard logger otherwise

Jump to

Keyboard shortcuts

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