Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (69 loc) · 1.92 KB
/
Copy pathmain.go
File metadata and controls
81 lines (69 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Command gojo is a fullscreen terminal UI for jj (Jujutsu VCS).
package main
import (
_ "embed"
"flag"
"fmt"
"io"
"os"
tea "charm.land/bubbletea/v2"
"gojo/internal/programstatus"
"gojo/internal/ui"
)
// version is set at build time via ldflags (e.g. by goreleaser). It defaults
// to "dev" for `go run` / `go build` without flags.
var version = "dev"
//go:embed CHANGELOG.md
var changelog string
func main() {
handled, err := handleFlags(os.Args[1:], os.Stdout, os.Stderr)
if err != nil {
if err == flag.ErrHelp {
return
}
os.Exit(2)
}
if handled {
return
}
if err := runTUI(); err != nil {
fmt.Fprintln(os.Stderr, "fatal:", err)
os.Exit(1)
}
}
func runTUI() error {
// Ask the terminal to report OS dark/light scheme changes as DSR replies
// (xterm mode 2031; supported by kitty, Ghostty, VTE, Contour, …). The UI
// handles Bubble Tea's parsed scheme events and re-themes (see
// internal/ui/darkmode.go). Terminals without
// support ignore the mode silently.
fmt.Fprint(os.Stdout, "\x1b[?2031h")
defer fmt.Fprint(os.Stdout, "\x1b[?2031l")
// A quit or interrupt cancels any in-flight work, including after Run errors.
defer fmt.Fprint(os.Stdout, programstatus.Report{State: "idle"}.Sequence())
p := tea.NewProgram(
ui.NewModel(),
)
_, err := p.Run()
return err
}
func handleFlags(args []string, stdout, stderr io.Writer) (bool, error) {
flags := flag.NewFlagSet("gojo", flag.ContinueOnError)
flags.SetOutput(stderr)
var showVersion bool
flags.BoolVar(&showVersion, "version", false, "print version and exit")
flags.BoolVar(&showVersion, "v", false, "print version and exit")
showChangelog := flags.Bool("changelog", false, "print changelog and exit")
if err := flags.Parse(args); err != nil {
return true, err
}
if showVersion {
fmt.Fprintln(stdout, "gojo", version)
return true, nil
}
if *showChangelog {
fmt.Fprint(stdout, changelog)
return true, nil
}
return false, nil
}