aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFredrik Salomonsson <plattfot@gmail.com>2020-05-04 11:22:16 -0700
committerFredrik Salomonsson <plattfot@gmail.com>2020-05-04 11:56:48 -0700
commit3c74cb264796fc5b29961a1a850ad205eb7a882d (patch)
tree5dbc5e1f65e6dd530d280a67e81f325e171c22c3
parent2f5e77e8549feeca3c141398c0b9822a327c5fd5 (diff)
downloadpinentry-rofi-3c74cb264796fc5b29961a1a850ad205eb7a882d.tar.gz
Added support for underline (#5)
Reading some more in the pinentry protocol [1], underscore followed by a character means underline that character. To escape that two underscore is used. Added that behavior in the messages. The input to dmenu i.e the buttons, does not support pango markup so just removing the underscore. [1] http://info2html.sourceforge.net/cgi-bin/info2html-demo/info2html?(pinentry)Protocol
-rwxr-xr-xpinentry-rofi.scm28
1 files changed, 27 insertions, 1 deletions
diff --git a/pinentry-rofi.scm b/pinentry-rofi.scm
index 932950f..1391844 100755
--- a/pinentry-rofi.scm
+++ b/pinentry-rofi.scm
@@ -59,10 +59,26 @@
"Evaluates to #t if string is empty."
(string=? str ""))
+(define (pinentry-remove-underline str)
+ "Replace _ followed by a character with just the character."
+ (regexp-substitute/global #f "(^|[[:blank:]])_([[:alpha:]])" str
+ 'pre 1 2 'post))
+
+(define (pinentry-escape-underscore str)
+ "Replace __ followed by a character with _ and said character.
+Always call this after `pinentry-remove-underline' or
+`html-underline'."
+ (regexp-substitute/global #f "(^|[[:blank:]])__([[:alpha:]])" str
+ 'pre 1 "_" 2 'post))
+
(define (html-newline str)
"Replace %0A with &#10;"
(regexp-substitute/global #f "%0A" str 'pre "&#10;" 'post))
+(define (html-underline str)
+ "Underscore followed by a character, underlines that character."
+ (regexp-substitute/global #f "(^|[[:blank:]])_([[:alpha:]])" str
+ 'pre 1"<u>"2"</u>" 'post))
(define (html-< str)
"Replace < with &lt;"
(regexp-substitute/global #f "<" str 'pre "&lt;" 'post))
@@ -77,7 +93,17 @@
(define (pango-markup str)
"Transform string to pango."
- (hex->char (html-< (html-newline str))))
+ (hex->char
+ (pinentry-escape-underscore
+ (html-underline
+ (html-<
+ (html-newline str))))))
+
+(define (input-string str)
+ "Transform string to input for rofi.
+Input strings does not support pango markup"
+ (pinentry-escape-underscore
+ (pinentry-remove-underline str)))
(define (pinentry-option pinentry line)
"Process line if it starts with OPTION.