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

View file

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