hobocode

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 7 Imported by: 2

README

Hobocode

Hobocode is a pty-aware colorized printing library intended for use in CLI applications for human consumption and UX rather than structured outputs.

Uses go-pretty v6 for colors and Sprinting.

	hobocode.Header("Hobocode Example")
	hobocode.Success("Welcome to hobocode")

hobocode_example

The underlying functions can be used if you are working with custom *os.File's or you can use the lazy opinionated helpers like

Plain

hobocode.Warn("Something might be going wrong")

Formatted

hobocode.Debugf("Output: %v", ret.Body())

Indented

hobocode.Ierror(2, "Something went terribly wrong")

Indented and Formatted

hobocode.Iinfof(1, "Date: %s", time.Now().Format("2006/01/02"))

Example

See examples

import (
    "github.com/asciifaceman/hobocode"
)

func main() {
    userinput := hobocode.Input("nvim", "What is your preferred editor?")

    hobocode.Notef("You chose: %s", userinput)
}

example

Documentation

Overview

package hobocode provides some lazy convenience functions for wrapping text in colors, detecting tty, terminal size, and colored/formatted interactive inputs

The coloring choices are opinionated and the "levels" are based on common logging patterns but with a focus on Console UX vs. logging style

Note: Most of the printers in this library automatically new-line fields with Println variants

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Colorable

func Colorable(pipe *os.File) bool

Colorable reports if the given *os.File is a terminal or not (os.Stdout, os.Stderr)

func Confirm

func Confirm(message string) bool

Confirm is a naive confirmation prompt in HiRed that won't break until an explicit answer is given

func Confirmf

func Confirmf(format string, a ...interface{}) bool

Confirmf is a naive confirmation prompt in HiRed that won't break until an affirmative answer is given (with a formatted message)

func Debug

func Debug(message string)

Debug prints the given message with bright green if Colorable

Stdout

func Debugf

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

Debugf prints the given formatted message with bright green if Colorable

Stdout

func Error

func Error(message string)

Error prints the given message with bright red if Colorable

Stderr

func Errorf

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

Errorf prints the given formatted message with bright red if Colorable

Stderr

func Ficolor added in v0.2.0

func Ficolor(indent int, fd *os.File, color text.Color, format string, a ...interface{})

Ficolor prints the given string at the given indent to the given os.File with the given text.Color, if colorable and does not newline

func Ficolorf added in v0.2.0

func Ficolorf(indent int, fd *os.File, color text.Color, format string, a ...interface{})

Ficolorf prints the given format at the given indent to the given os.File with the given text.Color, if colorable and does not newline

func Header(title string)

Header prints a header title wrapped by "=" characters sized to the terminal width

Stdout

func HeaderLeft

func HeaderLeft(title string)

HeaderLeft prints a header title offset to the left wrapped by "=" characters sized to the terminal width

Stdout

func Icolor

func Icolor(indent int, fd *os.File, color text.Color, message string)

Icolor prints the given string at the given indent to the given os.File with the given text.Color, if colorable with newline

func Icolorf

func Icolorf(indent int, fd *os.File, color text.Color, format string, a ...interface{})

Icolorf prints the given format at the given indent to the given os.File with the given text.Color, if colorable with newline

func Idebug

func Idebug(indent int, message string)

Idebug prints the given message with bright green if Colorable with an indent

Stdout

func Idebugf

func Idebugf(indent int, format string, a ...interface{})

Idebugf prints the given formatted message with bright green if Colorable with an indent

Stdout

func Ierror

func Ierror(indent int, message string)

Ierror prints the given message with bright red if Colorable and an indent

Stderr

func Ierrorf

func Ierrorf(indent int, format string, a ...interface{})

Ierrorf prints the given formatted message with bright red if Colorable and an indent

Stderr

func Iinfo

func Iinfo(indent int, message string)

Iinfo prints the given message with bright cyan if Colorable and an indent

Stdout

func Iinfof

func Iinfof(indent int, format string, a ...interface{})

Iinfof prints the given formatted message with bright cyan if Colorable and an indent

Stdout

func Info

func Info(message string)

Info prints the given message with bright cyan if Colorable

Stdout

func Infof

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

Infof prints the given formatted message with bright cyan if colorable

Stdout

func Input

func Input(message string) string

Input acquires user CLI input

func Inputd added in v0.2.0

func Inputd(defaultOption string, message string) string

Inputd acquires user CLI input with a default defaultOption is presented as the default and used on nil entry

func Inputf

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

Inputf acquires user CLI input using a formatted message defaultOption is presented as the default and used on nil entry

func Isuccess

func Isuccess(indent int, message string)

Isuccess prints the given message with bright green if Colorable with an indent

Stdout

func Isuccessf

func Isuccessf(indent int, format string, a ...interface{})

Isuccessf prints the given formatted message with bright green if Colorable with an indent

Stdout

func Iwarn

func Iwarn(indent int, message string)

Iwarn prints the given message with bright yellow if Colorable and an indent

Stderr

func Iwarnf

func Iwarnf(indent int, format string, a ...interface{})

Iwarnf prints the given formatted message with bright yellow if Colorable and an indent

Stderr

func Selection added in v0.2.0

func Selection(options []string, message string, prompt string) int

Select allows the user to select from a list of options the index of the options is used as the selection and the user selection is returned as that int a response of -1 indicates a failure to capture input message introduces the list selection prompt is the input line

func Selectionr added in v0.2.0

func Selectionr(options []string, recommendedOption int, message string, prompt string) int

Selectr allows the user to select from a list of options with a recommended option the index of the options is used as the selection and the user selection is returned as that int a response of -1 indicates a failure to capture input message introduces the list selection prompt is the input line

func Size

func Size(pipe *os.File) (int, int, error)

Size returns the terminal size or error

func Std added in v0.2.0

func Std(fd *os.File, message string)

Std prints without newline to *os.FIle

func Stderr added in v0.2.0

func Stderr(message string)

Stderr prints without newline to os.Stdout

func Stderrln

func Stderrln(message string)

Stderrln prints with newline to os.Stderr

func Stdlin

func Stdlin(fd *os.File, message string)

Stdlin prints with newline to *os.File the given message

func Stdout added in v0.2.0

func Stdout(message string)

Stdout prints without newline to os.Stdout

func Stdoutln

func Stdoutln(message string)

Stdoutln prints with newline to os.Stdout

func Success

func Success(message string)

Success prints the given message with bright green if Colorable

Stdout

func Successf

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

Successf prints the given formatted message with bright green if Colorable

Stdout

func Tindent

func Tindent(n int) string

Tindent returns a tabbed indent repeated n times

func Warn

func Warn(message string)

Warn prints the given message with bright yellow if Colorable

Stderr

func Warnf

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

Warnf prints the given formatted message with bright yellow if Colorable

Stderr

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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