-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkview.go
59 lines (50 loc) · 947 Bytes
/
linkview.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
package main
import (
"fmt"
"os"
)
func main() {
stat, err := os.Stdin.Stat()
if err != nil {
fmt.Fprintf(os.Stderr, "linkview: %s\n", err)
return
}
var file *os.File
if (stat.Mode() & os.ModeNamedPipe) == 0 {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "linkview: %s\n", "expected at least one argument")
return
}
file, err = os.Open(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "linkview: %s\n", err)
return
}
} else {
file = os.Stdin
}
links, err := FindLinks(file)
if err != nil {
fmt.Fprintf(os.Stderr, "linkview: %s\n", err)
return
}
terminal := NewTerminal(&links)
err = terminal.Start()
if err != nil {
panic(err)
}
defer terminal.Close()
terminal.Render()
terminal.SetSize()
terminal.Render()
for {
go PollEvent()
quit, err := terminal.HandleEvent(<-EventChan)
if err != nil {
fmt.Fprintf(os.Stderr, "linkview: %s\n", err)
}
if quit {
return
}
}
}