formatters

package
v0.0.0-...-760d8ea Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: GPL-3.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

View Source
const EraseLineSequence = ansi.EraseEntireLine + "\r" + ansi.CursorUp1

Variables

This section is empty.

Functions

func NoEnumerator

func NoEnumerator(_ list.Items, _ int) string

NoEnumerator adds an option to not show any enumerator on a lipgloss list.

Types

type Formatter

type Formatter interface {
	// Log sends a content to the logger, with the specified log level.
	Log(content LogContent, level loggers.LogLevel)
}

Formatter will handle a LogContent message and dispatch it to the appropriate logger.

func NewConsoleFormatter

func NewConsoleFormatter(consoleLogger loggers.Console, static bool) Formatter

NewConsoleFormatter creates a new Formatter that will dispatch messages to a logger.Console.

If static is set to true, the formatter will ignore dynamic content.

func NewJSONFormatter

func NewJSONFormatter(jsonLogger loggers.JSON) Formatter

NewJSONFormatter creates a new Formatter that will dispatch messages to a logger.JSON.

type LogBase

type LogBase interface {
	LogContent
	// SetStyle sets the style of the message. The style is only rendered with logger.ConsoleLogger.
	SetStyle(style lipgloss.Style) LogBase
	// SetChild sets a child LogContent to the message.
	SetChild(child LogContent) LogBase
}

LogBase is a simple implementation of LogContent. It supports colored output using lipgloss.Style, and can contain a child LogContent.

func NewBase

func NewBase(content string) LogBase

NewBase creates a new LogBase instance.

type LogClear

type LogClear interface {
	LogContent
}

LogClear is a utility LogContent that clears the terminal screen on logger.ConsoleLogger instances. It does nothing on logger.JSONLogger instances.

func NewClear

func NewClear() LogClear

NewClear creates a new LogClear instance.

type LogContent

type LogContent interface {
	// RenderConsole returns a string representation of the log content, that can be printed in a logger.Console.
	RenderConsole() string
	// RenderJSON returns a serializable representation of the log content, that can be printed in a logger.JSON.
	RenderJSON() interface{}
}

LogContent represents a special value, that can automatically be rendered in both logger.Console and logger.JSON.

type LogDiscoverGRPC

type LogDiscoverGRPC interface {
	LogContent
}

func NewDiscoverGRPC

func NewDiscoverGRPC(services []grpc.ServiceDesc, port int) LogDiscoverGRPC

type LogDynamicContent

type LogDynamicContent interface {
	LogContent
	// RenderConsoleDynamic is a special method, that will be called periodically by the logger to update the content.
	// It is up to the dynamic implementation to keep an internal running state. This method will be called everytime
	// the message should be updated.
	//
	// This method must be ignored once StopRunning has been called.
	RenderConsoleDynamic(renderer func(msg string)) LogDynamicContent
	// StopRunning stops the dynamic render execution. After triggering it, every call to RenderConsoleDynamic must be
	// ignored.
	StopRunning() LogDynamicContent
}

LogDynamicContent allows to render real-time output when the logger supports it. It is currently only available for logger.Console.

type LogDynamicContentPure

type LogDynamicContentPure interface {
	// RenderConsoleDynamic implements LogDynamicContent.RenderConsoleDynamic interface.
	RenderConsoleDynamic(renderer func(msg string)) LogDynamicContent
	// StopRunning implements LogDynamicContent.StopRunning interface.
	StopRunning() LogDynamicContent
}

LogDynamicContentPure is a subset of LogDynamicContent implemented by the generic default implementation.

func NewAnimated

func NewAnimated(renderer LogDynamicContent, fps time.Duration, update func()) LogDynamicContentPure

NewAnimated creates a new LogDynamicContentPure instance, that allows to render animated content.

type LogError

type LogError interface {
	LogContent
}

LogError renders an error as a message.

func NewError

func NewError(err error, message string) LogError

NewError creates a new LogError instance.

