commit f80c4ca3806dc74b2159f3fbf59a7b119c9bb7d8
parent 79ce513f3ab61b9a3cb5ca539ad03ed007a8a8ba
Author: dwrz <dwrz@dwrz.net>
Date: Fri, 2 Dec 2022 16:21:25 +0000
Add wen cmd
Diffstat:
A | cmd/wen/main.go | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/cmd/wen/main.go b/cmd/wen/main.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+
+ "code.dwrz.net/src/pkg/editor"
+ "code.dwrz.net/src/pkg/log"
+ "code.dwrz.net/src/pkg/terminal"
+)
+
+func main() {
+ var l = log.New(os.Stderr)
+
+ // Setup workspace and log file.
+ cdir, err := os.UserCacheDir()
+ if err != nil {
+ l.Error.Fatalf(
+ "failed to determine user cache directory: %v", err,
+ )
+ }
+ wdir := filepath.Join(cdir, "wen")
+
+ if err := os.MkdirAll(wdir, os.ModeDir|0700); err != nil {
+ l.Error.Fatalf("failed to create tmp dir: %v", err)
+ }
+
+ f, err := os.Create(wdir + "/log")
+ if err != nil {
+ l.Error.Fatalf("failed to create log file: %v", err)
+ }
+ defer f.Close()
+
+ // Retrieve terminal info.
+ t, err := terminal.New(os.Stdin.Fd())
+ if err != nil {
+ l.Error.Fatalf("failed to get terminal attributes: %v", err)
+ }
+
+ // Create the editor.
+ editor, err := editor.New(editor.Parameters{
+ In: os.Stdin,
+ Log: log.New(f),
+ Out: os.Stdout,
+ Terminal: t,
+ })
+ if err != nil {
+ l.Error.Fatalf("failed to create editor: %v", err)
+ }
+
+ // TODO: handle signals, sigwinch.
+
+ // Run the editor.
+ if err := editor.Run(os.Args[1:]); err != nil {
+ l.Error.Fatal(err)
+ }
+}