plain

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

README

plain

A tiny, super fast logger for Go with a couple of handy input helpers.

Install
go get -u github.com/coalaura/plain
Quick start
import (
	"os"
	"github.com/coalaura/plain"
)

func main() {
	pl := plain.New(plain.WithDate(plain.RFC3339Local))

	pl.Debugln("Hello from Debug")
	pl.Println("Hello from Print")
	pl.Warnln("Hello from Warn")
	pl.Errorln("Hello from Error")

	input, err := pl.Read(os.Stdin, "Input: ", 64)
	pl.MustFail(err)

	pl.Printf("You entered '%s'\n", input)

	options := []string{"Red", "Green", "Blue", "Yellow"}

	idx, err := pl.Select("Select: ", options)
	pl.MustFail(err)

	pl.Printf("You selected '%s'\n", options[idx])
}

Documentation

Index

Constants

View Source
const (
	RFC3339Local = "2006-01-02T15:04:05"

	Reset = "\x1b[0m"
)
View Source
const (
	ModeNone = iota - 1
	ModeSome
	Mode8Bit
	ModeFull
)

Variables

This section is empty.

Functions

func AsStrings

func AsStrings[T any](input []T) []string

AsStrings converts a slice/array of any type to a slice of strings

func WithDate

func WithDate(format string) option

func WithTarget

func WithTarget(out io.Writer) option

Types

type Plain

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

func New

func New(opts ...option) *Plain

func (*Plain) Close

func (p *Plain) Close() error

func (*Plain) Confirm

func (p *Plain) Confirm(prompt string, defaultYes bool) (bool, error)

Confirm displays a prompt aligned with the logger's format and reads y/n confirmation from stdin.

func (*Plain) Debug

func (p *Plain) Debug(a ...any)

Debug formats using the default formats for its operands and writes to the target output as a debug log.

func (*Plain) Debugf

func (p *Plain) Debugf(format string, a ...any)

Debugf formats according to a format specifier and writes to the target output as a debug log.

func (*Plain) Debugln

func (p *Plain) Debugln(a ...any)

Debugln formats using the default formats for its operands and writes to the target output as a debug log with a trailing newline.

func (*Plain) Error

func (p *Plain) Error(a ...any)

Error formats using the default formats for its operands and writes to the target output as an error.

func (*Plain) Errorf

func (p *Plain) Errorf(format string, a ...any)

Errorf formats according to a format specifier and writes to the target output as an error.

func (*Plain) Errorln

func (p *Plain) Errorln(a ...any)

Errorln formats using the default formats for its operands and writes to the target output as an error with a trailing newline.

func (*Plain) HandleInterrupt added in v1.1.4

func (p *Plain) HandleInterrupt(fn ...func())

func (*Plain) LogRequest

func (p *Plain) LogRequest(request *http.Request, metrics *httpsnoop.Metrics)

func (*Plain) Middleware

func (p *Plain) Middleware() func(http.Handler) http.Handler

func (*Plain) MustFail

func (p *Plain) MustFail(err error)

MustFail logs the error and exits with code 1 if the error is not nil.

func (*Plain) Print

func (p *Plain) Print(a ...any)

Print formats using the default formats for its operands and writes to the target output.

func (*Plain) Printf

func (p *Plain) Printf(format string, a ...any)

Printf formats according to a format specifier and writes to the target output.

func (*Plain) Println

func (p *Plain) Println(a ...any)

Println formats using the default formats for its operands and writes to the target output with a trailing newline.

func (*Plain) Read

func (p *Plain) Read(prompt string, max int) (string, error)

Read displays a prompt aligned with the logger's format and reads max bytes from stdin.

func (*Plain) ReadOne

func (p *Plain) ReadOne(prompt string) (rune, error)

ReadOne displays a prompt aligned with the logger's format and reads 1 byte from stdin.

func (*Plain) Select

func (p *Plain) Select(prompt string, options []string) (int, error)

Select displays a cyclic selector aligned with the logger's format.

func (*Plain) Warn

func (p *Plain) Warn(a ...any)

Warn formats using the default formats for its operands and writes to the target output as a warning.

func (*Plain) Warnf

func (p *Plain) Warnf(format string, a ...any)

Warnf formats according to a format specifier and writes to the target output as a warning.

func (*Plain) Warnln

func (p *Plain) Warnln(a ...any)

Warnln formats using the default formats for its operands and writes to the target output as a warning with a trailing newline.

func (*Plain) Write

func (p *Plain) Write(code, msg string, reset, nl bool)

type Theme

type Theme struct {
	Success   string
	Highlight string
	Input     string

	Dimmed string
	Warn   string
	Error  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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