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 pathhandlers.go
121 lines (110 loc) · 2.95 KB
/
handlers.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"fmt"
"sort"
"strconv"
"text/tabwriter"
"github.com/cheynewallace/tabby"
"github.com/jroimartin/gocui"
)
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
func cursorDown(g *gocui.Gui, v *gocui.View) error {
if v != nil {
cx, cy := v.Cursor()
if _, lineerr := v.Line(cy + 2); lineerr != nil {
return nil
}
if err := v.SetCursor(cx, cy+1); err != nil {
ox, oy := v.Origin()
if err := v.SetOrigin(ox, oy+1); err != nil {
return err
}
}
}
return nil
}
func cursorUp(g *gocui.Gui, v *gocui.View) error {
if v != nil {
ox, oy := v.Origin()
cx, cy := v.Cursor()
if _, lineerr := v.Line(cy - 2); lineerr != nil {
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
if err := v.SetOrigin(ox, oy-1); err != nil {
return err
}
}
if err := v.SetCursor(cx, cy); err != nil && oy > 0 {
if err := v.SetOrigin(ox, oy); err != nil {
return err
}
}
return nil
}
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
if err := v.SetOrigin(ox, oy-1); err != nil {
return err
}
}
}
return nil
}
func backtoSearch(g *gocui.Gui, v *gocui.View) error {
g.SetManagerFunc(searchui)
return nil
}
func backtoTorlist(g *gocui.Gui, v *gocui.View) error {
g.SetManagerFunc(searchlisttor)
return nil
}
func doSearch(g *gocui.Gui, v *gocui.View) error {
dstv, _ := g.View("inputbox")
query = dstv.Buffer()
err := torparadise(g)
return err
}
func doAbout(g *gocui.Gui, v *gocui.View) error {
g.SetManagerFunc(aboutfunc)
return nil
}
func sortAsc(g *gocui.Gui, v *gocui.View) error {
maxX, _ := g.Size()
sort.Sort(AscTorrents(torrents))
v.Clear()
if len(torrents) != 0 {
maxlentl := int(float64(maxX) / 1.35)
tw := tabwriter.NewWriter(v, 0, 0, 1, ' ', 0)
t := tabby.NewCustom(tw)
t.AddLine(term_res+"#", term_res+"Name", term_res+"Size", term_res+"Seeds", term_res+"Leeches"+term_res)
for idno, eachtorrent := range torrents {
t.AddLine(term_yell+strconv.Itoa(idno+1),
term_cyan+maxstring(eachtorrent.Text, maxlentl),
term_purp+fmt.Sprintf("%f", 0.000000001*eachtorrent.Length)+" GB",
term_green+"S:"+strconv.Itoa(eachtorrent.Seeds),
term_red+"L:"+strconv.Itoa(eachtorrent.Leechs)+term_res)
}
t.Print()
}
return nil
}
func sortDec(g *gocui.Gui, v *gocui.View) error {
maxX, _ := g.Size()
sort.Sort(DeTorrents(torrents))
v.Clear()
if len(torrents) != 0 {
maxlentl := int(float64(maxX) / 1.35)
tw := tabwriter.NewWriter(v, 0, 0, 1, ' ', 0)
t := tabby.NewCustom(tw)
t.AddLine(term_res+"#", term_res+"Name", term_res+"Size", term_res+"Seeds", term_res+"Leeches"+term_res)
for idno, eachtorrent := range torrents {
t.AddLine(term_yell+strconv.Itoa(idno+1),
term_cyan+maxstring(eachtorrent.Text, maxlentl),
term_purp+fmt.Sprintf("%f", 0.000000001*eachtorrent.Length)+" GB",
term_green+"S:"+strconv.Itoa(eachtorrent.Seeds),
term_red+"L:"+strconv.Itoa(eachtorrent.Leechs)+term_res)
}
t.Print()
}
return nil
}