type LogList

type LogList interface {
	LogContent
	// Append adds a new string to the list.
	Append(content string) LogList
	// Nest adds a new LogContent to the list.
	Nest(content LogContent) LogList

	// SetEnumerator sets the list enumerator.
	SetEnumerator(enumerator list.Enumerator) LogList
	// SetIndenter sets the list indenter.
	SetIndenter(indenter list.Indenter) LogList
	// SetStyle sets the style of the list.
	SetStyle(style lipgloss.Style) LogList
	// SetItemStyle sets the style of the list items.
	SetItemStyle(style lipgloss.Style) LogList
}

LogList is a utility LogContent that renders a list of LogContent instances.

func NewList

func NewList() LogList

NewList creates a new LogList instance.

type LogLoader

type LogLoader interface {
	LogDynamicContent
	// SetDescription updates the main message of the loader. Each change to this value triggers a new log, under
	// static environments.
	SetDescription(description string) LogLoader
	// SetCompleted marks the loader as completed. It triggers a new log under static environments. Under dynamic
	// environments, the loader is stopped.
	SetCompleted() LogLoader
	// SetChild sets a child LogContent to the loader. Each change to this value triggers a new log, under
	// static environments.
	SetChild(child LogContent) LogLoader
	// SetError marks the loader as errored. It triggers a new log under static environments. Under dynamic
	// environments, the loader is stopped.
	SetError() LogLoader
}

LogLoader renders a loader. Under dynamic environments, the loader is animated, as a single log. Otherwise, each update is rendered as a separate log.

func NewLoader

func NewLoader(description string, spinnerModel spinner.Spinner) LogLoader

NewLoader creates a new LogLoader instance.

type LogMigrationsList

type LogMigrationsList interface {
	LogContent
	SetLastAppliedGroup(groupID int64) LogMigrationsList
}

LogMigrationsList us used to log a list of postgres migrations, along with their statuses.

func NewMigrationsList

func NewMigrationsList(migrations migrate.MigrationSlice) LogMigrationsList

NewMigrationsList creates a new LogMigrationsList instance.

type LogPlaceholder

type LogPlaceholder interface {
	LogContent
}

LogPlaceholder renders a special message for indicating a no-op.

func NewPlaceholder

func NewPlaceholder(content string) LogPlaceholder

NewPlaceholder creates a new LogPlaceholder instance.

type LogSplit

type LogSplit interface {
	LogContent

	// SetConsoleMessage sets a message that will only be rendered if the logger implements loggers.Console.
	SetConsoleMessage(content string) LogSplit
	// SetJSONMessage sets a message that will only be rendered if the logger implements loggers.JSON.
	SetJSONMessage(content interface{}) LogSplit
	// SetConsoleContent sets a LogContent that will only be rendered if the logger implements loggers.Console.
	SetConsoleContent(content LogContent) LogSplit
	// SetJSONContent sets a LogContent that will only be rendered if the logger implements loggers.JSON.
	SetJSONContent(content LogContent) LogSplit
	// SetConsoleRenderer sets a render function that will only be triggered if the logger implements loggers.Console.
	SetConsoleRenderer(content func() string) LogSplit
	// SetJSONRenderer sets a render function that will only be triggered if the logger implements loggers.JSON.
	SetJSONRenderer(content func() interface{}) LogSplit
}

LogSplit allows to set specific logs format for console and JSON.

func NewSplit

func NewSplit() LogSplit

NewSplit creates a new LogSplit instance.

type LogTitle

type LogTitle interface {
	LogContent
	// SetDescription sets the description of the title, that appears under it (inside the title block).
	SetDescription(description string) LogTitle
	// SetChild sets the child of the title, that will be rendered as a section (under the title block).
	SetChild(child LogContent) LogTitle
}

LogTitle renders a title element.

func NewTitle

func NewTitle(title string) LogTitle

NewTitle creates a new LogTitle instance.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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