-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
157 lines (135 loc) · 4.23 KB
/
main.go
File metadata and controls
157 lines (135 loc) · 4.23 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"flag"
"fmt"
"os"
"github.com/SreeAditya-Dev/Cello-TUI/internal/app"
"github.com/SreeAditya-Dev/Cello-TUI/internal/loader"
tea "github.com/charmbracelet/bubbletea"
)
var version = "1.0.0"
var (
showVersion = flag.Bool("version", false, "Show version information")
showHelp = flag.Bool("help", false, "Show help information")
themeName = flag.String("theme", "catppuccin", "Set the color theme")
)
func main() {
// Handle config subcommand before flag parsing
if len(os.Args) > 1 && os.Args[1] == "config" {
runConfigTUI()
return
}
flag.StringVar(themeName, "t", "catppuccin", "Set the color theme (shorthand)")
flag.Parse()
if *showVersion {
printVersion()
os.Exit(0)
}
if *showHelp {
printHelp()
os.Exit(0)
}
args := flag.Args()
if len(args) < 1 {
printUsage()
os.Exit(1)
}
filename := args[0]
// Validate file exists
if err := validateFile(filename); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
// Load file
sheets, err := loader.LoadFile(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading file: %v\n", err)
os.Exit(1)
}
if len(sheets) == 0 {
fmt.Fprintln(os.Stderr, "Error: No sheets found in file")
os.Exit(1)
}
// Create and run application
model := app.NewModel(filename, sheets, *themeName)
program := tea.NewProgram(
model,
tea.WithAltScreen(),
tea.WithMouseCellMotion(),
)
if _, err := program.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running program: %v\n", err)
os.Exit(1)
}
}
// runConfigTUI runs the standalone configuration TUI
func runConfigTUI() {
model := app.NewConfigModel()
program := tea.NewProgram(
model,
tea.WithAltScreen(),
)
finalModel, err := program.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error running config: %v\n", err)
os.Exit(1)
}
// Check if config was saved
if configModel, ok := finalModel.(app.ConfigModel); ok && configModel.WasSaved() {
fmt.Println("✓ Configuration saved to ~/.cello/config.json")
}
}
func printVersion() {
fmt.Printf("cello version %s\n", version)
fmt.Println("A beautiful terminal-based Excel and CSV viewer & editor.")
fmt.Println("\nProject: https://github.com/SreeAditya-Dev/Cello-TUI")
}
func printHelp() {
fmt.Printf("cello v%s - Terminal Excel Viewer\n\n", version)
fmt.Println("USAGE:")
fmt.Println(" cello [OPTIONS] <file>")
fmt.Println(" cello config Configure AI provider settings")
fmt.Println("\nARGUMENTS:")
fmt.Println(" <file> Path to Excel (.xlsx, .xlsm, .xls) or CSV file")
fmt.Println("\nOPTIONS:")
fmt.Println(" -t, --theme <name> Set color theme (default: catppuccin)")
fmt.Println(" --version Show version information")
fmt.Println(" --help Show this help message")
fmt.Println("\nAI FORMULA GENERATION:")
fmt.Println(" Run 'cello config' to set up your AI provider (Gemini, OpenAI, Claude, etc.)")
fmt.Println(" Then use Ctrl+K in the app to generate formulas from natural language.")
fmt.Println("\nAVAILABLE THEMES:")
for _, name := range app.GetThemeNames() {
fmt.Printf(" • %s\n", name)
}
fmt.Println("\nEXAMPLES:")
fmt.Println(" cello data.xlsx")
fmt.Println(" cello config")
fmt.Println(" cello report.csv --theme nord")
fmt.Println("\nKEYBOARD SHORTCUTS:")
fmt.Println(" Navigation: ↑↓←→ / hjkl, PgUp/PgDn, Home/End")
fmt.Println(" Sheets: Tab / Shift+Tab")
fmt.Println(" Search: / (search), n (next), N (prev)")
fmt.Println(" Actions: Enter (details), Ctrl+G (jump), c (copy)")
fmt.Println(" Data viz: V (select range), v (visualize)")
fmt.Println(" Other: e (export), t (theme), f (formulas), ? (help), q (quit)")
fmt.Println("\nFor more information, visit: https://github.com/SreeAditya-Dev/Cello-TUI")
}
func printUsage() {
fmt.Fprintf(os.Stderr, "cello: missing file argument\n\n")
fmt.Fprintf(os.Stderr, "Usage: cello [OPTIONS] <file>\n")
fmt.Fprintf(os.Stderr, "Try 'cello --help' for more information.\n")
}
func validateFile(filename string) error {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return fmt.Errorf("file '%s' does not exist", filename)
}
if err != nil {
return err
}
if info.IsDir() {
return fmt.Errorf("'%s' is a directory, not a file", filename)
}
return nil
}