prints

package
v2.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 6 Imported by: 0

README

Prints

Usage

package main

import (
	"fmt"
	"time"

	"github.com/go-kratos-ecosystem/components/v2/prints"
)

func main() {
	// basic
	fmt.Println("Hello World!", "Hello Go!")
	prints.Line("Line: Hello World!", "Hello Go!")              
	prints.Linef("Linef: %s %s\n", "Hello World!", "Hello Go!") 
	prints.NewLine()                                            
	println("----------------------------------------")
	prints.NewLine(0) 
	println("----------------------------------------")
	prints.NewLine(1) 
	println("----------------------------------------")
	prints.NewLine(2) 
	println("----------------------------------------")
	prints.NewLine(3)                                                 
	prints.Info("Info: Hello World!", "Hello Go!")                    
	prints.Infof("Infof: %s %s\n", "Hello World!", "Hello Go!")       
	prints.Comment("Comment: Hello World!", "Hello Go!")              
	prints.Commentf("Commentf: %s %s\n", "Hello World!", "Hello Go!") 
	prints.Error("Error: Hello World!", "Hello Go!")                  
	prints.Errorf("Errorf: %s %s\n", "Hello World!", "Hello Go!")     
	prints.Warn("Warn: Hello World!", "Hello Go!")                    
	prints.Warnf("Warnf: %s %s\n", "Hello World!", "Hello Go!")       
	prints.Alert("Alert: Hello World!", "Hello Go!")                  
	prints.Alertf("Alertf: %s %s\n", "Hello World!", "Hello Go!")     

	// prompt
	r1, _ := prints.Ask("What is your name?", "FLC") 
	if r1 == "FLC" {
		prints.Warn("You are FLC!") 
	} else {
		prints.Infof("You are %s!\n", r1) 
	}
	r2, _ := prints.Ask("What is your name?") 
	prints.Info(r2)

	// secret
	r3, _ := prints.Secret("What is your password?", "123456")
	prints.Info("The password is " + r3)

	// progress bar
	bar := prints.NewProgressBar(100, prints.WithTemplate(prints.Full))
	for i := 1; i <= 100; i++ {
		time.Sleep(time.Millisecond * 100)
		bar.Increment()
	}

	bar.Finish()
}

Output:

Thanks

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Full    = pb.Full
	Default = pb.Default
	Simple  = pb.Simple

	FullTemplate    = WithTemplate(Full)
	DefaultTemplate = WithTemplate(Default)
	SimpleTemplate  = WithTemplate(Simple)
)

Functions

func Alert

func Alert(a ...interface{}) (int, error)

func Alertf

func Alertf(format string, a ...interface{}) (int, error)

func Ask

func Ask(question string, defaults ...string) (string, error)

func Comment

func Comment(a ...interface{}) (int, error)

func Commentf

func Commentf(format string, a ...interface{}) (int, error)

func Error

func Error(a ...interface{}) (int, error)

func Errorf

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

func Info

func Info(a ...interface{}) (int, error)

func Infof

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

func Line

func Line(a ...interface{}) (int, error)

func Linef

func Linef(format string, a ...interface{}) (int, error)

func NewLine

func NewLine(length ...int) (int, error)

func Secret added in v2.6.0

func Secret(question string, defaults ...string) (string, error)

func Success

func Success(a ...interface{}) (int, error)

func Successf

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

func Warn

func Warn(a ...interface{}) (int, error)

func Warnf

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

func WithProgressBar added in v2.5.0

func WithProgressBar(total int, fc func(bar *ProgressBar), opts ...ProgressBarOption)

Types

type ProgressBar

type ProgressBar struct {
	*pb.ProgressBar
	// contains filtered or unexported fields
}

func NewProgressBar

func NewProgressBar(total int, opts ...ProgressBarOption) *ProgressBar

type ProgressBarOption

type ProgressBarOption func(*ProgressBar)

func WithTemplate

func WithTemplate(template pb.ProgressBarTemplate) ProgressBarOption

type Prompt

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

func NewPrompt

func NewPrompt(question string, opts ...PromptOption) *Prompt

func (*Prompt) Ask

func (p *Prompt) Ask() (string, error)

type PromptOption

type PromptOption func(*Prompt)

func WithDefaultAnswer

func WithDefaultAnswer(defaultAnswer string) PromptOption

func WithSecret

func WithSecret() PromptOption

func WithTrimSpace added in v2.6.0

func WithTrimSpace(flag bool) PromptOption

Jump to

Keyboard shortcuts

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