From 64474a3cf766a7d866be19612cacbd2b8d86bb9d Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Tue, 21 Feb 2023 08:22:15 -0500 Subject: [PATCH] feat: add tapes and .go examples (#5) * feat: add tapes and .go examples * move to directories * add binaries to gitignore --- .gitignore | 14 +++++++++++++- examples/batch2/batch2.tape | 8 ++++++++ examples/chocolate-chips/chocolate-chips.go | 20 ++++++++++++++++++++ examples/cookie/cookie.go | 8 ++++++++ examples/cookie/cookie.tape | 8 ++++++++ examples/error/error.go | 12 ++++++++++++ examples/error/error.tape | 8 ++++++++ examples/format/format.go | 15 +++++++++++++++ examples/format/format.tape | 8 ++++++++ examples/log/log.go | 7 +++++++ examples/log/log.tape | 8 ++++++++ examples/new/new.go | 8 ++++++++ examples/new/new.tape | 8 ++++++++ examples/options/options-2.go | 16 ++++++++++++++++ examples/options/options.go | 15 +++++++++++++++ examples/options/options.tape | 8 ++++++++ examples/oven/oven.go | 13 +++++++++++++ examples/oven/oven.tape | 8 ++++++++ examples/temperature/temperature.go | 15 +++++++++++++++ examples/temperature/temperature.tape | 8 ++++++++ 20 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 examples/batch2/batch2.tape create mode 100644 examples/chocolate-chips/chocolate-chips.go create mode 100644 examples/cookie/cookie.go create mode 100644 examples/cookie/cookie.tape create mode 100644 examples/error/error.go create mode 100644 examples/error/error.tape create mode 100644 examples/format/format.go create mode 100644 examples/format/format.tape create mode 100644 examples/log/log.go create mode 100644 examples/log/log.tape create mode 100644 examples/new/new.go create mode 100644 examples/new/new.tape create mode 100644 examples/options/options-2.go create mode 100644 examples/options/options.go create mode 100644 examples/options/options.tape create mode 100644 examples/oven/oven.go create mode 100644 examples/oven/oven.tape create mode 100644 examples/temperature/temperature.go create mode 100644 examples/temperature/temperature.tape diff --git a/.gitignore b/.gitignore index 314f02b..25cfa0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,13 @@ -*.txt \ No newline at end of file +*.txt +*.gif + +examples/batch2/batch2 +examples/chocolate-chips/chocolate-chips +examples/cookie/cookie +examples/error/error +examples/format/format +examples/log/log +examples/new/new +examples/options/options +examples/oven/oven +examples/temperature/temperature diff --git a/examples/batch2/batch2.tape b/examples/batch2/batch2.tape new file mode 100644 index 0000000..5cb72db --- /dev/null +++ b/examples/batch2/batch2.tape @@ -0,0 +1,8 @@ +Output batch2.gif + +Set Height 300 +Set Width 1100 + +Type "./batch2" Sleep 500ms Enter + +Sleep 4s diff --git a/examples/chocolate-chips/chocolate-chips.go b/examples/chocolate-chips/chocolate-chips.go new file mode 100644 index 0000000..64f39e1 --- /dev/null +++ b/examples/chocolate-chips/chocolate-chips.go @@ -0,0 +1,20 @@ +package main + +import ( + "time" + + "github.com/charmbracelet/log" +) + +func main() { + logger := log.New(log.WithTimestamp(), log.WithTimeFormat(time.Kitchen), + log.WithCaller(), log.WithPrefix("Baking 🍪 ")) + + logger.SetReportTimestamp(false) + logger.SetReportCaller(false) + logger.SetLevel(log.DebugLevel) + logger.Debug("Preparing batch 2...") // DEBUG baking 🍪: Preparing batch 2...} + + batch2 := logger.With("batch", 2, "chocolateChips", true) + batch2.Debug("Adding chocolate chips") +} diff --git a/examples/cookie/cookie.go b/examples/cookie/cookie.go new file mode 100644 index 0000000..94da810 --- /dev/null +++ b/examples/cookie/cookie.go @@ -0,0 +1,8 @@ +package main + +import "github.com/charmbracelet/log" + +func main() { + log.Debug("Cookie 🍪") + log.Info("Hello World!") +} diff --git a/examples/cookie/cookie.tape b/examples/cookie/cookie.tape new file mode 100644 index 0000000..683523c --- /dev/null +++ b/examples/cookie/cookie.tape @@ -0,0 +1,8 @@ +Output cookie.gif + +Set Height 250 +Set Width 700 + +Type "./cookie" Sleep 500ms Enter + +Sleep 3s diff --git a/examples/error/error.go b/examples/error/error.go new file mode 100644 index 0000000..3bcbd22 --- /dev/null +++ b/examples/error/error.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" + + "github.com/charmbracelet/log" +) + +func main() { + err := fmt.Errorf("too much sugar") + log.Error("failed to bake cookies", "err", err) +} diff --git a/examples/error/error.tape b/examples/error/error.tape new file mode 100644 index 0000000..384d826 --- /dev/null +++ b/examples/error/error.tape @@ -0,0 +1,8 @@ +Output error.gif + +Set Height 250 +Set Width 1100 + +Type "./error" Sleep 500ms Enter + +Sleep 3s diff --git a/examples/format/format.go b/examples/format/format.go new file mode 100644 index 0000000..7dca763 --- /dev/null +++ b/examples/format/format.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "time" + + "github.com/charmbracelet/log" +) + +func main() { + for item := 1; item <= 100; item++ { + log.Info(fmt.Sprintf("Baking %d / 100 ...", item)) + time.Sleep(100 * time.Millisecond) + } +} diff --git a/examples/format/format.tape b/examples/format/format.tape new file mode 100644 index 0000000..b4238f5 --- /dev/null +++ b/examples/format/format.tape @@ -0,0 +1,8 @@ +Output format.gif + +Set Height 400 +Set Width 800 + +Type "./format" Sleep 500ms Enter + +Sleep 6s diff --git a/examples/log/log.go b/examples/log/log.go new file mode 100644 index 0000000..80f81e8 --- /dev/null +++ b/examples/log/log.go @@ -0,0 +1,7 @@ +package main + +import "log" + +func main() { + log.Print("Baking 101") +} diff --git a/examples/log/log.tape b/examples/log/log.tape new file mode 100644 index 0000000..3a07dc2 --- /dev/null +++ b/examples/log/log.tape @@ -0,0 +1,8 @@ +Output log.gif + +Set Height 250 +Set Width 800 + +Type "./log" Sleep 500ms Enter + +Sleep 3s diff --git a/examples/new/new.go b/examples/new/new.go new file mode 100644 index 0000000..685b240 --- /dev/null +++ b/examples/new/new.go @@ -0,0 +1,8 @@ +package main + +import "github.com/charmbracelet/log" + +func main() { + logger := log.New() + logger.Warn("chewy!", "butter", true) +} diff --git a/examples/new/new.tape b/examples/new/new.tape new file mode 100644 index 0000000..5832a22 --- /dev/null +++ b/examples/new/new.tape @@ -0,0 +1,8 @@ +Output new.gif + +Set Height 250 +Set Width 500 + +Type "./new" Sleep 500ms Enter + +Sleep 3s diff --git a/examples/options/options-2.go b/examples/options/options-2.go new file mode 100644 index 0000000..f63761e --- /dev/null +++ b/examples/options/options-2.go @@ -0,0 +1,16 @@ +package main + +import ( + "time" + + "github.com/charmbracelet/log" +) + +func main() { + logger := log.New(log.WithTimestamp(), log.WithTimeFormat(time.Kitchen), + log.WithCaller(), log.WithPrefix("baking 🍪")) + logger.SetReportTimestamp(false) + logger.SetReportCaller(false) + logger.SetLevel(log.DebugLevel) + logger.Debug("Preparing batch 2...") // DEBUG baking 🍪: Preparing batch 2...} +} diff --git a/examples/options/options.go b/examples/options/options.go new file mode 100644 index 0000000..c3711a6 --- /dev/null +++ b/examples/options/options.go @@ -0,0 +1,15 @@ +package main + +import ( + "time" + + "github.com/charmbracelet/log" +) + +func main() { + logger := log.New(log.WithTimestamp(), log.WithTimeFormat(time.Kitchen), + log.WithCaller(), log.WithPrefix("Baking 🍪 ")) + logger.Info("Starting oven!", "degree", 375) + time.Sleep(3 * time.Second) + logger.Info("Finished baking") +} diff --git a/examples/options/options.tape b/examples/options/options.tape new file mode 100644 index 0000000..f7bdbb1 --- /dev/null +++ b/examples/options/options.tape @@ -0,0 +1,8 @@ +Output options.gif + +Set Height 300 +Set Width 1200 + +Type "./options" Sleep 500ms Enter + +Sleep 6s diff --git a/examples/oven/oven.go b/examples/oven/oven.go new file mode 100644 index 0000000..19e68aa --- /dev/null +++ b/examples/oven/oven.go @@ -0,0 +1,13 @@ +package main + +import "github.com/charmbracelet/log" + +func startOven(degree int) { + log.Helper() + log.Info("Starting oven", "degree", degree) +} + +func main() { + log.SetReportCaller(true) + startOven(400) +} diff --git a/examples/oven/oven.tape b/examples/oven/oven.tape new file mode 100644 index 0000000..bd755f9 --- /dev/null +++ b/examples/oven/oven.tape @@ -0,0 +1,8 @@ +Output oven.gif + +Set Height 250 +Set Width 1200 + +Type "./oven" Sleep 500ms Enter + +Sleep 3s diff --git a/examples/temperature/temperature.go b/examples/temperature/temperature.go new file mode 100644 index 0000000..20f522c --- /dev/null +++ b/examples/temperature/temperature.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "time" + + "github.com/charmbracelet/log" +) + +func main() { + for temp := 375; temp <= 400; temp++ { + log.Info("Increasing temperature", "degree", fmt.Sprintf("%d°F", temp)) + time.Sleep(100 * time.Millisecond) + } +} diff --git a/examples/temperature/temperature.tape b/examples/temperature/temperature.tape new file mode 100644 index 0000000..244552b --- /dev/null +++ b/examples/temperature/temperature.tape @@ -0,0 +1,8 @@ +Output temperature.gif + +Set Height 400 +Set Width 1100 + +Type "./temperature" Sleep 500ms Enter + +Sleep 6s