aboutsummaryrefslogtreecommitdiff
path: root/gui/cmd/krino-gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui/cmd/krino-gui')
-rw-r--r--gui/cmd/krino-gui/main.go33
-rw-r--r--gui/cmd/krino-gui/paths.go42
2 files changed, 66 insertions, 9 deletions
diff --git a/gui/cmd/krino-gui/main.go b/gui/cmd/krino-gui/main.go
index 4142e8c..9b46b22 100644
--- a/gui/cmd/krino-gui/main.go
+++ b/gui/cmd/krino-gui/main.go
@@ -6,29 +6,44 @@
package main
import (
+ "flag"
"fmt"
"os"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
+
+ "krino/gui/internal/ui"
+ "krino/internal/engine"
)
// version is stamped at build time, as krino's is.
var version = "dev"
func main() {
- if len(os.Args) > 1 && os.Args[1] == "--version" {
+ conf := flag.String("c", "", "use FILE instead of ~/.config/krino/krino.conf")
+ showVersion := flag.Bool("version", false, "print the version and exit")
+ flag.Parse()
+ if *showVersion {
fmt.Println("krino-gui " + version)
return
}
+
+ e, diags := engine.Load(mainFile(*conf))
+ if len(diags) > 0 {
+ printDiags(diags)
+ os.Exit(2)
+ }
+ e.CacheDir = cacheDir()
+ sess, err := e.NewSession(false)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "krino-gui: "+err.Error())
+ os.Exit(1)
+ }
+ defer sess.Close()
+
app := gtk.NewApplication("xyz.labunix.krino", 0)
- app.ConnectActivate(func() {
- win := gtk.NewApplicationWindow(app)
- win.SetTitle("krino")
- win.SetDefaultSize(900, 600)
- win.SetChild(gtk.NewLabel("krino-gui"))
- win.Show()
- })
- if code := app.Run(os.Args); code != 0 {
+ app.ConnectActivate(func() { ui.NewWindow(app, e, sess).Show() })
+ if code := app.Run(nil); code != 0 {
os.Exit(code)
}
}
diff --git a/gui/cmd/krino-gui/paths.go b/gui/cmd/krino-gui/paths.go
new file mode 100644
index 0000000..447fc15
--- /dev/null
+++ b/gui/cmd/krino-gui/paths.go
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "krino/internal/config"
+ "krino/internal/xdg"
+)
+
+// cacheDir is where every directory's keyword cache lives (spec ยง6.1), the
+// same place krino uses.
+func cacheDir() string {
+ return filepath.Join(xdg.CacheHome(), "krino")
+}
+
+// mainFile is -c FILE, or the default krino.conf - the same rule the
+// command line follows, tilde and all.
+func mainFile(conf string) string {
+ if conf != "" {
+ return xdg.Expand(conf)
+ }
+ return config.DefaultFile()
+}
+
+// printDiags reports configuration problems the way krino(1) does, so a
+// file that will not load reads the same however it was opened.
+func printDiags(errs []*config.Diag) {
+ for _, e := range errs {
+ d := *e
+ d.File = xdg.Abbrev(d.File)
+ fmt.Fprintln(os.Stderr, &d)
+ }
+ if len(errs) == 1 {
+ fmt.Fprintln(os.Stderr, "krino-gui: 1 problem found")
+ } else {
+ fmt.Fprintf(os.Stderr, "krino-gui: %d problems found\n", len(errs))
+ }
+}