π Console β
go
import (
"github.com/thuongtruong109/gouse"
"github.com/thuongtruong109/gouse/cookbook/console/choice"
"github.com/thuongtruong109/gouse/cookbook/console/countdown"
"github.com/thuongtruong109/gouse/cookbook/console/dir"
"github.com/thuongtruong109/gouse/cookbook/console/glamour"
"github.com/thuongtruong109/gouse/cookbook/console/inline"
"github.com/thuongtruong109/gouse/cookbook/console/list"
"github.com/thuongtruong109/gouse/cookbook/console/parallel"
"github.com/thuongtruong109/gouse/cookbook/console/progress"
"github.com/thuongtruong109/gouse/cookbook/console/realtime"
"github.com/thuongtruong109/gouse/cookbook/console/sequence"
"github.com/thuongtruong109/gouse/cookbook/console/spinner"
"github.com/thuongtruong109/gouse/cookbook/console/split"
"github.com/thuongtruong109/gouse/cookbook/console/stopwatch"
"github.com/thuongtruong109/gouse/cookbook/console/table"
)
1. Console cmd β
Description: Run a command in the console
Input params: (...command string)
go
func ConsoleCmd() {
gouse.Cmd("echo command is working")
// first param is default command, second param is windows command (default is empty)
gouse.Cmd("ls", "clear")
}
2. Console clear β
Description: Clear the console
go
func ConsoleClear() {
println("console will be cleared now")
gouse.Cls()
println("console cleared")
}
3. Console with color β
Description: Print with color in the console
Input params: (color string, text string)
go
func ConsoleWithColor() {
gouse.OutputColor(gouse.DEFAULT_CONSOLE, "this is default")
gouse.OutputColor(gouse.WHITE_CONSOLE, "this is white")
gouse.OutputColor(gouse.RED_CONSOLE, "this is red")
gouse.OutputColor(gouse.GREEN_CONSOLE, "this is green")
gouse.OutputColor(gouse.YELLOW_CONSOLE, "this is yellow")
gouse.OutputColor(gouse.BLUE_CONSOLE, "this is blue")
gouse.OutputColor(gouse.MAGENTA_CONSOLE, "this is magenta")
gouse.OutputColor(gouse.CYAN_CONSOLE, "this is cyan")
}
4. Console banner β
Description: Display a banner in the console
Input params: (font string, text string)
go
func ConsoleBanner() {
gouse.Banner(gouse.DOUBLE_ALPHA, "gouse - type double")
gouse.Banner(gouse.DOUBLE_ALPHA, "gouse - type single")
}
5. Console help β
Description: Display a help menu in the console
Input params: (name string, options []*gouse.IHelpOptions)
go
func ConsoleHelp() {
name := "myprogram"
options := []*gouse.IHelpOptions{
{
Opt: "name",
Desc: "Enter your name",
Val: "Example name",
Action: func(name string) {
println("Your name is: ", name)
},
},
{
Opt: "age",
Desc: "Enter your age",
Val: 18,
Action: func(age int) {
println("this is age: ", age)
},
},
{
Opt: "learning",
Desc: "Enter your confirm",
Val: true,
Action: func(confirm bool) {
println("this is your confirm", confirm)
},
},
}
gouse.Help(name, options)
// for _, option := range options {
// gouse.Printf("Option %s: %v\n", option.Opt, option.Val)
// }
}
6. Console select β
Description: Display a select menu in the console
go
func ConsoleSelect() {
optconsolens := []string{"a", "b", "c"}
selected, err := gouse.Select("Select an optconsolen:", optconsolens)
if err != nil {
panic(err)
}
gouse.Confirm("Are you sure?")
println("You selected: ", selected)
}
7. Console list β
go
func ConsoleList() {
title := "My Fave Things"
items := []list.Item{
{Label: "Raspberry Piβs", Desc: "I have βem all over my house"},
{Label: "Nutella", Desc: "It's good on toast"},
{Label: "Bitter melon", Desc: "It cools you down"},
{Label: "Nice socks", Desc: "And by that I mean socks without holes"},
{Label: "Eight hours of sleep", Desc: "I had this once"},
{Label: "Cats", Desc: "Usually"},
{Label: "Plantasia, the album", Desc: "My plants love it too"},
{Label: "Pour over coffee", Desc: "It takes forever to make though"},
{Label: "VR", Desc: "Virtual reality...what is there to say?"},
{Label: "Noguchi Lamps", Desc: "Such pleasing organic forms"},
{Label: "Linux", Desc: "Pretty much the best OS"},
{Label: "Business school", Desc: "Just kidding"},
{Label: "Pottery", Desc: "Wet clay is a great feeling"},
{Label: "Shampoo", Desc: "Nothing like clean hair"},
{Label: "Table tennis", Desc: "Itβs surprisingly exhausting"},
{Label: "Milk crates", Desc: "Great for packing in your extra stuff"},
{Label: "Afternoon tea", Desc: "Especially the tea sandwich part"},
{Label: "Stickers", Desc: "The thicker the vinyl the better"},
{Label: "20Β° Weather", Desc: "Celsius, not Fahrenheit"},
{Label: "Warm light", Desc: "Like around 2700 Kelvin"},
{Label: "The vernal equinox", Desc: "The autumnal equinox is pretty good too"},
{Label: "Gafferβs tape", Desc: "Basically sticky fabric"},
{Label: "Terrycloth", Desc: "In other words, towel fabric"},
}
list.Default(title, items)
}
8. Console progress β
go
func ConsoleProgress() {
// first param is fail message
// second param is done message
// third param is increment percent (default 0.25)
progress.Run("^_^ Oh no, something went wrong", "βοΈ Done!", 0.5)
}
9. Console realtime β
go
func ConsoleRealtime() {
realtime.Run()
}
10. Console choice β
go
func ConsoleChoice() {
question := "What's your favorite flavor?"
options := []string{"Taro", "Coffee", "Lychee"}
update := &choice.Model{}
choice.Run(question, options, update)
gouse.Printf("\n---\nYou chose %s!\n", update.Choice)
}
11. Console spinner β
go
func ConsoleSpinner() {
spinner.Run()
}
12. Console split β
go
func ConsoleSplit() {
split.Run()
}
13. Console stopwatch β
go
func ConsoleStopwatch() {
stopwatch.Run()
}
14. Console table β
go
func ConsoleTable() {
table.Run()
}
15. Console countdown β
go
func ConsoleCountdown() {
countdown.Run()
}
16. Console sequence β
go
func ConsoleSequence() {
sequence.Run()
}
17. Console inline β
go
func ConsoleInline() {
customMode := &inline.Mode{
AltscreenMode: " altscreen mode ", // string will be displayed when switch to altscreen mode
InlineMode: " inline mode ", // string will be displayed when switch to inline mode
Key: " ", // space key to switch mode
}
inline.Run(customMode)
}
18. Console parallel β
go
func ConsoleParallel() {
parallel.Run()
}
19. Console dir β
go
func ConsoleDir() {
dir.Run()
}
20. Console glamour β
go
func ConsoleGlamour() {
const content = `
# Todayβs Menu
## Appetizers
| Name | Price | Notes |
| --- | --- | --- |
| Tsukemono | $2 | Just an appetizer |
| Tomato Soup | $4 | Made with San Marzano tomatoes |
| Okonomiyaki | $4 | Takes a few minutes to make |
| Curry | $3 | We can add squash if youβd like |
## Seasonal Dishes
| Name | Price | Notes |
| --- | --- | --- |
| Steamed bitter melon | $2 | Not so bitter |
| Takoyaki | $3 | Fun to eat |
| Winter squash | $3 | Today it's pumpkin |
## Desserts
| Name | Price | Notes |
| --- | --- | --- |
| Dorayaki | $4 | Looks good on rabbits |
| Banana Split | $5 | A classic |
| Cream Puff | $3 | Pretty creamy! |
All our dishes are made in-house by Karen, our chef. Most of our ingredients
are from our garden or the fish market down the street.
Some famous people that have eaten here lately:
* [x] RenΓ© Redzepi
* [x] David Chang
* [ ] Jiro Ono (maybe some day)
Bon appΓ©tit!
`
glamour.Run(content)
}