-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (81 loc) · 1.89 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2020 lintong <[email protected]>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
package main
import (
"flag"
"fmt"
ui "github.com/gizak/termui/v3"
"log"
"os"
)
var cursor = 0
var short = false
var fullscreen = false
var h = false
func init() {
flag.BoolVar(&h, "h", false, "help")
flag.BoolVar(&fullscreen, "full", false, "进入全屏模式,常驻展示")
flag.BoolVar(&short, "short", false, "在全屏模式下, 适配小屏幕")
flag.Usage = usage
}
func usage() {
fmt.Fprintln(os.Stderr, `fastfind: 快速命令行检索工具,也能够作为一款辅助记忆软件`)
flag.PrintDefaults()
}
func fastfind() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
inputChain := make(chan string, 1)
historyCommandChain := make(chan string, 1)
recordHistoryCommandChain := make(chan string, 1)
input := NewInput(&inputChain, &historyCommandChain)
content := NewContent(&inputChain, &recordHistoryCommandChain)
history := NewHistory(&historyCommandChain, &recordHistoryCommandChain)
elems := make([]ui.Drawable, 0)
input.Render(&elems)
content.Render(&elems)
if !short {
history.Render(&elems)
}
ui.Render(elems...)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
if e.Type != ui.KeyboardEvent {
continue
}
var next bool
var repeat = true
for repeat {
if short {
elems[1], next, repeat = content.HandleEvent(e)
} else {
if cursor == 0 {
elems[1], next, repeat = content.HandleEvent(e)
} else {
elems[2], next, repeat = history.HandleEvent(e)
}
}
}
if next {
elems[0] = input.HandleEvent(e)
}
ui.Render(elems...)
}
}
func main() {
flag.Parse()
if h {
flag.Usage()
return
}
if fullscreen == true {
fastfind()
} else {
fmt.Println("输入exit退出")
execCommand()
}
}