aboutsummaryrefslogtreecommitdiff
path: root/poe.go
blob: ca2b26d78651065a507f4376d29dca62a45792d3 (plain)
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
package main

import (
	"flag"
	"fmt"
	"os"
	"runtime"

	"github.com/prodhe/poe/editor"
	"github.com/prodhe/poe/ui"
)

const poeVersion = "0.0.0"

func main() {
	version := flag.Bool("v", false, "prints current version of poe")
	// cli := flag.Bool("c", false, "run in command line")

	flag.Parse()

	if *version {
		fmt.Println(poeVersion)
		os.Exit(0)
	}

	// new editor with loaded files
	e := editor.New()
	e.LoadBuffers(flag.Args())

	// load client user interface
	cui := ui.NewTcell()
	// if *cli {
	// 	cui = ui.NewCli()
	// }

	cui.Init(e)

	// close ui and show stack trace on panic
	defer func() {
		cui.Close()

		if err := recover(); err != nil {
			buf := make([]byte, 1<<16)
			n := runtime.Stack(buf, true)
			fmt.Println("poe error:", err)
			fmt.Printf("%s", buf[:n+1])
			os.Exit(1)
		}
	}()

	// This will loop and listen on chosen UI.
	cui.Listen()
}