Implement support for buttons on notifications in Linux

This commit is contained in:
Kovid Goyal
2024-07-31 12:11:21 +05:30
parent ad36c481af
commit aa16918dd4
8 changed files with 60 additions and 25 deletions

View File

@@ -102,6 +102,9 @@ func (p *parsed_data) generate_chunks(callback func(string)) {
if len(p.image_data) > 0 {
add_payload("icon", utils.UnsafeBytesToString(p.image_data))
}
if len(p.opts.Button) > 0 {
add_payload("buttons", strings.Join(p.opts.Button, "\u2028"))
}
write_chunk(";")
}
@@ -110,7 +113,7 @@ func (p *parsed_data) run_loop() (err error) {
if err != nil {
return err
}
activated := ""
activated := -1
prefix := ESC_CODE_PREFIX + "i=" + p.identifier
poll_for_close := func() {
@@ -156,7 +159,9 @@ func (p *parsed_data) run_loop() (err error) {
lp.Quit(0)
}
case "":
activated = utils.IfElse(payload == "", "activated", payload)
if activated, err = strconv.Atoi(utils.IfElse(payload == "", "0", payload)); err != nil {
return fmt.Errorf("Got invalid activation response from terminal: %#v", payload)
}
}
}
}
@@ -192,7 +197,7 @@ func (p *parsed_data) run_loop() (err error) {
lp.KillIfSignalled()
return
}
if activated != "" && err == nil {
if activated > -1 && err == nil {
fmt.Println(activated)
}
return

View File

@@ -26,6 +26,13 @@ default=kitten-notify
The application name for the notification.
--button -b
type=list
Add a button with the specified text to the notification. Can be specified multiple times for multiple buttons.
If --wait-for-completion is used then the kitten will print th ebutton number to STDOUT if the user clicks a button.
1 for the first button, 2 for the second button and so on.
--urgency -u
default=normal
choices=normal,low,critical
@@ -62,7 +69,7 @@ your own identifier via the --identifier option.
--wait-till-closed -w
type=bool-set
Wait until the notification is closed. If the user activates the notification,
"activated" is printed to STDOUT before quitting. Press the Esc or Ctrl+C keys
"0" is printed to STDOUT before quitting. Press the Esc or Ctrl+C keys
to close the notification manually.