summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/zed/internal/console/console.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
committermo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
commit20ef0d92694465ac86b550df139e8366a0a2b4fa (patch)
tree3f14589e1ce6eb9306a3af31c3a1f9e1af5ed637 /vendor/github.com/authzed/zed/internal/console/console.go
parent44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff)
feat: connect to spicedb
Diffstat (limited to 'vendor/github.com/authzed/zed/internal/console/console.go')
-rw-r--r--vendor/github.com/authzed/zed/internal/console/console.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/zed/internal/console/console.go b/vendor/github.com/authzed/zed/internal/console/console.go
new file mode 100644
index 0000000..53f815c
--- /dev/null
+++ b/vendor/github.com/authzed/zed/internal/console/console.go
@@ -0,0 +1,60 @@
+package console
+
+import (
+ "fmt"
+ "os"
+ "time"
+
+ "github.com/mattn/go-isatty"
+ "github.com/schollz/progressbar/v3"
+)
+
+// Printf defines an (overridable) function for printing to the console via stdout.
+var Printf = func(format string, a ...any) {
+ fmt.Printf(format, a...)
+}
+
+var Print = func(a ...any) {
+ fmt.Print(a...)
+}
+
+// Errorf defines an (overridable) function for printing to the console via stderr.
+var Errorf = func(format string, a ...any) {
+ _, err := fmt.Fprintf(os.Stderr, format, a...)
+ if err != nil {
+ panic(err)
+ }
+}
+
+// Println prints a line with optional values to the console.
+var Println = func(values ...any) {
+ for _, value := range values {
+ Printf("%v\n", value)
+ }
+}
+
+// CreateProgressBar creates a new progress bar with the given description and defaults adjusted to zed's UX experience
+func CreateProgressBar(description string) *progressbar.ProgressBar {
+ bar := progressbar.NewOptions(-1,
+ progressbar.OptionSetWidth(10),
+ progressbar.OptionSetRenderBlankState(true),
+ progressbar.OptionSetVisibility(false),
+ )
+ if isatty.IsTerminal(os.Stderr.Fd()) {
+ bar = progressbar.NewOptions64(-1,
+ progressbar.OptionSetDescription(description),
+ progressbar.OptionSetWriter(os.Stderr),
+ progressbar.OptionSetWidth(10),
+ progressbar.OptionThrottle(65*time.Millisecond),
+ progressbar.OptionShowCount(),
+ progressbar.OptionShowIts(),
+ progressbar.OptionSetItsString("relationship"),
+ progressbar.OptionOnCompletion(func() { _, _ = fmt.Fprint(os.Stderr, "\n") }),
+ progressbar.OptionSpinnerType(14),
+ progressbar.OptionFullWidth(),
+ progressbar.OptionSetRenderBlankState(true),
+ )
+ }
+
+ return bar
+}