msg

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: MIT Imports: 4 Imported by: 5

README

msg

License Go Reference Go Report Card GitHub CI codecov

🚀 A lightweight terminal printing toolkit for Go CLIs.

demo

Project Description

Who else is bored with boring grey text in CLIs? 🙋🏻‍♂️

We all have fancy terminals, utf-8 is everywhere, no one is still using the stock windows command prompt any more... are they? 🤨

msg is a tiny toolkit to make rendering beautiful looking output from CLIs as easy as possible in Go.

It's so easy, you already know how it works!

Installation

go get github.com/FollowTheProcess/msg@latest

Quickstart

The demo screenshot at the top of the page will get you:

output

Not bad! 🚀

User Guide

msg has 5 message types:

  • Title - Section header for a block of output
  • Info - General info, status updates etc.
  • Success - Your CLI has successfully done something
  • Warn - Warn the user about something e.g. ignoring hidden files
  • Error - Something has gone wrong in your application

All have a single trailing newline automatically applied except Title which has 1 leading and 2 trailing newlines to create separation.

msg.Error("My error message, underlying error: %v", err) // Newlines are handled for you

// i.e. you don't need to do this
msg.Error("My error message, underlying error: %v\n", err)

// Titles are effectively "\n{your title}\n\n"
msg.Title("My title") // Is enough to get separation in sections of output
Stdout/Stderr

By default, every function in msg prints to os.Stdout with the exception of msg.Error which prints to os.Stderr.

msg also exports "F-style" print functions which can write to any io.Writer e.g:

buf := &bytes.Buffer{} // is an io.Writer

msg.Ferror(buf, "My error message")
Credits

This package was created with copier and the FollowTheProcess/go_copier project template.

Documentation

Overview

Package msg is a simple, easy to use, opinionated console printing toolkit for Go CLIs rendering pretty formatted output with colours specific to the particular message type:

  • Info: For general user information and progress updates
  • Title: Separation between sections of output
  • Warn: User warnings
  • Success: Report success
  • Error: Report failure

All message types default to stdout other than the `Error` type which prints to stderr by default.

There are also "F-style" print methods that allow you to specify an io.Writer to print the messages to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error added in v0.6.0

func Error(format string, a ...any)

Error prints an error message with optional format args to stderr.

Example

msg.Error("Invalid config")
msg.Error("Could not find file: %s", "missing.txt")

func Ferror added in v0.6.0

func Ferror(w io.Writer, format string, a ...any)

Ferror prints an error message with optional format args to w.

Example

msg.Ferror(os.Stderr, "Uh oh! %s", "something wrong")

func Finfo added in v0.6.0

func Finfo(w io.Writer, format string, a ...any)

Finfo prints an info message with optional format args to w.

Example

msg.Finfo(os.Stdout, "The meaning of life is %v", 42)

func Fsuccess added in v0.6.0

func Fsuccess(w io.Writer, format string, a ...any)

Fsuccess prints a success message with optional format args to w.

Example

msg.Fsuccess(os.Stdout, "Compiled project: %s", "msg")

func Ftitle added in v0.6.0

func Ftitle(w io.Writer, format string, a ...any)

Ftitle prints a title message to w.

A title message differs from every other message type in msg as it has 1 leading newline and 2 trailing newlines to create separation between the sections it is differentiating in your CLI.

Example

msg.Ftitle(os.Stdout, "Some section")

func Fwarn added in v0.6.0

func Fwarn(w io.Writer, format string, a ...any)

Fwarn prints a warning message with optional format args to w.

Example

msg.Fwarn(os.Stderr, "hmmmm: %v", true)

func Info

func Info(format string, a ...any)

Info prints an info message with optional format args to stdout.

Example

msg.Info("You have %d repos on GitHub", 42)

func Success added in v0.6.0

func Success(format string, a ...any)

Success prints a success message with optional format args to stdout.

Example

msg.Success("Compiled project: %s", "msg")

func Title

func Title(format string, a ...any)

Title prints a title message to stdout.

A title message differs from every other message type in msg as it has 1 leading newline and 2 trailing newlines to create separation between the sections it is differentiating in your CLI.

Example

msg.Title("Some section")

func Warn

func Warn(format string, a ...any)

Warn prints a warning message with optional format args to stdout.

Example

msg.Warn("Skipping %s, directory is empty", "some/empty/dir")

Types

This section is empty.

Jump to

Keyboard shortcuts

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