-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (55 loc) · 1.45 KB
/
main.go
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
package main
import (
"flag"
"os/user"
"path/filepath"
"time"
"github.com/jroimartin/gocui"
"github.com/thejasbabu/track-it/pkg/task"
"github.com/thejasbabu/track-it/pkg/task/display"
"github.com/thejasbabu/track-it/util"
)
const (
// ScreenRefreshInterval determines the screen refresh interval
ScreenRefreshInterval = 1 * time.Second
// RootContainerID is the containerID of the root
RootContainerID = "root"
)
func main() {
var subreddit string
flag.StringVar(&subreddit, "subreddit", "", "name of the subreddit to take the tittle from, eg: r/jokes")
flag.Parse()
dataPath := dataPath()
db, err := util.Open(dataPath)
panicIfErr(err)
repo := task.NewBadgerRepository(db)
taskOperator := task.NewOperator(repo, util.UUIDIdentifier{}, util.SystemClock{})
gui, err := gocui.NewGui(gocui.Output256)
defer gui.Close()
panicIfErr(err)
var screen display.Screen
if subreddit != "" {
redditClient := util.RedditClient{SubReddit: subreddit}
screen = display.NewScreen(taskOperator, gui, &redditClient)
} else {
screen = display.NewScreen(taskOperator, gui, nil)
}
gui.SetManagerFunc(screen.Display)
screen.SetUp(gui)
if err := gui.MainLoop(); err != nil && err != gocui.ErrQuit {
panic(err)
}
}
//TODO: Handle when user's HOME changes
func dataPath() string {
usr, err := user.Current()
if err != nil {
panicIfErr(err)
}
return filepath.Join(usr.HomeDir, ".track-it")
}
func panicIfErr(err error) {
if err != nil {
panic(err)
}
}