Skip to content

Commit

Permalink
feat: add tapes and .go examples (#5)
Browse files Browse the repository at this point in the history
* feat: add tapes and .go examples

* move to directories

* add binaries to gitignore
  • Loading branch information
maaslalani authored Feb 21, 2023
1 parent fcc8d9c commit 64474a3
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
*.txt
*.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
8 changes: 8 additions & 0 deletions examples/batch2/batch2.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output batch2.gif

Set Height 300
Set Width 1100

Type "./batch2" Sleep 500ms Enter

Sleep 4s
20 changes: 20 additions & 0 deletions examples/chocolate-chips/chocolate-chips.go
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions examples/cookie/cookie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "github.com/charmbracelet/log"

func main() {
log.Debug("Cookie 🍪")
log.Info("Hello World!")
}
8 changes: 8 additions & 0 deletions examples/cookie/cookie.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output cookie.gif

Set Height 250
Set Width 700

Type "./cookie" Sleep 500ms Enter

Sleep 3s
12 changes: 12 additions & 0 deletions examples/error/error.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions examples/error/error.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output error.gif

Set Height 250
Set Width 1100

Type "./error" Sleep 500ms Enter

Sleep 3s
15 changes: 15 additions & 0 deletions examples/format/format.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 8 additions & 0 deletions examples/format/format.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output format.gif

Set Height 400
Set Width 800

Type "./format" Sleep 500ms Enter

Sleep 6s
7 changes: 7 additions & 0 deletions examples/log/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "log"

func main() {
log.Print("Baking 101")
}
8 changes: 8 additions & 0 deletions examples/log/log.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output log.gif

Set Height 250
Set Width 800

Type "./log" Sleep 500ms Enter

Sleep 3s
8 changes: 8 additions & 0 deletions examples/new/new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "github.com/charmbracelet/log"

func main() {
logger := log.New()
logger.Warn("chewy!", "butter", true)
}
8 changes: 8 additions & 0 deletions examples/new/new.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output new.gif

Set Height 250
Set Width 500

Type "./new" Sleep 500ms Enter

Sleep 3s
16 changes: 16 additions & 0 deletions examples/options/options-2.go
Original file line number Diff line number Diff line change
@@ -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...}
}
15 changes: 15 additions & 0 deletions examples/options/options.go
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions examples/options/options.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output options.gif

Set Height 300
Set Width 1200

Type "./options" Sleep 500ms Enter

Sleep 6s
13 changes: 13 additions & 0 deletions examples/oven/oven.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions examples/oven/oven.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output oven.gif

Set Height 250
Set Width 1200

Type "./oven" Sleep 500ms Enter

Sleep 3s
15 changes: 15 additions & 0 deletions examples/temperature/temperature.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 8 additions & 0 deletions examples/temperature/temperature.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Output temperature.gif

Set Height 400
Set Width 1100

Type "./temperature" Sleep 500ms Enter

Sleep 6s

0 comments on commit 64474a3

Please sign in to comment.