-
Notifications
You must be signed in to change notification settings - Fork 4
/
announcements.go
76 lines (62 loc) · 2.15 KB
/
announcements.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
package main
import (
// "encoding/json"
// "io/ioutil"
// "net/http"
// "github.com/spf13/viper"
// "log"
// "strconv"
// "time"
// "reflect"
// "time"
// "bytes"
// "fmt"
strip "github.com/grokify/html-strip-tags-go"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
// ui "github.com/GideonWolfe/termui/v3"
// "github.com/GideonWolfe/termui/v3/widgets"
)
func createAnnouncementParagraph(announcement Announcement) *widgets.Paragraph {
paragraph := widgets.NewParagraph()
paragraph.Text = announcement.Message
return paragraph
}
func createAnnouncementTable(announcements *[]Announcement, width int) *widgets.Table {
var tableData [][]string
header := []string{"Message"}
tableData = append(tableData, header)
for _, ann := range *announcements {
var announcementData []string
announcementData = append(announcementData, strip.StripTags(ann.Message))
tableData = append(tableData, announcementData)
}
announcementData := widgets.NewTable()
announcementData.Title = "Announcements:"
announcementData.Rows = tableData
announcementData.TextStyle = ui.NewStyle(ui.ColorWhite)
announcementData.RowSeparator = true
announcementData.FillRow = false
// assignmentTable.RowStyles
// assignmentTable.ColumnWidths = []int{10, width}
announcementData.RowStyles[0] = ui.NewStyle(ui.ColorWhite, ui.ColorBlack, ui.ModifierBold)
return announcementData
}
func createAnnouncementGrid(course Course, announcements *[]Announcement) *ui.Grid {
// var announcements *[]Announcement = fetchAnnouncements(course.ID)
// var announcmentParagraphs []widgets.Paragraph
announcementGrid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
announcementGrid.SetRect(0, 0, termWidth, termHeight)
announcementGrid.Title = "Announcement Grid"
announcementGrid.Set(
ui.NewCol(1.0,
ui.NewRow(1.0, createAnnouncementTable(announcements, termWidth)),
// ui.NewRow(1.0, &announcmentParagraphs[0]),
),
)
// for _, ann := range *announcements {
// announcmentParagraphs = append(announcmentParagraphs, *createAnnouncementParagraph(ann))
// }
return announcementGrid
}