commit 3dfda0a274e04a1429f1fcb8a31555bda98c6c06
parent 4837130a3e1358de58b2ce3e8c8a24497b2ca89a
Author: dwrz <dwrz@dwrz.net>
Date: Tue, 30 May 2023 01:14:32 +0000
Refactor wisdom to use terminal size
Diffstat:
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/cmd/wisdom/wisdom.go b/cmd/wisdom/wisdom.go
@@ -20,21 +20,29 @@ func main() {
l.Error.Fatalf("failed to get user config dir: %v", err)
}
+ var params = wisdom.Parameters{
+ Log: l,
+ Path: filepath.Join(dir, "wisdom"),
+ }
+
terminal, err := terminal.New(os.Stdin.Fd())
if err != nil {
- l.Error.Fatalf("failed to create terminal: %v", err)
+ l.Error.Printf("failed to create terminal: %v", err)
}
- size, err := terminal.Size()
- if err != nil {
- l.Error.Fatalf("failed to get terminal size: %v", err)
+ if terminal != nil {
+ size, err := terminal.Size()
+ if err != nil {
+ l.Error.Printf("failed to get terminal size: %v", err)
+ }
+
+ params.Size = *size
}
- w, err := wisdom.New(wisdom.Parameters{
- Log: l,
- Path: filepath.Join(dir, "wisdom"),
- Size: size,
- })
+ w, err := wisdom.New(params)
+ if err != nil {
+ l.Error.Fatalf("failed to create command: %v", err)
+ }
if err := w.Command(flag.CommandLine.Args()); err != nil {
l.Error.Fatal(err)
diff --git a/pkg/wisdom/wisdom.go b/pkg/wisdom/wisdom.go
@@ -26,13 +26,13 @@ const coll = "data"
type Parameters struct {
Log *log.Logger
Path string
- Size *terminal.Size
+ Size terminal.Size
}
type Wisdom struct {
log *log.Logger
store *store.Store
- size *terminal.Size
+ size terminal.Size
}
func New(p Parameters) (*Wisdom, error) {