Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add notification body message & text min-width (#7) #8

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion internal/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package internal
import (
"fmt"
"os"
"regexp"
"strings"
"time"

"github.com/godbus/dbus/v5"
Expand Down Expand Up @@ -98,9 +100,30 @@ func (n DBusNotify) Notify(

// Send Notification
nf := NewNotification()
nf.message = summary

parse_hints(&nf, hints)

// Setting min-width, left alignment
summary = fmt.Sprintf("%-60s", summary)
if nf.icon.value == nf.icon.NOICON {
summary += " "
}
summary += "\u205F"

if body != "" {
nf.message = fmt.Sprintf("%s\n%s", summary, body)
} else {
nf.message = summary
}

// Using RegExp to add padding for all lines
nf.message = regexp.
MustCompile("^\\s*|(\n)\\s*(.)").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you could store this regex in a package-level variable to not recompile it every time this function is ran

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll do it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! 024ba8b

ReplaceAllString(
strings.TrimLeft(nf.message, "\n"),
"$1\u205F $2",
)

if expire_timeout != -1 {
nf.time_ms = expire_timeout
}
Expand Down
6 changes: 1 addition & 5 deletions internal/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,23 @@ func newIconStruct() icon {

func (nf *Notification) set_urgency(urgency uint8) {
icon := nf.icon.NOICON
padding := ""
color := nf.color.DEFAULT
var time_ms int32 = 5 * 1000

if urgency == 0 {
icon = nf.icon.OK
padding = " "
color = nf.color.GREEN
} else if urgency == 1 {
icon = nf.icon.NOICON
padding = " "
color = nf.color.LIGHTBLUE
} else if urgency == 2 {
icon = nf.icon.WARNING
padding = " "
color = nf.color.RED
time_ms = 60 * 1000
}

nf.icon.value = icon
nf.icon.padding = padding
nf.icon.padding = ""
nf.color.value = color
nf.time_ms = time_ms
}
Expand Down
Loading