-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
58 lines (48 loc) · 1 KB
/
utils.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
package main
import (
"fmt"
"github.com/rivo/tview"
)
func clearInputFields(fields ...*tview.InputField) {
for _, field := range fields {
field.SetText("")
}
}
func updateTextView(contact Contact) {
app.SetFocus(inputField)
textView.Clear()
wr := textView.BatchWriter()
defer func(wr tview.TextViewWriter) {
err := wr.Close()
if err != nil {
}
}(wr)
for _, msg := range messages[contact] {
switch name := msg.From; name {
case "You":
_, err := fmt.Fprintf(wr, "[red]>%s: [white]%s\n", msg.From, msg.Text)
if err != nil {
return
}
default:
_, err := fmt.Fprintf(wr, "[blue]>%s: [white]%s\n", msg.From, msg.Text)
if err != nil {
return
}
}
}
}
func addContactToList(contact Contact) {
list.AddItem(contact.Name, "", 0, func() {
currContact = contact
updateTextView(contact)
})
}
func findContactByIP(ip string, contacts *[]Contact) (Contact, bool) {
for _, cont := range *contacts {
if cont.IP == ip {
return cont, true
}
}
return Contact{}, false
}