-
Notifications
You must be signed in to change notification settings - Fork 6
/
gui.go
145 lines (130 loc) · 3.48 KB
/
gui.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"fmt"
"log"
"strings"
"time"
"github.com/ChimeraCoder/anaconda"
"github.com/gdamore/tcell"
"gitlab.com/tslocum/cview"
)
func createTextViewItem(title string) *cview.TextView {
tempView := cview.NewTextView()
tempView.SetDynamicColors(true)
tempView.SetRegions(false)
tempView.SetWordWrap(true)
tempView.SetBorder(true)
tempView.SetTitle(title)
tempView.SetBorderColor(tcell.ColorGrey)
tempView.SetChangedFunc(func() {
tempView.ScrollToBeginning()
app.Draw()
})
tempView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyTab {
blah := nextColumn(columnItems, tempView)
app.SetFocus(blah)
tempView.SetTitleColor(tcell.ColorWhite)
blah.SetTitleColor(tcell.ColorYellow)
return nil
}
return event
})
return tempView
}
func textViewProcessFeed(tv *cview.TextView, listID int64, api *anaconda.TwitterApi) {
for {
tv.Clear()
lastUpdateTime := time.Now()
fmt.Fprintf(tv, "[#CCFFCC::b]%s %v[white]\n\n", "UPDATED", lastUpdateTime.Format(time.UnixDate))
timeTweets, err := getListTweets(api, listID)
if err != nil {
log.Println(err)
}
tweetSplit := buildBreak(tv)
for _, tweet := range timeTweets {
tempTime, err := tweet.CreatedAtTime()
if err != nil {
log.Println(err)
}
if tweet.RetweetedStatus != nil {
fmt.Fprintf(tv, "[#66CCFF::b]@%s[-::-] at [#66CCFF]%s[-] [red]*RT*[-]:\n\n%s\n%s\n\n", tweet.User.ScreenName, tempTime.Local().Format(time.UnixDate), tweet.FullText, tweetSplit)
} else {
fmt.Fprintf(tv, "[#66CCFF::b]@%s[-::-] at [#66CCFF]%s[-]:\n\n%s\n%s\n\n", tweet.User.ScreenName, tempTime.Local().Format(time.UnixDate), tweet.Text, tweetSplit)
}
}
time.Sleep(parsedconfig.Refresh * time.Minute)
}
}
func showModal(currentColumn *cview.TextView) {
buttons := make([]string, 0)
for _, column := range columnItems {
if !isColumnActive(column) {
buttons = append(buttons, column.GetTitle())
}
}
buttons = append(buttons, "Close")
modal := cview.NewModal()
modal.SetText("Select a column to add")
modal.AddButtons(buttons)
modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Close" {
app.SetRoot(flex, true)
} else {
columnToAdd := getColumnByTitle(buttonLabel)
app.QueueUpdateDraw(func() {
flex.AddItem(columnToAdd, 0, 1, true)
app.SetRoot(flex, true)
app.SetFocus(columnToAdd)
currentColumn.SetTitleColor(tcell.ColorWhite)
columnToAdd.SetTitleColor(tcell.ColorYellow)
})
}
})
app.QueueUpdateDraw(func() {
app.SetRoot(modal, true)
app.SetFocus(modal)
})
}
func buildBreak(tv *cview.TextView) string {
_, _, w, _ := tv.GetInnerRect()
charCount := w / 2
var sb strings.Builder
for i := 0; i < charCount/2; i++ {
sb.WriteString(" ")
}
for i := 0; i < charCount; i++ {
sb.WriteString("=")
}
return sb.String()
}
func nextColumn(columns []*cview.TextView, view *cview.TextView) *cview.TextView {
childers := flex.GetChildren()
for k, v := range childers {
if view == v.(*cview.TextView) {
if k+1 == len(childers) {
return childers[0].(*cview.TextView)
} else {
return childers[k+1].(*cview.TextView)
}
}
}
return nil
}
func getColumnByTitle(title string) *cview.TextView {
for _, column := range columnItems {
if column.GetTitle() == title {
return column
}
}
return nil
}
func isColumnActive(column *cview.TextView) bool {
childers := flex.GetChildren()
for _, v := range childers {
if column == v.(*cview.TextView) {
return true
}
}
return false
}