simplify mako impl

This commit is contained in:
Daylin Morgan 2024-06-06 13:25:01 -05:00
parent 269cc8e53f
commit 36dd259822
Signed by: daylin
GPG Key ID: 950D13E9719334AD
1 changed files with 46 additions and 26 deletions

View File

@ -31,24 +31,55 @@ type MakoNotificationData struct {
Data string `json:"data"`
}
// type Notifcation
type History struct {
Notifications []Notifcation
}
// type History struct {
// notifications []Notifcation
// }
type Notifcation struct {
AppName string
Summary string
Body string
}
func getHistory() MakoHistory {
var history MakoHistory
func (mn MakoNotification) toNotification() Notifcation {
var n Notifcation
n.AppName = mn.AppName.Data
n.Summary = mn.Summary.Data
n.Body = mn.Body.Data
return n
}
func (mh MakoHistory) toHistory() History {
var h History
var notifications []Notifcation
for _, mn := range mh.Data[0] {
notifications = append(notifications, mn.toNotification())
}
h.Notifications = notifications
return h
}
func getHistory() History {
var makoHistory MakoHistory
makoOutput, err := exec.Command("makoctl", "history").CombinedOutput()
if err != nil {
log.Fatal(err)
}
json.Unmarshal(makoOutput, &history)
return history
json.Unmarshal(makoOutput, &makoHistory)
return makoHistory.toHistory()
}
// TODO: replace with simple Render function
func displayNotification(n MakoNotification) {
func ListNotifications(number int) {
history := getHistory()
for i, n := range history.Notifications {
if i > number-1 {
break
}
n.Render()
}
}
func (n Notifcation) Render() {
appStyle := lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("3")).
@ -57,26 +88,15 @@ func displayNotification(n MakoNotification) {
BorderStyle(lipgloss.ThickBorder()).
BorderLeft(true)
fmt.Println(appStyle.Render(n.AppName.Data))
if len(n.Summary.Data) > 0 {
fmt.Println(appStyle.Render(n.AppName))
if len(n.Summary) > 0 {
fmt.Println(textStyle.
BorderForeground(lipgloss.Color("14")).
Render(n.Summary.Data))
Render(n.Summary))
}
if len(n.Body.Data) > 0 {
if len(n.Body) > 0 {
fmt.Println(textStyle.
BorderForeground(lipgloss.Color("2")).
Render(n.Body.Data))
}
}
func ListNotifications(number int) {
history := getHistory()
for i, notification := range history.Data[0] {
displayNotification(notification)
if i > number-1 {
break
}
Render(n.Body))
}
}