1package main
 2
 3// Global configuration of the editor. Settings are populated from command-line
 4// flags during initialization.
 5
 6import (
 7	"flag"
 8	"time"
 9)
10
11// Configuration holds all adjustable settings for the editor.
12type Configuration struct {
13	GutterWidth          int           // Width of the left column (line numbers, LSP signs).
14	DefaultTabWidth      int           // Number of spaces a tab character represents.
15	FuzzyFinderHeight    int           // Number of rows the fuzzy finder takes up.
16	LeaderKey            rune          // The prefix key for many custom commands (default: \).
17	UseLogFile           bool          // Whether to write debug logs to a file.
18	LogFilePath          string        // Where to store the debug logs.
19	NumLogsInDebugWindow int           // How many recent logs to show in the UI debug window.
20	OllamaCheckInterval  time.Duration // How often to check if Ollama is running.
21	FileCheckInterval    time.Duration // How often to check for external file changes.
22	OllamaURL            string        // Endpoint for the Ollama AI service.
23	OllamaModel          string        // The specific AI model to use for completion.
24	DevMode              bool          // Enables verbose logging and developer tools.
25	ShowColors           bool          // Command-line flag to show available colors and exit.
26	ShowInfo             bool          // Command-line flag to show file types and exit.
27	ShowVersion          bool          // Command-line flag to show version and exit.
28	FormatterMarkers     []string      // List of comment prefixes for text formatting (no CLI flag).
29}
30
31// Config is the global configuration instance.
32var Config Configuration
33
34// InitConfig sets up command-line flags and parses them into the global Config.
35func InitConfig() {
36	var leaderKey string
37
38	flag.IntVar(&Config.GutterWidth, "gutter-width", 7, "Width of the gutter")
39	flag.IntVar(&Config.DefaultTabWidth, "tab-width", 4, "Default tab width")
40	flag.IntVar(&Config.FuzzyFinderHeight, "fuzzy-height", 8, "Height of fuzzy finder")
41	flag.StringVar(&leaderKey, "leader", "\\", "Leader key")
42	flag.BoolVar(&Config.UseLogFile, "log", false, "Enable logging to file")
43	flag.StringVar(&Config.LogFilePath, "log-path", "/tmp/qwe-editor-debug.log", "Path to log file")
44	flag.IntVar(&Config.NumLogsInDebugWindow, "num-logs", 10, "Number of logs in debug window")
45	flag.DurationVar(&Config.OllamaCheckInterval, "ollama-interval", 5*time.Second, "Ollama check interval")
46	flag.DurationVar(&Config.FileCheckInterval, "file-check-interval", 2*time.Second, "File check interval")
47	flag.StringVar(&Config.OllamaURL, "ollama-url", "http://localhost:11434", "Ollama URL")
48	flag.StringVar(&Config.OllamaModel, "ollama-model", "qwen2.5-coder:latest", "Ollama model")
49	flag.BoolVar(&Config.DevMode, "dev", false, "Enable development mode")
50	flag.BoolVar(&Config.ShowColors, "colors", false, "Show available colors")
51	flag.BoolVar(&Config.ShowInfo, "info", false, "Show file associations and LSP info")
52	flag.BoolVar(&Config.ShowVersion, "version", false, "Show version")
53
54	flag.Parse()
55
56	// Convert the first character of the leader flag into a rune.
57	if len(leaderKey) > 0 {
58		Config.LeaderKey = rune(leaderKey[0])
59	}
60
61	// Initialize formatter markers for text formatting.
62	Config.FormatterMarkers = []string{
63		"//", // C/C++/Go/JavaScript/Rust
64		"--", // SQL/Lua/Haskell
65		"#",  // Python/Shell/Ruby/YAML
66		";;", // Lisp/Scheme
67		"%",  // LaTeX/MATLAB
68		">",  // Markdown quote
69	}
70}