-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (52 loc) · 1.48 KB
/
main.go
File metadata and controls
63 lines (52 loc) · 1.48 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
package main
import (
"flag"
"fmt"
"os"
"atlas.cat/internal/ui"
"atlas.cat/internal/viewer"
tea "github.com/charmbracelet/bubbletea"
)
var Version = "dev"
func main() {
showVersion := flag.Bool("v", false, "Show version")
showVersionLong := flag.Bool("version", false, "Show version")
noInteractive := flag.Bool("n", false, "Non-interactive mode (direct output)")
showLineNumbers := flag.Bool("l", false, "Show line numbers")
hexMode := flag.Bool("H", false, "Hex mode")
wrapLines := flag.Bool("w", false, "Wrap long lines")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Atlas Cat - A beautiful terminal text viewer.\n\n")
fmt.Fprintf(os.Stderr, "Usage:\n atlas.cat [flags] <file>\n\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
}
flag.Parse()
if *showVersion || *showVersionLong {
fmt.Printf("atlas.cat v%s\n", Version)
return
}
args := flag.Args()
if len(args) < 1 {
flag.Usage()
os.Exit(1)
}
filePath := args[0]
// We no longer read everything here to save RAM
p, err := viewer.NewProcessor(filePath, *showLineNumbers, *hexMode, *wrapLines)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing: %v\n", err)
os.Exit(1)
}
if *noInteractive {
fmt.Print(p.HighlightAll("", -1))
return
}
// Interactive TUI Mode
pModel := ui.NewModel(p)
prog := tea.NewProgram(pModel, tea.WithAltScreen(), tea.WithMouseCellMotion())
if _, err := prog.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err)
os.Exit(1)
}
}