~adnano/astronaut

ref: 72ba913688a9d2dafb0bfdf11a5cee16685ce98a astronaut/main.go -rw-r--r-- 1.4 KiB
72ba9136Adnan Maolood Use scfg to configure settings 3 months ago
                                                                                
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
package main

import (
	"astronaut/binds"
	"astronaut/styles"
	"astronaut/ui"
	"flag"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"time"

	"git.sr.ht/~adnano/go-xdg"
	"git.sr.ht/~emersion/go-scfg"
)

var (
	Version string
)

func main() {
	version := flag.Bool("v", false, "print version")
	flag.Parse()
	if *version {
		fmt.Println("astronaut", Version)
		return
	}

	os.MkdirAll(filepath.Join(xdg.DataHome(), "astronaut"), 0700)

	// Load the config
	styleConf := filepath.Join(xdg.ConfigHome(), "astronaut", "style.conf")
	f, err := os.Open(styleConf)
	if err == nil {
		defer f.Close()
		block, err := scfg.Read(f)
		if err != nil {
			log.Print(err)
		} else {
			styles.Parse(block)
		}
	}

	bindsConf := filepath.Join(xdg.ConfigHome(), "astronaut", "binds.conf")
	f, err = os.Open(bindsConf)
	if err == nil {
		defer f.Close()
		block, err := scfg.Read(f)
		if err != nil {
			log.Print(err)
		} else {
			binds.Parse(block)
		}
	}

	settings := &Settings{}
	astronautConf := filepath.Join(xdg.ConfigHome(), "astronaut", "astronaut.conf")
	f, err = os.Open(astronautConf)
	if err == nil {
		defer f.Close()
		block, err := scfg.Read(f)
		if err != nil {
			log.Print(err)
		} else {
			settings.Parse(block)
		}
	}

	ui, err := ui.New()
	if err != nil {
		log.Fatal(err)
	}
	defer ui.Close()

	browser := NewBrowser(ui.View(), settings)

	for !ui.Exiting() {
		browser.Update()

		if !ui.Tick(browser) {
			// ~60 FPS
			time.Sleep(16 * time.Millisecond)
		}
	}
}