diff --git a/README.md b/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/_examples/README.md b/_examples/README.md new file mode 100644 index 000000000..7d0ea6060 --- /dev/null +++ b/_examples/README.md @@ -0,0 +1,4 @@ +# PTerm Examples + +> This directory contains examples of using the PTerm library. + diff --git a/_examples/print-basic-text/README.md b/_examples/basictext/demo/README.md similarity index 97% rename from _examples/print-basic-text/README.md rename to _examples/basictext/demo/README.md index 8ca5fbf55..ce498440a 100644 --- a/_examples/print-basic-text/README.md +++ b/_examples/basictext/demo/README.md @@ -1,20 +1,20 @@ -# print-basic-text - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // A BasicText printer is used to print text, without special formatting. - // As it implements the TextPrinter interface, you can use it in combination with other printers. - pterm.DefaultBasicText.Println("Default basic text printer.") - pterm.DefaultBasicText.Println("Can be used in any" + pterm.LightMagenta(" TextPrinter ") + "context.") - pterm.DefaultBasicText.Println("For example to resolve progressbars and spinners.") - // If you just want to print text, you should use this instead: - // pterm.Println("Hello, World!") -} - -``` +# print-basic-text + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // A BasicText printer is used to print text, without special formatting. + // As it implements the TextPrinter interface, you can use it in combination with other printers. + pterm.DefaultBasicText.Println("Default basic text printer.") + pterm.DefaultBasicText.Println("Can be used in any" + pterm.LightMagenta(" TextPrinter ") + "context.") + pterm.DefaultBasicText.Println("For example to resolve progressbars and spinners.") + // If you just want to print text, you should use this instead: + // pterm.Println("Hello, World!") +} + +``` diff --git a/_examples/print-basic-text/animation.svg b/_examples/basictext/demo/animation.svg similarity index 100% rename from _examples/print-basic-text/animation.svg rename to _examples/basictext/demo/animation.svg diff --git a/_examples/print-basic-text/main.go b/_examples/basictext/demo/main.go similarity index 100% rename from _examples/print-basic-text/main.go rename to _examples/basictext/demo/main.go diff --git a/_examples/bulletlist-custom/README.md b/_examples/bulletlist/customized/README.md similarity index 96% rename from _examples/bulletlist-custom/README.md rename to _examples/bulletlist/customized/README.md index 1a1d854a7..9b9b6c5c4 100644 --- a/_examples/bulletlist-custom/README.md +++ b/_examples/bulletlist/customized/README.md @@ -1,21 +1,21 @@ -# bulletlist-custom - -![Animation](animation.svg) - -```go -package main - -import ( - "github.com/pterm/pterm" -) - -func main() { - // Print a customized list with different styles and levels. - pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{ - {Level: 0, Text: "Blue", TextStyle: pterm.NewStyle(pterm.FgBlue), BulletStyle: pterm.NewStyle(pterm.FgRed)}, - {Level: 1, Text: "Green", TextStyle: pterm.NewStyle(pterm.FgGreen), Bullet: "-", BulletStyle: pterm.NewStyle(pterm.FgLightWhite)}, - {Level: 2, Text: "Cyan", TextStyle: pterm.NewStyle(pterm.FgCyan), Bullet: ">", BulletStyle: pterm.NewStyle(pterm.FgYellow)}, - }).Render() -} - -``` +# bulletlist-custom + +![Animation](animation.svg) + +```go +package main + +import ( + "github.com/pterm/pterm" +) + +func main() { + // Print a customized list with different styles and levels. + pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{ + {Level: 0, Text: "Blue", TextStyle: pterm.NewStyle(pterm.FgBlue), BulletStyle: pterm.NewStyle(pterm.FgRed)}, + {Level: 1, Text: "Green", TextStyle: pterm.NewStyle(pterm.FgGreen), Bullet: "-", BulletStyle: pterm.NewStyle(pterm.FgLightWhite)}, + {Level: 2, Text: "Cyan", TextStyle: pterm.NewStyle(pterm.FgCyan), Bullet: ">", BulletStyle: pterm.NewStyle(pterm.FgYellow)}, + }).Render() +} + +``` diff --git a/_examples/bulletlist-custom/animation.svg b/_examples/bulletlist/customized/animation.svg similarity index 100% rename from _examples/bulletlist-custom/animation.svg rename to _examples/bulletlist/customized/animation.svg diff --git a/_examples/bulletlist-custom/main.go b/_examples/bulletlist/customized/main.go similarity index 100% rename from _examples/bulletlist-custom/main.go rename to _examples/bulletlist/customized/main.go diff --git a/_examples/center/README.md b/_examples/center/demo/README.md similarity index 96% rename from _examples/center/README.md rename to _examples/center/demo/README.md index 3b7a8b9db..0d2ad2403 100644 --- a/_examples/center/README.md +++ b/_examples/center/demo/README.md @@ -1,20 +1,20 @@ -# center - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - pterm.DefaultCenter.Println("This text is centered!\nIt centeres the whole block by default.\nIn that way you can do stuff like this:") - - // Generate BigLetters - s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString("PTerm")).Srender() - pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter - - pterm.DefaultCenter.WithCenterEachLineSeparately().Println("This text is centered!\nBut each line is\ncentered\nseparately") -} - -``` +# center + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + pterm.DefaultCenter.Println("This text is centered!\nIt centeres the whole block by default.\nIn that way you can do stuff like this:") + + // Generate BigLetters + s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString("PTerm")).Srender() + pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter + + pterm.DefaultCenter.WithCenterEachLineSeparately().Println("This text is centered!\nBut each line is\ncentered\nseparately") +} + +``` diff --git a/_examples/center/animation.svg b/_examples/center/demo/animation.svg similarity index 100% rename from _examples/center/animation.svg rename to _examples/center/demo/animation.svg diff --git a/_examples/center/main.go b/_examples/center/demo/main.go similarity index 100% rename from _examples/center/main.go rename to _examples/center/demo/main.go diff --git a/_examples/print-with-color/README.md b/_examples/coloring/demo/README.md similarity index 96% rename from _examples/print-with-color/README.md rename to _examples/coloring/demo/README.md index 5b7bf2c6f..fb5e134e8 100644 --- a/_examples/print-with-color/README.md +++ b/_examples/coloring/demo/README.md @@ -1,34 +1,34 @@ -# print-with-color - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print different colored words. - pterm.Println(pterm.Red("Hello, ") + pterm.Green("World") + pterm.Cyan("!")) - pterm.Println(pterm.Red("Even " + pterm.Cyan("nested ") + pterm.Green("colors ") + "are supported!")) - - // Print strings with set color. - pterm.FgBlack.Println("FgBlack") - pterm.FgRed.Println("FgRed") - pterm.FgGreen.Println("FgGreen") - pterm.FgYellow.Println("FgYellow") - pterm.FgBlue.Println("FgBlue") - pterm.FgMagenta.Println("FgMagenta") - pterm.FgCyan.Println("FgCyan") - pterm.FgWhite.Println("FgWhite") - pterm.Println() // Print one line space. - pterm.FgLightRed.Println("FgLightRed") - pterm.FgLightGreen.Println("FgLightGreen") - pterm.FgLightYellow.Println("FgLightYellow") - pterm.FgLightBlue.Println("FgLightBlue") - pterm.FgLightMagenta.Println("FgLightMagenta") - pterm.FgLightCyan.Println("FgLightCyan") - pterm.FgLightWhite.Println("FgLightWhite") -} - -``` +# print-with-color + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print different colored words. + pterm.Println(pterm.Red("Hello, ") + pterm.Green("World") + pterm.Cyan("!")) + pterm.Println(pterm.Red("Even " + pterm.Cyan("nested ") + pterm.Green("colors ") + "are supported!")) + + // Print strings with set color. + pterm.FgBlack.Println("FgBlack") + pterm.FgRed.Println("FgRed") + pterm.FgGreen.Println("FgGreen") + pterm.FgYellow.Println("FgYellow") + pterm.FgBlue.Println("FgBlue") + pterm.FgMagenta.Println("FgMagenta") + pterm.FgCyan.Println("FgCyan") + pterm.FgWhite.Println("FgWhite") + pterm.Println() // Print one line space. + pterm.FgLightRed.Println("FgLightRed") + pterm.FgLightGreen.Println("FgLightGreen") + pterm.FgLightYellow.Println("FgLightYellow") + pterm.FgLightBlue.Println("FgLightBlue") + pterm.FgLightMagenta.Println("FgLightMagenta") + pterm.FgLightCyan.Println("FgLightCyan") + pterm.FgLightWhite.Println("FgLightWhite") +} + +``` diff --git a/_examples/print-with-color/animation.svg b/_examples/coloring/demo/animation.svg similarity index 100% rename from _examples/print-with-color/animation.svg rename to _examples/coloring/demo/animation.svg diff --git a/_examples/print-with-color/main.go b/_examples/coloring/demo/main.go similarity index 100% rename from _examples/print-with-color/main.go rename to _examples/coloring/demo/main.go diff --git a/_examples/disable-color/README.md b/_examples/coloring/disable-color/README.md similarity index 97% rename from _examples/disable-color/README.md rename to _examples/coloring/disable-color/README.md index f3a8f5f6b..39561cc55 100644 --- a/_examples/disable-color/README.md +++ b/_examples/coloring/disable-color/README.md @@ -1,162 +1,162 @@ -# disable-color - -![Animation](animation.svg) - -```go -package main - -import ( - "math/rand" - "strconv" - "strings" - "time" - - "github.com/pterm/pterm" -) - -// Change this to time.Millisecond*200 to speed up the demo. -// Useful when debugging. -const second = time.Second - -var pseudoProgramList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ - "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") - -func main() { - pterm.DisableColor() - introScreen() - clear() - pseudoApplicationHeader() - time.Sleep(second) - installingPseudoList() - time.Sleep(second * 2) - pterm.DefaultSection.WithLevel(2).Println("Program Install Report") - installedProgramsSize() - time.Sleep(second * 4) - pterm.DefaultSection.Println("Tree Printer") - installedTree() - time.Sleep(second * 4) - pterm.DefaultSection.Println("TrueColor Support") - fadeText() - time.Sleep(second) - pterm.DefaultSection.Println("Bullet List Printer") - listPrinter() -} - -func installedTree() { - leveledList := pterm.LeveledList{ - pterm.LeveledListItem{Level: 0, Text: "C:"}, - pterm.LeveledListItem{Level: 1, Text: "Go"}, - pterm.LeveledListItem{Level: 1, Text: "Windows"}, - pterm.LeveledListItem{Level: 1, Text: "Programs"}, - } - for _, s := range pseudoProgramList { - if s != "pseudo-minecraft" { - leveledList = append(leveledList, pterm.LeveledListItem{Level: 2, Text: s}) - } - if s == "pseudo-chrome" { - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Tabs"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Extensions"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "Refined GitHub"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "GitHub Dark Theme"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Bookmarks"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "PTerm"}) - } - } - - pterm.DefaultTree.WithRoot(pterm.NewTreeFromLeveledList(leveledList)).Render() -} - -func installingPseudoList() { - pterm.DefaultSection.Println("Installing pseudo programs") - - p, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start() - for i := 0; i < p.Total; i++ { - p.UpdateTitle("Installing " + pseudoProgramList[i]) - if pseudoProgramList[i] == "pseudo-minecraft" { - pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.") - } else { - pterm.Success.Println("Installing " + pseudoProgramList[i]) - p.Increment() - } - time.Sleep(second / 2) - } - p.Stop() -} - -func listPrinter() { - pterm.NewBulletListFromString(`Good bye - Have a nice day!`, " ").Render() -} - -func fadeText() { - from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. - to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. - - str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)" - strs := strings.Split(str, "") - var fadeInfo string // String which will be used to print info. - // For loop over the range of the string length. - for i := 0; i < len(str); i++ { - // Append faded letter to info string. - fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) - } - pterm.Info.Println(fadeInfo) -} - -func installedProgramsSize() { - d := pterm.TableData{{"Program Name", "Status", "Size"}} - for _, s := range pseudoProgramList { - if s != "pseudo-minecraft" { - d = append(d, []string{s, pterm.LightGreen("pass"), strconv.Itoa(randomInt(7, 200)) + "mb"}) - } else { - d = append(d, []string{pterm.LightRed(s), pterm.LightRed("fail"), "0mb"}) - } - } - pterm.DefaultTable.WithHasHeader().WithData(d).Render() -} - -func pseudoApplicationHeader() *pterm.TextPrinter { - return pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( - "Pseudo Application created with PTerm") -} - -func introScreen() { - pterm.DefaultBigText.WithLetters( - pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)), - pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))). - Render() - - pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( - "PTDP - PTerm Demo Program") - - pterm.Info.Println("This animation was generated with the latest version of PTerm!" + - "\nPTerm works on nearly every terminal and operating system." + - "\nIt's super easy to use!" + - "\nIf you want, you can customize everything :)" + - "\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." + - "\n" + - "\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST"))) - pterm.Println() - introSpinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone(true).Start("Waiting for 15 seconds...") - time.Sleep(second) - for i := 14; i > 0; i-- { - if i > 1 { - introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...") - } else { - introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...") - } - time.Sleep(second) - } - introSpinner.Stop() -} - -func clear() { - print("\033[H\033[2J") -} - -func randomInt(min, max int) int { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(max-min+1) + min -} - -``` +# disable-color + +![Animation](animation.svg) + +```go +package main + +import ( + "math/rand" + "strconv" + "strings" + "time" + + "github.com/pterm/pterm" +) + +// Change this to time.Millisecond*200 to speed up the demo. +// Useful when debugging. +const second = time.Second + +var pseudoProgramList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ + "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") + +func main() { + pterm.DisableColor() + introScreen() + clear() + pseudoApplicationHeader() + time.Sleep(second) + installingPseudoList() + time.Sleep(second * 2) + pterm.DefaultSection.WithLevel(2).Println("Program Install Report") + installedProgramsSize() + time.Sleep(second * 4) + pterm.DefaultSection.Println("Tree Printer") + installedTree() + time.Sleep(second * 4) + pterm.DefaultSection.Println("TrueColor Support") + fadeText() + time.Sleep(second) + pterm.DefaultSection.Println("Bullet List Printer") + listPrinter() +} + +func installedTree() { + leveledList := pterm.LeveledList{ + pterm.LeveledListItem{Level: 0, Text: "C:"}, + pterm.LeveledListItem{Level: 1, Text: "Go"}, + pterm.LeveledListItem{Level: 1, Text: "Windows"}, + pterm.LeveledListItem{Level: 1, Text: "Programs"}, + } + for _, s := range pseudoProgramList { + if s != "pseudo-minecraft" { + leveledList = append(leveledList, pterm.LeveledListItem{Level: 2, Text: s}) + } + if s == "pseudo-chrome" { + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Tabs"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Extensions"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "Refined GitHub"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "GitHub Dark Theme"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Bookmarks"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "PTerm"}) + } + } + + pterm.DefaultTree.WithRoot(pterm.NewTreeFromLeveledList(leveledList)).Render() +} + +func installingPseudoList() { + pterm.DefaultSection.Println("Installing pseudo programs") + + p, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start() + for i := 0; i < p.Total; i++ { + p.UpdateTitle("Installing " + pseudoProgramList[i]) + if pseudoProgramList[i] == "pseudo-minecraft" { + pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.") + } else { + pterm.Success.Println("Installing " + pseudoProgramList[i]) + p.Increment() + } + time.Sleep(second / 2) + } + p.Stop() +} + +func listPrinter() { + pterm.NewBulletListFromString(`Good bye + Have a nice day!`, " ").Render() +} + +func fadeText() { + from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. + to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. + + str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)" + strs := strings.Split(str, "") + var fadeInfo string // String which will be used to print info. + // For loop over the range of the string length. + for i := 0; i < len(str); i++ { + // Append faded letter to info string. + fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) + } + pterm.Info.Println(fadeInfo) +} + +func installedProgramsSize() { + d := pterm.TableData{{"Program Name", "Status", "Size"}} + for _, s := range pseudoProgramList { + if s != "pseudo-minecraft" { + d = append(d, []string{s, pterm.LightGreen("pass"), strconv.Itoa(randomInt(7, 200)) + "mb"}) + } else { + d = append(d, []string{pterm.LightRed(s), pterm.LightRed("fail"), "0mb"}) + } + } + pterm.DefaultTable.WithHasHeader().WithData(d).Render() +} + +func pseudoApplicationHeader() *pterm.TextPrinter { + return pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( + "Pseudo Application created with PTerm") +} + +func introScreen() { + pterm.DefaultBigText.WithLetters( + pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)), + pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))). + Render() + + pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( + "PTDP - PTerm Demo Program") + + pterm.Info.Println("This animation was generated with the latest version of PTerm!" + + "\nPTerm works on nearly every terminal and operating system." + + "\nIt's super easy to use!" + + "\nIf you want, you can customize everything :)" + + "\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." + + "\n" + + "\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST"))) + pterm.Println() + introSpinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone(true).Start("Waiting for 15 seconds...") + time.Sleep(second) + for i := 14; i > 0; i-- { + if i > 1 { + introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...") + } else { + introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...") + } + time.Sleep(second) + } + introSpinner.Stop() +} + +func clear() { + print("\033[H\033[2J") +} + +func randomInt(min, max int) int { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(max-min+1) + min +} + +``` diff --git a/_examples/disable-color/animation.svg b/_examples/coloring/disable-color/animation.svg similarity index 100% rename from _examples/disable-color/animation.svg rename to _examples/coloring/disable-color/animation.svg diff --git a/_examples/disable-color/main.go b/_examples/coloring/disable-color/main.go similarity index 100% rename from _examples/disable-color/main.go rename to _examples/coloring/disable-color/main.go diff --git a/_examples/disable-output/README.md b/_examples/coloring/disable-output/README.md similarity index 93% rename from _examples/disable-output/README.md rename to _examples/coloring/disable-output/README.md index 536cfc574..5adec41d5 100644 --- a/_examples/disable-output/README.md +++ b/_examples/coloring/disable-output/README.md @@ -1,25 +1,25 @@ -# disable-output - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - for i := 0; i < 15; i++ { - switch i { - case 5: - pterm.Info.Println("Disabled Output!") - pterm.DisableOutput() - case 10: - pterm.EnableOutput() - pterm.Info.Println("Enabled Output!") - } - - pterm.Printf("Printing something... [%d/%d]\n", i, 15) - } -} - -``` +# disable-output + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + for i := 0; i < 15; i++ { + switch i { + case 5: + pterm.Info.Println("Disabled Output!") + pterm.DisableOutput() + case 10: + pterm.EnableOutput() + pterm.Info.Println("Enabled Output!") + } + + pterm.Printf("Printing something... [%d/%d]\n", i, 15) + } +} + +``` diff --git a/_examples/disable-output/animation.svg b/_examples/coloring/disable-output/animation.svg similarity index 100% rename from _examples/disable-output/animation.svg rename to _examples/coloring/disable-output/animation.svg diff --git a/_examples/disable-output/main.go b/_examples/coloring/disable-output/main.go similarity index 100% rename from _examples/disable-output/main.go rename to _examples/coloring/disable-output/main.go diff --git a/_examples/disable-styling/README.md b/_examples/coloring/disable-styling/README.md similarity index 97% rename from _examples/disable-styling/README.md rename to _examples/coloring/disable-styling/README.md index 93f3846dc..ae4555074 100644 --- a/_examples/disable-styling/README.md +++ b/_examples/coloring/disable-styling/README.md @@ -1,162 +1,162 @@ -# disable-styling - -![Animation](animation.svg) - -```go -package main - -import ( - "math/rand" - "strconv" - "strings" - "time" - - "github.com/pterm/pterm" -) - -// Change this to time.Millisecond*200 to speed up the demo. -// Useful when debugging. -const second = time.Second - -var pseudoProgramList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ - "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") - -func main() { - pterm.DisableStyling() - introScreen() - clear() - pseudoApplicationHeader() - time.Sleep(second) - installingPseudoList() - time.Sleep(second * 2) - pterm.DefaultSection.WithLevel(2).Println("Program Install Report") - installedProgramsSize() - time.Sleep(second * 4) - pterm.DefaultSection.Println("Tree Printer") - installedTree() - time.Sleep(second * 4) - pterm.DefaultSection.Println("TrueColor Support") - fadeText() - time.Sleep(second) - pterm.DefaultSection.Println("Bullet List Printer") - listPrinter() -} - -func installedTree() { - leveledList := pterm.LeveledList{ - pterm.LeveledListItem{Level: 0, Text: "C:"}, - pterm.LeveledListItem{Level: 1, Text: "Go"}, - pterm.LeveledListItem{Level: 1, Text: "Windows"}, - pterm.LeveledListItem{Level: 1, Text: "Programs"}, - } - for _, s := range pseudoProgramList { - if s != "pseudo-minecraft" { - leveledList = append(leveledList, pterm.LeveledListItem{Level: 2, Text: s}) - } - if s == "pseudo-chrome" { - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Tabs"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Extensions"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "Refined GitHub"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "GitHub Dark Theme"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Bookmarks"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "PTerm"}) - } - } - - pterm.DefaultTree.WithRoot(pterm.NewTreeFromLeveledList(leveledList)).Render() -} - -func installingPseudoList() { - pterm.DefaultSection.Println("Installing pseudo programs") - - p, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start() - for i := 0; i < p.Total; i++ { - p.UpdateTitle("Installing " + pseudoProgramList[i]) - if pseudoProgramList[i] == "pseudo-minecraft" { - pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.") - } else { - pterm.Success.Println("Installing " + pseudoProgramList[i]) - p.Increment() - } - time.Sleep(second / 2) - } - p.Stop() -} - -func listPrinter() { - pterm.NewBulletListFromString(`Good bye - Have a nice day!`, " ").Render() -} - -func fadeText() { - from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. - to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. - - str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)" - strs := strings.Split(str, "") - var fadeInfo string // String which will be used to print info. - // For loop over the range of the string length. - for i := 0; i < len(str); i++ { - // Append faded letter to info string. - fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) - } - pterm.Info.Println(fadeInfo) -} - -func installedProgramsSize() { - d := pterm.TableData{{"Program Name", "Status", "Size"}} - for _, s := range pseudoProgramList { - if s != "pseudo-minecraft" { - d = append(d, []string{s, pterm.LightGreen("pass"), strconv.Itoa(randomInt(7, 200)) + "mb"}) - } else { - d = append(d, []string{pterm.LightRed(s), pterm.LightRed("fail"), "0mb"}) - } - } - pterm.DefaultTable.WithHasHeader().WithData(d).Render() -} - -func pseudoApplicationHeader() *pterm.TextPrinter { - return pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( - "Pseudo Application created with PTerm") -} - -func introScreen() { - pterm.DefaultBigText.WithLetters( - pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)), - pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))). - Render() - - pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( - "PTDP - PTerm Demo Program") - - pterm.Info.Println("This animation was generated with the latest version of PTerm!" + - "\nPTerm works on nearly every terminal and operating system." + - "\nIt's super easy to use!" + - "\nIf you want, you can customize everything :)" + - "\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." + - "\n" + - "\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST"))) - pterm.Println() - introSpinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone(true).Start("Waiting for 15 seconds...") - time.Sleep(second) - for i := 14; i > 0; i-- { - if i > 1 { - introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...") - } else { - introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...") - } - time.Sleep(second) - } - introSpinner.Stop() -} - -func clear() { - print("\033[H\033[2J") -} - -func randomInt(min, max int) int { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(max-min+1) + min -} - -``` +# disable-styling + +![Animation](animation.svg) + +```go +package main + +import ( + "math/rand" + "strconv" + "strings" + "time" + + "github.com/pterm/pterm" +) + +// Change this to time.Millisecond*200 to speed up the demo. +// Useful when debugging. +const second = time.Second + +var pseudoProgramList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ + "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") + +func main() { + pterm.DisableStyling() + introScreen() + clear() + pseudoApplicationHeader() + time.Sleep(second) + installingPseudoList() + time.Sleep(second * 2) + pterm.DefaultSection.WithLevel(2).Println("Program Install Report") + installedProgramsSize() + time.Sleep(second * 4) + pterm.DefaultSection.Println("Tree Printer") + installedTree() + time.Sleep(second * 4) + pterm.DefaultSection.Println("TrueColor Support") + fadeText() + time.Sleep(second) + pterm.DefaultSection.Println("Bullet List Printer") + listPrinter() +} + +func installedTree() { + leveledList := pterm.LeveledList{ + pterm.LeveledListItem{Level: 0, Text: "C:"}, + pterm.LeveledListItem{Level: 1, Text: "Go"}, + pterm.LeveledListItem{Level: 1, Text: "Windows"}, + pterm.LeveledListItem{Level: 1, Text: "Programs"}, + } + for _, s := range pseudoProgramList { + if s != "pseudo-minecraft" { + leveledList = append(leveledList, pterm.LeveledListItem{Level: 2, Text: s}) + } + if s == "pseudo-chrome" { + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Tabs"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Extensions"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "Refined GitHub"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "GitHub Dark Theme"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Bookmarks"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "PTerm"}) + } + } + + pterm.DefaultTree.WithRoot(pterm.NewTreeFromLeveledList(leveledList)).Render() +} + +func installingPseudoList() { + pterm.DefaultSection.Println("Installing pseudo programs") + + p, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start() + for i := 0; i < p.Total; i++ { + p.UpdateTitle("Installing " + pseudoProgramList[i]) + if pseudoProgramList[i] == "pseudo-minecraft" { + pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.") + } else { + pterm.Success.Println("Installing " + pseudoProgramList[i]) + p.Increment() + } + time.Sleep(second / 2) + } + p.Stop() +} + +func listPrinter() { + pterm.NewBulletListFromString(`Good bye + Have a nice day!`, " ").Render() +} + +func fadeText() { + from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. + to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. + + str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)" + strs := strings.Split(str, "") + var fadeInfo string // String which will be used to print info. + // For loop over the range of the string length. + for i := 0; i < len(str); i++ { + // Append faded letter to info string. + fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) + } + pterm.Info.Println(fadeInfo) +} + +func installedProgramsSize() { + d := pterm.TableData{{"Program Name", "Status", "Size"}} + for _, s := range pseudoProgramList { + if s != "pseudo-minecraft" { + d = append(d, []string{s, pterm.LightGreen("pass"), strconv.Itoa(randomInt(7, 200)) + "mb"}) + } else { + d = append(d, []string{pterm.LightRed(s), pterm.LightRed("fail"), "0mb"}) + } + } + pterm.DefaultTable.WithHasHeader().WithData(d).Render() +} + +func pseudoApplicationHeader() *pterm.TextPrinter { + return pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( + "Pseudo Application created with PTerm") +} + +func introScreen() { + pterm.DefaultBigText.WithLetters( + pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)), + pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))). + Render() + + pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( + "PTDP - PTerm Demo Program") + + pterm.Info.Println("This animation was generated with the latest version of PTerm!" + + "\nPTerm works on nearly every terminal and operating system." + + "\nIt's super easy to use!" + + "\nIf you want, you can customize everything :)" + + "\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." + + "\n" + + "\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST"))) + pterm.Println() + introSpinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone(true).Start("Waiting for 15 seconds...") + time.Sleep(second) + for i := 14; i > 0; i-- { + if i > 1 { + introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...") + } else { + introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...") + } + time.Sleep(second) + } + introSpinner.Stop() +} + +func clear() { + print("\033[H\033[2J") +} + +func randomInt(min, max int) int { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(max-min+1) + min +} + +``` diff --git a/_examples/disable-styling/animation.svg b/_examples/coloring/disable-styling/animation.svg similarity index 100% rename from _examples/disable-styling/animation.svg rename to _examples/coloring/disable-styling/animation.svg diff --git a/_examples/disable-styling/main.go b/_examples/coloring/disable-styling/main.go similarity index 100% rename from _examples/disable-styling/main.go rename to _examples/coloring/disable-styling/main.go diff --git a/_examples/print-color-fade/README.md b/_examples/coloring/fade-colors/README.md similarity index 96% rename from _examples/print-color-fade/README.md rename to _examples/coloring/fade-colors/README.md index 3ca653132..35c1dbd01 100644 --- a/_examples/print-color-fade/README.md +++ b/_examples/coloring/fade-colors/README.md @@ -1,26 +1,26 @@ -# print-color-fade - -![Animation](animation.svg) - -```go -package main - -import ( - "github.com/pterm/pterm" -) - -func main() { - // Print info. - pterm.Info.Println("RGB colors only work in Terminals which support TrueColor.") - - from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. - to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients end point. - - // For loop over the range of the terminal height. - for i := 0; i < pterm.GetTerminalHeight()-2; i++ { - // Print string which is colored with the faded RGB value. - from.Fade(0, float32(pterm.GetTerminalHeight()-2), float32(i), to).Println("Hello, World!") - } -} - -``` +# print-color-fade + +![Animation](animation.svg) + +```go +package main + +import ( + "github.com/pterm/pterm" +) + +func main() { + // Print info. + pterm.Info.Println("RGB colors only work in Terminals which support TrueColor.") + + from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. + to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients end point. + + // For loop over the range of the terminal height. + for i := 0; i < pterm.GetTerminalHeight()-2; i++ { + // Print string which is colored with the faded RGB value. + from.Fade(0, float32(pterm.GetTerminalHeight()-2), float32(i), to).Println("Hello, World!") + } +} + +``` diff --git a/_examples/print-color-fade/animation.svg b/_examples/coloring/fade-colors/animation.svg similarity index 100% rename from _examples/print-color-fade/animation.svg rename to _examples/coloring/fade-colors/animation.svg diff --git a/_examples/print-color-fade/main.go b/_examples/coloring/fade-colors/main.go similarity index 100% rename from _examples/print-color-fade/main.go rename to _examples/coloring/fade-colors/main.go diff --git a/_examples/print-color-fade-multiple/README.md b/_examples/coloring/fade-multiple-colors/README.md similarity index 97% rename from _examples/print-color-fade-multiple/README.md rename to _examples/coloring/fade-multiple-colors/README.md index 3584be65b..85b091cee 100644 --- a/_examples/print-color-fade-multiple/README.md +++ b/_examples/coloring/fade-multiple-colors/README.md @@ -1,40 +1,40 @@ -# print-color-fade-multiple - -![Animation](animation.svg) - -```go -package main - -import ( - "strings" - - "github.com/pterm/pterm" -) - -func main() { - from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. - to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. - to2 := pterm.NewRGB(255, 0, 0) // This RGB value is used as the gradients second point. - to3 := pterm.NewRGB(0, 255, 0) // This RGB value is used as the gradients third point. - to4 := pterm.NewRGB(255, 255, 255) // This RGB value is used as the gradients end point. - - str := "RGB colors only work in Terminals which support TrueColor." - strs := strings.Split(str, "") - var fadeInfo string // String which will be used to print info. - // For loop over the range of the string length. - for i := 0; i < len(str); i++ { - // Append faded letter to info string. - fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) - } - - // Print info. - pterm.Info.Println(fadeInfo) - - // For loop over the range of the terminal height. - for i := 0; i < pterm.GetTerminalHeight()-2; i++ { - // Print string which is colored with the faded RGB value. - from.Fade(0, float32(pterm.GetTerminalHeight()-2), float32(i), to, to2, to3, to4).Println("Hello, World!") - } -} - -``` +# print-color-fade-multiple + +![Animation](animation.svg) + +```go +package main + +import ( + "strings" + + "github.com/pterm/pterm" +) + +func main() { + from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. + to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. + to2 := pterm.NewRGB(255, 0, 0) // This RGB value is used as the gradients second point. + to3 := pterm.NewRGB(0, 255, 0) // This RGB value is used as the gradients third point. + to4 := pterm.NewRGB(255, 255, 255) // This RGB value is used as the gradients end point. + + str := "RGB colors only work in Terminals which support TrueColor." + strs := strings.Split(str, "") + var fadeInfo string // String which will be used to print info. + // For loop over the range of the string length. + for i := 0; i < len(str); i++ { + // Append faded letter to info string. + fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) + } + + // Print info. + pterm.Info.Println(fadeInfo) + + // For loop over the range of the terminal height. + for i := 0; i < pterm.GetTerminalHeight()-2; i++ { + // Print string which is colored with the faded RGB value. + from.Fade(0, float32(pterm.GetTerminalHeight()-2), float32(i), to, to2, to3, to4).Println("Hello, World!") + } +} + +``` diff --git a/_examples/print-color-fade-multiple/animation.svg b/_examples/coloring/fade-multiple-colors/animation.svg similarity index 100% rename from _examples/print-color-fade-multiple/animation.svg rename to _examples/coloring/fade-multiple-colors/animation.svg diff --git a/_examples/print-color-fade-multiple/main.go b/_examples/coloring/fade-multiple-colors/main.go similarity index 100% rename from _examples/print-color-fade-multiple/main.go rename to _examples/coloring/fade-multiple-colors/main.go diff --git a/_examples/override-default-printers/README.md b/_examples/coloring/override-default-printers/README.md similarity index 95% rename from _examples/override-default-printers/README.md rename to _examples/coloring/override-default-printers/README.md index a58774595..567c7161f 100644 --- a/_examples/override-default-printers/README.md +++ b/_examples/coloring/override-default-printers/README.md @@ -1,24 +1,24 @@ -# override-default-printers - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print default error. - pterm.Error.Println("This is the default Error") - - // Customize default error. - pterm.Error.Prefix = pterm.Prefix{ - Text: "OVERRIDE", - Style: pterm.NewStyle(pterm.BgCyan, pterm.FgRed), - } - - // Print new default error. - pterm.Error.Println("This is the default Error after the prefix was overridden") -} - -``` +# override-default-printers + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print default error. + pterm.Error.Println("This is the default Error") + + // Customize default error. + pterm.Error.Prefix = pterm.Prefix{ + Text: "OVERRIDE", + Style: pterm.NewStyle(pterm.BgCyan, pterm.FgRed), + } + + // Print new default error. + pterm.Error.Println("This is the default Error after the prefix was overridden") +} + +``` diff --git a/_examples/override-default-printers/animation.svg b/_examples/coloring/override-default-printers/animation.svg similarity index 100% rename from _examples/override-default-printers/animation.svg rename to _examples/coloring/override-default-printers/animation.svg diff --git a/_examples/override-default-printers/main.go b/_examples/coloring/override-default-printers/main.go similarity index 100% rename from _examples/override-default-printers/main.go rename to _examples/coloring/override-default-printers/main.go diff --git a/_examples/print-color-rgb/README.md b/_examples/coloring/print-color-rgb/README.md similarity index 96% rename from _examples/print-color-rgb/README.md rename to _examples/coloring/print-color-rgb/README.md index e5ce365d4..e96e5084b 100644 --- a/_examples/print-color-rgb/README.md +++ b/_examples/coloring/print-color-rgb/README.md @@ -1,18 +1,18 @@ -# print-color-rgb - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print strings with a custom RGB color. - // NOTICE: This only works with terminals which support TrueColor. - pterm.NewRGB(178, 44, 199).Println("This text is printed with a custom RGB!") - pterm.NewRGB(15, 199, 209).Println("This text is printed with a custom RGB!") - pterm.NewRGB(201, 144, 30).Println("This text is printed with a custom RGB!") -} - -``` +# print-color-rgb + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print strings with a custom RGB color. + // NOTICE: This only works with terminals which support TrueColor. + pterm.NewRGB(178, 44, 199).Println("This text is printed with a custom RGB!") + pterm.NewRGB(15, 199, 209).Println("This text is printed with a custom RGB!") + pterm.NewRGB(201, 144, 30).Println("This text is printed with a custom RGB!") +} + +``` diff --git a/_examples/print-color-rgb/animation.svg b/_examples/coloring/print-color-rgb/animation.svg similarity index 100% rename from _examples/print-color-rgb/animation.svg rename to _examples/coloring/print-color-rgb/animation.svg diff --git a/_examples/print-color-rgb/main.go b/_examples/coloring/print-color-rgb/main.go similarity index 100% rename from _examples/print-color-rgb/main.go rename to _examples/coloring/print-color-rgb/main.go diff --git a/_examples/demo/README.md b/_examples/demo/demo/README.md similarity index 97% rename from _examples/demo/README.md rename to _examples/demo/demo/README.md index 243a8247a..4738b2e1f 100644 --- a/_examples/demo/README.md +++ b/_examples/demo/demo/README.md @@ -1,162 +1,162 @@ -# demo - -![Animation](animation.svg) - -```go -package main - -import ( - "math/rand" - "strconv" - "strings" - "time" - - "github.com/pterm/pterm" -) - -// Change this to time.Millisecond*200 to speed up the demo. -// Useful when debugging. -const second = time.Second - -var pseudoProgramList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ - "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") - -func main() { - introScreen() - clear() - pseudoApplicationHeader() - time.Sleep(second) - installingPseudoList() - time.Sleep(second * 2) - pterm.DefaultSection.WithLevel(2).Println("Program Install Report") - installedProgramsSize() - time.Sleep(second * 4) - pterm.DefaultSection.Println("Tree Printer") - installedTree() - time.Sleep(second * 4) - pterm.DefaultSection.Println("TrueColor Support") - fadeText() - time.Sleep(second) - pterm.DefaultSection.Println("Bullet List Printer") - listPrinter() -} - -func installedTree() { - leveledList := pterm.LeveledList{ - pterm.LeveledListItem{Level: 0, Text: "C:"}, - pterm.LeveledListItem{Level: 1, Text: "Go"}, - pterm.LeveledListItem{Level: 1, Text: "Windows"}, - pterm.LeveledListItem{Level: 1, Text: "Programs"}, - } - for _, s := range pseudoProgramList { - if s != "pseudo-minecraft" { - leveledList = append(leveledList, pterm.LeveledListItem{Level: 2, Text: s}) - } - if s == "pseudo-chrome" { - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Tabs"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Extensions"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "Refined GitHub"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "GitHub Dark Theme"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Bookmarks"}) - leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "PTerm"}) - } - } - - pterm.DefaultTree.WithRoot(pterm.NewTreeFromLeveledList(leveledList)).Render() -} - -func installingPseudoList() { - pterm.DefaultSection.Println("Installing pseudo programs") - - p, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start() - for i := 0; i < p.Total; i++ { - p.UpdateTitle("Installing " + pseudoProgramList[i]) - if pseudoProgramList[i] == "pseudo-minecraft" { - pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.") - } else { - pterm.Success.Println("Installing " + pseudoProgramList[i]) - p.Increment() - } - time.Sleep(second / 2) - } - p.Stop() -} - -func listPrinter() { - pterm.NewBulletListFromString(`Good bye - Have a nice day!`, " ").Render() -} - -func fadeText() { - from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. - to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. - - str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)" - strs := strings.Split(str, "") - var fadeInfo string // String which will be used to print info. - // For loop over the range of the string length. - for i := 0; i < len(str); i++ { - // Append faded letter to info string. - fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) - } - pterm.Info.Println(fadeInfo) -} - -func installedProgramsSize() { - d := pterm.TableData{{"Program Name", "Status", "Size"}} - for _, s := range pseudoProgramList { - if s != "pseudo-minecraft" { - d = append(d, []string{s, pterm.LightGreen("pass"), strconv.Itoa(randomInt(7, 200)) + "mb"}) - } else { - d = append(d, []string{pterm.LightRed(s), pterm.LightRed("fail"), "0mb"}) - } - } - pterm.DefaultTable.WithHasHeader().WithData(d).Render() -} - -func pseudoApplicationHeader() *pterm.TextPrinter { - return pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( - "Pseudo Application created with PTerm") -} - -func introScreen() { - ptermLogo, _ := pterm.DefaultBigText.WithLetters( - pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)), - pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))). - Srender() - - pterm.DefaultCenter.Print(ptermLogo) - - pterm.DefaultCenter.Print(pterm.DefaultHeader.WithFullWidth().WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Sprint("PTDP - PTerm Demo Program")) - - pterm.Info.Println("This animation was generated with the latest version of PTerm!" + - "\nPTerm works on nearly every terminal and operating system." + - "\nIt's super easy to use!" + - "\nIf you want, you can customize everything :)" + - "\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." + - "\n" + - "\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST"))) - pterm.Println() - introSpinner, _ := pterm.DefaultSpinner.WithShowTimer(false).WithRemoveWhenDone(true).Start("Waiting for 15 seconds...") - time.Sleep(second) - for i := 14; i > 0; i-- { - if i > 1 { - introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...") - } else { - introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...") - } - time.Sleep(second) - } - introSpinner.Stop() -} - -func clear() { - print("\033[H\033[2J") -} - -func randomInt(min, max int) int { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(max-min+1) + min -} - -``` +# demo + +![Animation](animation.svg) + +```go +package main + +import ( + "math/rand" + "strconv" + "strings" + "time" + + "github.com/pterm/pterm" +) + +// Change this to time.Millisecond*200 to speed up the demo. +// Useful when debugging. +const second = time.Second + +var pseudoProgramList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ + "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") + +func main() { + introScreen() + clear() + pseudoApplicationHeader() + time.Sleep(second) + installingPseudoList() + time.Sleep(second * 2) + pterm.DefaultSection.WithLevel(2).Println("Program Install Report") + installedProgramsSize() + time.Sleep(second * 4) + pterm.DefaultSection.Println("Tree Printer") + installedTree() + time.Sleep(second * 4) + pterm.DefaultSection.Println("TrueColor Support") + fadeText() + time.Sleep(second) + pterm.DefaultSection.Println("Bullet List Printer") + listPrinter() +} + +func installedTree() { + leveledList := pterm.LeveledList{ + pterm.LeveledListItem{Level: 0, Text: "C:"}, + pterm.LeveledListItem{Level: 1, Text: "Go"}, + pterm.LeveledListItem{Level: 1, Text: "Windows"}, + pterm.LeveledListItem{Level: 1, Text: "Programs"}, + } + for _, s := range pseudoProgramList { + if s != "pseudo-minecraft" { + leveledList = append(leveledList, pterm.LeveledListItem{Level: 2, Text: s}) + } + if s == "pseudo-chrome" { + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Tabs"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Extensions"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "Refined GitHub"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "GitHub Dark Theme"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 3, Text: "pseudo-Bookmarks"}) + leveledList = append(leveledList, pterm.LeveledListItem{Level: 4, Text: "PTerm"}) + } + } + + pterm.DefaultTree.WithRoot(pterm.NewTreeFromLeveledList(leveledList)).Render() +} + +func installingPseudoList() { + pterm.DefaultSection.Println("Installing pseudo programs") + + p, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start() + for i := 0; i < p.Total; i++ { + p.UpdateTitle("Installing " + pseudoProgramList[i]) + if pseudoProgramList[i] == "pseudo-minecraft" { + pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.") + } else { + pterm.Success.Println("Installing " + pseudoProgramList[i]) + p.Increment() + } + time.Sleep(second / 2) + } + p.Stop() +} + +func listPrinter() { + pterm.NewBulletListFromString(`Good bye + Have a nice day!`, " ").Render() +} + +func fadeText() { + from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point. + to := pterm.NewRGB(255, 0, 255) // This RGB value is used as the gradients first point. + + str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)" + strs := strings.Split(str, "") + var fadeInfo string // String which will be used to print info. + // For loop over the range of the string length. + for i := 0; i < len(str); i++ { + // Append faded letter to info string. + fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i]) + } + pterm.Info.Println(fadeInfo) +} + +func installedProgramsSize() { + d := pterm.TableData{{"Program Name", "Status", "Size"}} + for _, s := range pseudoProgramList { + if s != "pseudo-minecraft" { + d = append(d, []string{s, pterm.LightGreen("pass"), strconv.Itoa(randomInt(7, 200)) + "mb"}) + } else { + d = append(d, []string{pterm.LightRed(s), pterm.LightRed("fail"), "0mb"}) + } + } + pterm.DefaultTable.WithHasHeader().WithData(d).Render() +} + +func pseudoApplicationHeader() *pterm.TextPrinter { + return pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println( + "Pseudo Application created with PTerm") +} + +func introScreen() { + ptermLogo, _ := pterm.DefaultBigText.WithLetters( + pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)), + pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))). + Srender() + + pterm.DefaultCenter.Print(ptermLogo) + + pterm.DefaultCenter.Print(pterm.DefaultHeader.WithFullWidth().WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Sprint("PTDP - PTerm Demo Program")) + + pterm.Info.Println("This animation was generated with the latest version of PTerm!" + + "\nPTerm works on nearly every terminal and operating system." + + "\nIt's super easy to use!" + + "\nIf you want, you can customize everything :)" + + "\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." + + "\n" + + "\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST"))) + pterm.Println() + introSpinner, _ := pterm.DefaultSpinner.WithShowTimer(false).WithRemoveWhenDone(true).Start("Waiting for 15 seconds...") + time.Sleep(second) + for i := 14; i > 0; i-- { + if i > 1 { + introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...") + } else { + introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...") + } + time.Sleep(second) + } + introSpinner.Stop() +} + +func clear() { + print("\033[H\033[2J") +} + +func randomInt(min, max int) int { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(max-min+1) + min +} + +``` diff --git a/_examples/demo/animation.svg b/_examples/demo/demo/animation.svg similarity index 100% rename from _examples/demo/animation.svg rename to _examples/demo/demo/animation.svg diff --git a/_examples/demo/main.go b/_examples/demo/demo/main.go similarity index 100% rename from _examples/demo/main.go rename to _examples/demo/demo/main.go diff --git a/_examples/header-custom/README.md b/_examples/header-custom/demo/README.md similarity index 96% rename from _examples/header-custom/README.md rename to _examples/header-custom/demo/README.md index 535a8174a..c8d2ec956 100644 --- a/_examples/header-custom/README.md +++ b/_examples/header-custom/demo/README.md @@ -1,33 +1,33 @@ -# header-custom - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // All available options: https://pkg.go.dev/github.com/pterm/pterm#HeaderPrinter - - // Build on top of DefaultHeader - pterm.DefaultHeader. // Use DefaultHeader as base - WithMargin(15). - WithBackgroundStyle(pterm.NewStyle(pterm.BgCyan)). - WithTextStyle(pterm.NewStyle(pterm.FgBlack)). - Println("This is a custom header!") - // Instead of printing the header you can set it to a variable. - // You can then reuse your custom header. - - // Making a completely new HeaderPrinter - newHeader := pterm.HeaderPrinter{ - TextStyle: pterm.NewStyle(pterm.FgBlack), - BackgroundStyle: pterm.NewStyle(pterm.BgRed), - Margin: 20, - } - - // Print header. - newHeader.Println("This is a custom header!") -} - -``` +# header-custom + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // All available options: https://pkg.go.dev/github.com/pterm/pterm#HeaderPrinter + + // Build on top of DefaultHeader + pterm.DefaultHeader. // Use DefaultHeader as base + WithMargin(15). + WithBackgroundStyle(pterm.NewStyle(pterm.BgCyan)). + WithTextStyle(pterm.NewStyle(pterm.FgBlack)). + Println("This is a custom header!") + // Instead of printing the header you can set it to a variable. + // You can then reuse your custom header. + + // Making a completely new HeaderPrinter + newHeader := pterm.HeaderPrinter{ + TextStyle: pterm.NewStyle(pterm.FgBlack), + BackgroundStyle: pterm.NewStyle(pterm.BgRed), + Margin: 20, + } + + // Print header. + newHeader.Println("This is a custom header!") +} + +``` diff --git a/_examples/header-custom/animation.svg b/_examples/header-custom/demo/animation.svg similarity index 100% rename from _examples/header-custom/animation.svg rename to _examples/header-custom/demo/animation.svg diff --git a/_examples/header-custom/main.go b/_examples/header-custom/demo/main.go similarity index 100% rename from _examples/header-custom/main.go rename to _examples/header-custom/demo/main.go diff --git a/_examples/header/README.md b/_examples/header/demo/README.md similarity index 94% rename from _examples/header/README.md rename to _examples/header/demo/README.md index 05cd60399..9ad70d682 100644 --- a/_examples/header/README.md +++ b/_examples/header/demo/README.md @@ -1,17 +1,17 @@ -# header - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print a default header. - pterm.DefaultHeader.Println("This is the default header!") - pterm.Println() // spacer - pterm.DefaultHeader.WithFullWidth().Println("This is a full-width header.") -} - -``` +# header + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print a default header. + pterm.DefaultHeader.Println("This is the default header!") + pterm.Println() // spacer + pterm.DefaultHeader.WithFullWidth().Println("This is a full-width header.") +} + +``` diff --git a/_examples/header/animation.svg b/_examples/header/demo/animation.svg similarity index 100% rename from _examples/header/animation.svg rename to _examples/header/demo/animation.svg diff --git a/_examples/header/main.go b/_examples/header/demo/main.go similarity index 100% rename from _examples/header/main.go rename to _examples/header/demo/main.go diff --git a/_examples/panel/README.md b/_examples/panel/demo/README.md similarity index 96% rename from _examples/panel/README.md rename to _examples/panel/demo/README.md index 60a5942e8..220be07bc 100644 --- a/_examples/panel/README.md +++ b/_examples/panel/demo/README.md @@ -1,21 +1,21 @@ -# panel - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Declare panels in a two dimensional grid system. - panels := pterm.Panels{ - {{Data: "This is the first panel"}, {Data: pterm.DefaultHeader.Sprint("Hello, World!")}, {Data: "This\npanel\ncontains\nmultiple\nlines"}}, - {{Data: pterm.Red("This is another\npanel line")}, {Data: "This is the second panel\nwith a new line"}}, - } - - // Print panels. - _ = pterm.DefaultPanel.WithPanels(panels).WithPadding(5).Render() -} - -``` +# panel + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Declare panels in a two dimensional grid system. + panels := pterm.Panels{ + {{Data: "This is the first panel"}, {Data: pterm.DefaultHeader.Sprint("Hello, World!")}, {Data: "This\npanel\ncontains\nmultiple\nlines"}}, + {{Data: pterm.Red("This is another\npanel line")}, {Data: "This is the second panel\nwith a new line"}}, + } + + // Print panels. + _ = pterm.DefaultPanel.WithPanels(panels).WithPadding(5).Render() +} + +``` diff --git a/_examples/panel/animation.svg b/_examples/panel/demo/animation.svg similarity index 100% rename from _examples/panel/animation.svg rename to _examples/panel/demo/animation.svg diff --git a/_examples/panel/main.go b/_examples/panel/demo/main.go similarity index 100% rename from _examples/panel/main.go rename to _examples/panel/demo/main.go diff --git a/_examples/paragraph-custom/README.md b/_examples/paragraph/customized/README.md similarity index 97% rename from _examples/paragraph-custom/README.md rename to _examples/paragraph/customized/README.md index bc3000b7a..3d15cd0a4 100644 --- a/_examples/paragraph-custom/README.md +++ b/_examples/paragraph/customized/README.md @@ -1,24 +1,24 @@ -# paragraph-custom - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print a paragraph with a custom maximal width. - pterm.DefaultParagraph.WithMaxWidth(60).Println("This is a custom paragraph printer. As you can see, no words are separated, " + - "but the text is split at the spaces. This is useful for continuous text of all kinds. You can manually change the line width if you want to." + - "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") - - // Print one line space. - pterm.Println() - - // Print text without a paragraph printer. - pterm.Println("This text is written with the default Println() function. No intelligent splitting here." + - "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") -} - -``` +# paragraph-custom + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print a paragraph with a custom maximal width. + pterm.DefaultParagraph.WithMaxWidth(60).Println("This is a custom paragraph printer. As you can see, no words are separated, " + + "but the text is split at the spaces. This is useful for continuous text of all kinds. You can manually change the line width if you want to." + + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") + + // Print one line space. + pterm.Println() + + // Print text without a paragraph printer. + pterm.Println("This text is written with the default Println() function. No intelligent splitting here." + + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") +} + +``` diff --git a/_examples/paragraph-custom/animation.svg b/_examples/paragraph/customized/animation.svg similarity index 100% rename from _examples/paragraph-custom/animation.svg rename to _examples/paragraph/customized/animation.svg diff --git a/_examples/paragraph-custom/main.go b/_examples/paragraph/customized/main.go similarity index 100% rename from _examples/paragraph-custom/main.go rename to _examples/paragraph/customized/main.go diff --git a/_examples/paragraph/README.md b/_examples/paragraph/demo/README.md similarity index 97% rename from _examples/paragraph/README.md rename to _examples/paragraph/demo/README.md index d6102eb13..07ad0d57c 100644 --- a/_examples/paragraph/README.md +++ b/_examples/paragraph/demo/README.md @@ -1,24 +1,24 @@ -# paragraph - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print long text with default paragraph printer. - pterm.DefaultParagraph.Println("This is the default paragraph printer. As you can see, no words are separated, " + - "but the text is split at the spaces. This is useful for continuous text of all kinds. You can manually change the line width if you want to." + - "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") - - // Print one line space. - pterm.Println() - - // Print long text without paragraph printer. - pterm.Println("This text is written with the default Println() function. No intelligent splitting here." + - "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") -} - -``` +# paragraph + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print long text with default paragraph printer. + pterm.DefaultParagraph.Println("This is the default paragraph printer. As you can see, no words are separated, " + + "but the text is split at the spaces. This is useful for continuous text of all kinds. You can manually change the line width if you want to." + + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") + + // Print one line space. + pterm.Println() + + // Print long text without paragraph printer. + pterm.Println("This text is written with the default Println() function. No intelligent splitting here." + + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam") +} + +``` diff --git a/_examples/paragraph/animation.svg b/_examples/paragraph/demo/animation.svg similarity index 100% rename from _examples/paragraph/animation.svg rename to _examples/paragraph/demo/animation.svg diff --git a/_examples/paragraph/main.go b/_examples/paragraph/demo/main.go similarity index 100% rename from _examples/paragraph/main.go rename to _examples/paragraph/demo/main.go diff --git a/_examples/prefix/README.md b/_examples/prefix/demo/README.md similarity index 97% rename from _examples/prefix/README.md rename to _examples/prefix/demo/README.md index 9df20dd0b..3d23fe3ec 100644 --- a/_examples/prefix/README.md +++ b/_examples/prefix/demo/README.md @@ -1,24 +1,24 @@ -# prefix - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Enable debug messages. - pterm.EnableDebugMessages() - - pterm.Debug.Println("Hello, World!") // Print Debug. - pterm.Info.Println("Hello, World!") // Print Info. - pterm.Success.Println("Hello, World!") // Print Success. - pterm.Warning.Println("Hello, World!") // Print Warning. - pterm.Error.Println("Errors show the filename and linenumber inside the terminal!") // Print Error. - pterm.Info.WithShowLineNumber().Println("Other PrefixPrinters can do that too!") // Print Error. - // Temporarily set Fatal to false, so that the CI won't crash. - pterm.Fatal.WithFatal(false).Println("Hello, World!") // Print Fatal. -} - -``` +# prefix + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Enable debug messages. + pterm.EnableDebugMessages() + + pterm.Debug.Println("Hello, World!") // Print Debug. + pterm.Info.Println("Hello, World!") // Print Info. + pterm.Success.Println("Hello, World!") // Print Success. + pterm.Warning.Println("Hello, World!") // Print Warning. + pterm.Error.Println("Errors show the filename and linenumber inside the terminal!") // Print Error. + pterm.Info.WithShowLineNumber().Println("Other PrefixPrinters can do that too!") // Print Error. + // Temporarily set Fatal to false, so that the CI won't crash. + pterm.Fatal.WithFatal(false).Println("Hello, World!") // Print Fatal. +} + +``` diff --git a/_examples/prefix/animation.svg b/_examples/prefix/demo/animation.svg similarity index 100% rename from _examples/prefix/animation.svg rename to _examples/prefix/demo/animation.svg diff --git a/_examples/prefix/main.go b/_examples/prefix/demo/main.go similarity index 100% rename from _examples/prefix/main.go rename to _examples/prefix/demo/main.go diff --git a/_examples/progressbar/README.md b/_examples/progressbar/demo/README.md similarity index 97% rename from _examples/progressbar/README.md rename to _examples/progressbar/demo/README.md index 49cb10121..250d14098 100644 --- a/_examples/progressbar/README.md +++ b/_examples/progressbar/demo/README.md @@ -1,31 +1,31 @@ -# progressbar - -![Animation](animation.svg) - -```go -package main - -import ( - "strings" - "time" - - "github.com/pterm/pterm" -) - -// Slice of strings with placeholder text. -var fakeInstallList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ - "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") - -func main() { - // Create progressbar as fork from the default progressbar. - p, _ := pterm.DefaultProgressbar.WithTotal(len(fakeInstallList)).WithTitle("Downloading stuff").Start() - - for i := 0; i < p.Total; i++ { - p.UpdateTitle("Downloading " + fakeInstallList[i]) // Update the title of the progressbar. - pterm.Success.Println("Downloading " + fakeInstallList[i]) // If a progressbar is running, each print will be printed above the progressbar. - p.Increment() // Increment the progressbar by one. Use Add(x int) to increment by a custom amount. - time.Sleep(time.Millisecond * 350) // Sleep 350 milliseconds. - } -} - -``` +# progressbar + +![Animation](animation.svg) + +```go +package main + +import ( + "strings" + "time" + + "github.com/pterm/pterm" +) + +// Slice of strings with placeholder text. +var fakeInstallList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+ + "pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ") + +func main() { + // Create progressbar as fork from the default progressbar. + p, _ := pterm.DefaultProgressbar.WithTotal(len(fakeInstallList)).WithTitle("Downloading stuff").Start() + + for i := 0; i < p.Total; i++ { + p.UpdateTitle("Downloading " + fakeInstallList[i]) // Update the title of the progressbar. + pterm.Success.Println("Downloading " + fakeInstallList[i]) // If a progressbar is running, each print will be printed above the progressbar. + p.Increment() // Increment the progressbar by one. Use Add(x int) to increment by a custom amount. + time.Sleep(time.Millisecond * 350) // Sleep 350 milliseconds. + } +} + +``` diff --git a/_examples/progressbar/animation.svg b/_examples/progressbar/demo/animation.svg similarity index 100% rename from _examples/progressbar/animation.svg rename to _examples/progressbar/demo/animation.svg diff --git a/_examples/progressbar/main.go b/_examples/progressbar/demo/main.go similarity index 100% rename from _examples/progressbar/main.go rename to _examples/progressbar/demo/main.go diff --git a/_examples/section/README.md b/_examples/section/demo/README.md similarity index 95% rename from _examples/section/README.md rename to _examples/section/demo/README.md index 2a912ee3d..dd04dbf02 100644 --- a/_examples/section/README.md +++ b/_examples/section/demo/README.md @@ -1,22 +1,22 @@ -# section - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Print a section with level one. - pterm.DefaultSection.Println("This is a section!") - // Print placeholder. - pterm.Info.Println("And here is some text.\nThis text could be anything.\nBasically it's just a placeholder") - - // Print a section with level two. - pterm.DefaultSection.WithLevel(2).Println("This is another section!") - // Print placeholder. - pterm.Info.Println("And this is\nmore placeholder text") -} - -``` +# section + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Print a section with level one. + pterm.DefaultSection.Println("This is a section!") + // Print placeholder. + pterm.Info.Println("And here is some text.\nThis text could be anything.\nBasically it's just a placeholder") + + // Print a section with level two. + pterm.DefaultSection.WithLevel(2).Println("This is another section!") + // Print placeholder. + pterm.Info.Println("And this is\nmore placeholder text") +} + +``` diff --git a/_examples/section/animation.svg b/_examples/section/demo/animation.svg similarity index 100% rename from _examples/section/animation.svg rename to _examples/section/demo/animation.svg diff --git a/_examples/section/main.go b/_examples/section/demo/main.go similarity index 100% rename from _examples/section/main.go rename to _examples/section/demo/main.go diff --git a/_examples/spinner/README.md b/_examples/spinner/demo/README.md similarity index 97% rename from _examples/spinner/README.md rename to _examples/spinner/demo/README.md index b20f24319..95583c282 100644 --- a/_examples/spinner/README.md +++ b/_examples/spinner/demo/README.md @@ -1,40 +1,40 @@ -# spinner - -![Animation](animation.svg) - -```go -package main - -import ( - "time" - - "github.com/pterm/pterm" -) - -func main() { - // Create and start a fork of the default spinner. - spinnerSuccess, _ := pterm.DefaultSpinner.Start("Doing something important... (will succeed)") - time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something. - spinnerSuccess.Success() // Resolve spinner with success message. - - // Create and start a fork of the default spinner. - spinnerWarning, _ := pterm.DefaultSpinner.Start("Doing something important... (will warn)") - time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something. - spinnerWarning.Warning() // Resolve spinner with warning message. - - // Create and start a fork of the default spinner. - spinnerFail, _ := pterm.DefaultSpinner.Start("Doing something important... (will fail)") - time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something. - spinnerFail.Fail() // Resolve spinner with error message. - - // Create and start a fork of the default spinner. - spinnerLiveText, _ := pterm.DefaultSpinner.Start("Doing a lot of stuff...") - time.Sleep(time.Second) // Simulate 2 seconds of processing something. - spinnerLiveText.UpdateText("It's really much") // Update spinner text. - time.Sleep(time.Second) // Simulate 2 seconds of processing something. - spinnerLiveText.UpdateText("We're nearly done!") // Update spinner text. - time.Sleep(time.Second) // Simulate 2 seconds of processing something. - spinnerLiveText.Success("Finally!") // Resolve spinner with success message. -} - -``` +# spinner + +![Animation](animation.svg) + +```go +package main + +import ( + "time" + + "github.com/pterm/pterm" +) + +func main() { + // Create and start a fork of the default spinner. + spinnerSuccess, _ := pterm.DefaultSpinner.Start("Doing something important... (will succeed)") + time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something. + spinnerSuccess.Success() // Resolve spinner with success message. + + // Create and start a fork of the default spinner. + spinnerWarning, _ := pterm.DefaultSpinner.Start("Doing something important... (will warn)") + time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something. + spinnerWarning.Warning() // Resolve spinner with warning message. + + // Create and start a fork of the default spinner. + spinnerFail, _ := pterm.DefaultSpinner.Start("Doing something important... (will fail)") + time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something. + spinnerFail.Fail() // Resolve spinner with error message. + + // Create and start a fork of the default spinner. + spinnerLiveText, _ := pterm.DefaultSpinner.Start("Doing a lot of stuff...") + time.Sleep(time.Second) // Simulate 2 seconds of processing something. + spinnerLiveText.UpdateText("It's really much") // Update spinner text. + time.Sleep(time.Second) // Simulate 2 seconds of processing something. + spinnerLiveText.UpdateText("We're nearly done!") // Update spinner text. + time.Sleep(time.Second) // Simulate 2 seconds of processing something. + spinnerLiveText.Success("Finally!") // Resolve spinner with success message. +} + +``` diff --git a/_examples/spinner/animation.svg b/_examples/spinner/demo/animation.svg similarity index 100% rename from _examples/spinner/animation.svg rename to _examples/spinner/demo/animation.svg diff --git a/_examples/spinner/main.go b/_examples/spinner/demo/main.go similarity index 100% rename from _examples/spinner/main.go rename to _examples/spinner/demo/main.go diff --git a/_examples/style/README.md b/_examples/style/demo/README.md similarity index 95% rename from _examples/style/README.md rename to _examples/style/demo/README.md index ab8bee029..1b11de92e 100644 --- a/_examples/style/README.md +++ b/_examples/style/demo/README.md @@ -1,20 +1,20 @@ -# style - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Create styles as new variables - primary := pterm.NewStyle(pterm.FgLightCyan, pterm.BgGray, pterm.Bold) - secondary := pterm.NewStyle(pterm.FgLightGreen, pterm.BgWhite, pterm.Italic) - - // Use created styles - primary.Println("Hello, World!") - secondary.Println("Hello, World!") -} - -``` +# style + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Create styles as new variables + primary := pterm.NewStyle(pterm.FgLightCyan, pterm.BgGray, pterm.Bold) + secondary := pterm.NewStyle(pterm.FgLightGreen, pterm.BgWhite, pterm.Italic) + + // Use created styles + primary.Println("Hello, World!") + secondary.Println("Hello, World!") +} + +``` diff --git a/_examples/style/animation.svg b/_examples/style/demo/animation.svg similarity index 100% rename from _examples/style/animation.svg rename to _examples/style/demo/animation.svg diff --git a/_examples/style/main.go b/_examples/style/demo/main.go similarity index 100% rename from _examples/style/main.go rename to _examples/style/demo/main.go diff --git a/_examples/table/README.md b/_examples/table/demo/README.md similarity index 96% rename from _examples/table/README.md rename to _examples/table/demo/README.md index 54abfb276..23ed3fba8 100644 --- a/_examples/table/README.md +++ b/_examples/table/demo/README.md @@ -1,31 +1,31 @@ -# table - -![Animation](animation.svg) - -```go -package main - -import "github.com/pterm/pterm" - -func main() { - // Create a fork of the default table, fill it with data and print it. - // Data can also be generated and inserted later. - pterm.DefaultTable.WithHasHeader().WithData(pterm.TableData{ - {"Firstname", "Lastname", "Email"}, - {"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"}, - {"Callie", "Mckay", "egestas.nunc.sed@est.com"}, - {"Libby", "Camacho", "aliquet.lobortis@semper.com"}, - }).Render() - - pterm.Println() // Blank line - - // Create a table with right alignment. - pterm.DefaultTable.WithHasHeader().WithData(pterm.TableData{ - {"Firstname", "Lastname", "Email"}, - {"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"}, - {"Callie", "Mckay", "egestas.nunc.sed@est.com"}, - {"Libby", "Camacho", "aliquet.lobortis@semper.com"}, - }).WithRightAlignment().Render() -} - -``` +# table + +![Animation](animation.svg) + +```go +package main + +import "github.com/pterm/pterm" + +func main() { + // Create a fork of the default table, fill it with data and print it. + // Data can also be generated and inserted later. + pterm.DefaultTable.WithHasHeader().WithData(pterm.TableData{ + {"Firstname", "Lastname", "Email"}, + {"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"}, + {"Callie", "Mckay", "egestas.nunc.sed@est.com"}, + {"Libby", "Camacho", "aliquet.lobortis@semper.com"}, + }).Render() + + pterm.Println() // Blank line + + // Create a table with right alignment. + pterm.DefaultTable.WithHasHeader().WithData(pterm.TableData{ + {"Firstname", "Lastname", "Email"}, + {"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"}, + {"Callie", "Mckay", "egestas.nunc.sed@est.com"}, + {"Libby", "Camacho", "aliquet.lobortis@semper.com"}, + }).WithRightAlignment().Render() +} + +``` diff --git a/_examples/table/negative-values/animation.svg b/_examples/table/demo/animation.svg similarity index 100% rename from _examples/table/negative-values/animation.svg rename to _examples/table/demo/animation.svg diff --git a/_examples/table/main.go b/_examples/table/demo/main.go similarity index 100% rename from _examples/table/main.go rename to _examples/table/demo/main.go diff --git a/_examples/theme/README.md b/_examples/theme/demo/README.md similarity index 95% rename from _examples/theme/README.md rename to _examples/theme/demo/README.md index e4bc59cb4..2d4de7678 100644 --- a/_examples/theme/README.md +++ b/_examples/theme/demo/README.md @@ -1,37 +1,37 @@ -# theme - -![Animation](animation.svg) - -```go -package main - -import ( - "github.com/pterm/pterm" - "reflect" - "time" -) - -func main() { - // Print info. - pterm.Info.Println("These are the default theme styles.\n" + - "You can modify them easily to your personal preference,\n" + - "or create new themes from scratch :)") - - pterm.Println() // Print one line space. - - // Print every value of the default theme with its own style. - v := reflect.ValueOf(pterm.ThemeDefault) - typeOfS := v.Type() - - if typeOfS == reflect.TypeOf(pterm.Theme{}) { - for i := 0; i < v.NumField(); i++ { - field, ok := v.Field(i).Interface().(pterm.Style) - if ok { - field.Println(typeOfS.Field(i).Name) - } - time.Sleep(time.Millisecond * 250) - } - } -} - -``` +# theme + +![Animation](animation.svg) + +```go +package main + +import ( + "github.com/pterm/pterm" + "reflect" + "time" +) + +func main() { + // Print info. + pterm.Info.Println("These are the default theme styles.\n" + + "You can modify them easily to your personal preference,\n" + + "or create new themes from scratch :)") + + pterm.Println() // Print one line space. + + // Print every value of the default theme with its own style. + v := reflect.ValueOf(pterm.ThemeDefault) + typeOfS := v.Type() + + if typeOfS == reflect.TypeOf(pterm.Theme{}) { + for i := 0; i < v.NumField(); i++ { + field, ok := v.Field(i).Interface().(pterm.Style) + if ok { + field.Println(typeOfS.Field(i).Name) + } + time.Sleep(time.Millisecond * 250) + } + } +} + +``` diff --git a/_examples/theme/animation.svg b/_examples/theme/demo/animation.svg similarity index 100% rename from _examples/theme/animation.svg rename to _examples/theme/demo/animation.svg diff --git a/_examples/theme/main.go b/_examples/theme/demo/main.go similarity index 100% rename from _examples/theme/main.go rename to _examples/theme/demo/main.go diff --git a/_examples/tree/README.md b/_examples/tree/demo/README.md similarity index 97% rename from _examples/tree/README.md rename to _examples/tree/demo/README.md index 4f77dcb24..7a9eab639 100644 --- a/_examples/tree/README.md +++ b/_examples/tree/demo/README.md @@ -1,46 +1,46 @@ -# tree - -![Animation](animation.svg) - -```go -package main - -import ( - "github.com/pterm/pterm" -) - -func main() { - // You can use a LeveledList here, for easy generation. - leveledList := pterm.LeveledList{ - pterm.LeveledListItem{Level: 0, Text: "C:"}, - pterm.LeveledListItem{Level: 1, Text: "Users"}, - pterm.LeveledListItem{Level: 1, Text: "Windows"}, - pterm.LeveledListItem{Level: 1, Text: "Programs"}, - pterm.LeveledListItem{Level: 1, Text: "Programs(x86)"}, - pterm.LeveledListItem{Level: 1, Text: "dev"}, - pterm.LeveledListItem{Level: 0, Text: "D:"}, - pterm.LeveledListItem{Level: 0, Text: "E:"}, - pterm.LeveledListItem{Level: 1, Text: "Movies"}, - pterm.LeveledListItem{Level: 1, Text: "Music"}, - pterm.LeveledListItem{Level: 2, Text: "LinkinPark"}, - pterm.LeveledListItem{Level: 1, Text: "Games"}, - pterm.LeveledListItem{Level: 2, Text: "Shooter"}, - pterm.LeveledListItem{Level: 3, Text: "CallOfDuty"}, - pterm.LeveledListItem{Level: 3, Text: "CS:GO"}, - pterm.LeveledListItem{Level: 3, Text: "Battlefield"}, - pterm.LeveledListItem{Level: 4, Text: "Battlefield 1"}, - pterm.LeveledListItem{Level: 4, Text: "Battlefield 2"}, - pterm.LeveledListItem{Level: 0, Text: "F:"}, - pterm.LeveledListItem{Level: 1, Text: "dev"}, - pterm.LeveledListItem{Level: 2, Text: "dops"}, - pterm.LeveledListItem{Level: 2, Text: "PTerm"}, - } - - // Generate tree from LeveledList. - root := pterm.NewTreeFromLeveledList(leveledList) - - // Render TreePrinter - pterm.DefaultTree.WithRoot(root).Render() -} - -``` +# tree + +![Animation](animation.svg) + +```go +package main + +import ( + "github.com/pterm/pterm" +) + +func main() { + // You can use a LeveledList here, for easy generation. + leveledList := pterm.LeveledList{ + pterm.LeveledListItem{Level: 0, Text: "C:"}, + pterm.LeveledListItem{Level: 1, Text: "Users"}, + pterm.LeveledListItem{Level: 1, Text: "Windows"}, + pterm.LeveledListItem{Level: 1, Text: "Programs"}, + pterm.LeveledListItem{Level: 1, Text: "Programs(x86)"}, + pterm.LeveledListItem{Level: 1, Text: "dev"}, + pterm.LeveledListItem{Level: 0, Text: "D:"}, + pterm.LeveledListItem{Level: 0, Text: "E:"}, + pterm.LeveledListItem{Level: 1, Text: "Movies"}, + pterm.LeveledListItem{Level: 1, Text: "Music"}, + pterm.LeveledListItem{Level: 2, Text: "LinkinPark"}, + pterm.LeveledListItem{Level: 1, Text: "Games"}, + pterm.LeveledListItem{Level: 2, Text: "Shooter"}, + pterm.LeveledListItem{Level: 3, Text: "CallOfDuty"}, + pterm.LeveledListItem{Level: 3, Text: "CS:GO"}, + pterm.LeveledListItem{Level: 3, Text: "Battlefield"}, + pterm.LeveledListItem{Level: 4, Text: "Battlefield 1"}, + pterm.LeveledListItem{Level: 4, Text: "Battlefield 2"}, + pterm.LeveledListItem{Level: 0, Text: "F:"}, + pterm.LeveledListItem{Level: 1, Text: "dev"}, + pterm.LeveledListItem{Level: 2, Text: "dops"}, + pterm.LeveledListItem{Level: 2, Text: "PTerm"}, + } + + // Generate tree from LeveledList. + root := pterm.NewTreeFromLeveledList(leveledList) + + // Render TreePrinter + pterm.DefaultTree.WithRoot(root).Render() +} + +``` diff --git a/_examples/tree/animation.svg b/_examples/tree/demo/animation.svg similarity index 100% rename from _examples/tree/animation.svg rename to _examples/tree/demo/animation.svg diff --git a/_examples/tree/negative-values/main.go b/_examples/tree/demo/main.go similarity index 100% rename from _examples/tree/negative-values/main.go rename to _examples/tree/demo/main.go