cute

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 3 Imported by: 5

README

Cute Print

A cute Go print package (fmt alternative), Minimalist, No dependencies!

Support me to be an independent open-source programmer 💟

ko-fi

Installation

go get github.com/zakaria-chahboun/cute

The idea is to simplify the printing of messages in the terminal, especially in error case. Letting you to put a title for your message in different colors.

Print line

cute.Println("Hi everyone", "My name is", "Zakaria!")
print line

As you see the default color for the title is bright yellow and for the message is bright purple.

Print muti-lines

cute.Printlns("Hi everyone", "My name is Zakaria!", "Zaki is my nick name.")
print multi-lines

Check errors

The cute.Check(..) is useful in case of errors, especially if you have a lot of functions in you code. It will help you to print a clear error code.

// equal to (if error != nil)
cute.Check("Error Title", errors.New("This is a cute panic!"))
check errors

Change colors

You can change the color:

  • ResetColor

  • DefaultColor

  • Black / BrightBlack

  • Red / BrightRed

  • Yellow / BrightYellow

  • Green / BrightGreen

  • Blue / BrightBlue

  • Purple / BrightPurple

  • Cyan / BrightCyan

  • White / BrightWhite

cute.SetTitleColor(cute.BrightBlue)
cute.SetMessageColor(cute.BrightGreen)
cute.Println("Hi everyone", "My name is Zakaria!")
colors

Printf

cute.Printf("Another title", "%s, a Country in North Africa.\n", "Morocco")
printf

List

You can print a list of lines dynamically! You can also specify the color for each line:

// juice recipe 🧃
list := cute.NewList(cute.BrightBlue, "Yummy Juice!")
list.Add(cute.BrightGreen, "1 avocado 🥑")
list.Add(cute.BrightRed, "4 strawberry 🍓")
list.Addf(cute.White, "%d ML %s", 500, "milk 🥛")
list.Print()
print list with colors

How you can use it with Scan?

This is a little example:

cute.Printf("How old are you?", "")

var age int
_, err := fmt.Scanln(&age)
cute.Check("Error scan", err)

cute.Println("Info", "Your age is:", age)
use cute with Scan

Unicode in title box

We supported also a lot of languages and emojis!

// arabic
Println("﴾ الله خالِقُ كُلِّ شيء ﴿")
// frensh
Println("délicieux pain français")
// spanish
Println("¡Hola! español")
// german
Println("ich möchte Kaffee")
// chinese (simplified)
Println("中国的长城")
// chinese (traditional)
Println("中國的長城")
// japanese (hiragana)
Println("進撃の巨人 すばらしい")
// russian
Println("русская литература")
// turkish
Println("türk şarküteri")
// korean
Println("한국라면 맛있다")
// hindi (devanagari)
Println("मसालों की भूमि")
// emoji
Println("✅  🚀")
// complex
Println("sweet | sucré | süß | 甜的 | 甘い | मीठा | حلو | 🍬")
support unicode

Real example

Tarjem is used our cute package, Here are some examples:

real example

Contribute 💟

Feel free to contribute or propose a feature or share your idea with us!


If you are using cute in your project please share that with us 😍 Twitter: @Zaki_Chahboun

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(title string, err error)

a cute panic like

func Printf

func Printf(title string, message string, params ...any)

Println

func Println

func Println(title string, messages ...any)

Println

func Printlns added in v1.0.5

func Printlns(title string, messages ...any)

Printlns multi-lines

func SetMessageColor

func SetMessageColor(c CuteColor)

Change the message color

func SetTitleColor

func SetTitleColor(c CuteColor)

Change the title color

Types

type CuteColor added in v1.0.2

type CuteColor string

new type : color

const (
	ResetColor   CuteColor = "\033[0m"
	DefaultColor CuteColor = "\033[39m"

	Black  CuteColor = "\033[30m"
	Red    CuteColor = "\033[31m"
	Green  CuteColor = "\033[32m"
	Yellow CuteColor = "\033[33m"
	Blue   CuteColor = "\033[34m"
	Purple CuteColor = "\033[35m"
	Cyan   CuteColor = "\033[36m"
	White  CuteColor = "\033[37m"

	BrightBlack  CuteColor = "\033[90m"
	BrightRed    CuteColor = "\033[91m"
	BrightGreen  CuteColor = "\033[92m"
	BrightYellow CuteColor = "\033[93m"
	BrightBlue   CuteColor = "\033[94m"
	BrightPurple CuteColor = "\033[95m"
	BrightCyan   CuteColor = "\033[96m"
	BrightWhite  CuteColor = "\033[97m"
)

list of available colors

type CuteLine added in v1.0.5

type CuteLine struct {
	Message      any
	MessageColor CuteColor
}

CluteLine (child of CuteList)

type CuteList added in v1.0.5

type CuteList struct {
	Title      string
	TitleColor CuteColor
	Lines      []CuteLine
}

CuteList (print lines dynamically)

func NewList added in v1.0.5

func NewList(color CuteColor, title string) *CuteList

constructor of list

func (*CuteList) Add added in v1.0.5

func (this *CuteList) Add(color CuteColor, message any)

add message to list

func (*CuteList) Addf added in v1.0.5

func (this *CuteList) Addf(color CuteColor, message string, params ...any)

addf message to list

func (*CuteList) Print added in v1.0.5

func (this *CuteList) Print()

print list

Jump to

Keyboard shortcuts

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