This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsearchui.go
86 lines (71 loc) · 2.06 KB
/
searchui.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
package main
import (
"fmt"
"log"
"github.com/jroimartin/gocui"
)
func searchui(g *gocui.Gui) error {
maxX, maxY := g.Size()
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Println(err)
}
// Header
if header, err := g.SetView("header", maxX/2-9, maxY/2-6, maxX/2+9, maxY/2-3); err != nil {
if err != gocui.ErrUnknownView {
return err
}
header.Frame = false
fmt.Fprintln(header, " Search the")
fmt.Fprintln(header, term_yell, "Torrent Paradise", term_res)
}
// Input Box
if editbox, err := g.SetView("inputbox", maxX/2-17, maxY/2-2, maxX/2+17, maxY/2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
editbox.Editable = true
if err := g.SetKeybinding("inputbox", gocui.KeyEnter, gocui.ModNone, doSearch); err != nil {
return err
}
if err := g.SetKeybinding("inputbox", gocui.KeyArrowRight, gocui.ModNone, doSearch); err != nil {
return err
}
if err := g.SetKeybinding("inputbox", gocui.KeyHome, gocui.ModNone, doAbout); err != nil {
return err
}
if err := g.SetKeybinding("inputbox", gocui.KeyDelete, gocui.ModNone, resetInput); err != nil {
return err
}
if err := g.SetKeybinding("inputbox", gocui.KeyArrowLeft, gocui.ModNone, quit); err != nil {
return err
}
if _, err := g.SetCurrentView("inputbox"); err != nil {
return err
}
}
// Enter to Search View
if srview, err := g.SetView("srview", maxX/2-9, maxY/2+1, maxX/2+9, maxY/2+3); err != nil {
if err != gocui.ErrUnknownView {
return err
}
srview.Frame = false
fmt.Fprintln(srview, term_grey, "Enter to Search", term_res)
}
// Help Widget
if srhelp, err := g.SetView("srhelp", -1, maxY-2, maxX, maxY); err != nil {
if err != gocui.ErrUnknownView {
return err
}
srhelp.Frame = true
srhelp.Wrap = true
fmt.Fprintln(srhelp, "Press <enter> / → to Search , ← / Ctrl-c to Quit , <home> for About Menu")
}
return nil
}
func resetInput(g *gocui.Gui, v *gocui.View) error {
inpbox, _ := g.View("inputbox")
inpbox.Clear()
inpbox.SetCursor(0, 0)
inpbox.SetOrigin(0, 0)
return nil
}