-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (46 loc) · 1.12 KB
/
main.go
File metadata and controls
56 lines (46 loc) · 1.12 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
package main
import (
"flag"
"fmt"
"os"
"atlas.ed/internal/ui"
tea "github.com/charmbracelet/bubbletea"
)
var Version = "dev"
func main() {
showVersion := flag.Bool("v", false, "Show version")
showVersionLong := flag.Bool("version", false, "Show version")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Atlas Ed - A beautiful terminal text editor.\n\n")
fmt.Fprintf(os.Stderr, "Usage:\n atlas.ed [flags] <file>\n\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
}
flag.Parse()
if *showVersion || *showVersionLong {
fmt.Printf("atlas.ed v%s\n", Version)
return
}
args := flag.Args()
if len(args) < 1 {
flag.Usage()
os.Exit(1)
}
filePath := args[0]
content := ""
if _, err := os.Stat(filePath); err == nil {
data, err := os.ReadFile(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err)
os.Exit(1)
}
content = string(data)
}
// Interactive TUI Mode
m := ui.NewModel(filePath, content)
p := tea.NewProgram(&m, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err)
os.Exit(1)
}
}