summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2023-06-15 22:29:03 +0200
committerDave Davenport <qball@gmpclient.org>2023-06-15 22:29:03 +0200
commit7814da7ee42ee7763cbced5ac1dc0f6f39369ab2 (patch)
tree6052c35a55fc78d9496ee263b53d5f7d48623281
parent635fbd04647354c71e6e0245a4eedcdca0c6fb7b (diff)
[ROFI] -e '-' reads from stdin
-rw-r--r--doc/rofi.13
-rw-r--r--doc/rofi.1.markdown2
-rw-r--r--source/rofi.c22
3 files changed, 25 insertions, 2 deletions
diff --git a/doc/rofi.1 b/doc/rofi.1
index 51414db2..2dca0788 100644
--- a/doc/rofi.1
+++ b/doc/rofi.1
@@ -1142,6 +1142,9 @@ cause slowdowns when set too high)
Pops up a message dialog (used internally for showing errors) with \fImessage\fP\&.
Message can be multi-line.
+.PP
+Passing \fB\fC-e -\fR reads (blocking) from standard in and displays this.
+
.SS File browser settings
.PP
File browser behavior can be controlled via the following options:
diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown
index c8befe97..a68a92c0 100644
--- a/doc/rofi.1.markdown
+++ b/doc/rofi.1.markdown
@@ -740,6 +740,8 @@ cause slowdowns when set too high)
Pops up a message dialog (used internally for showing errors) with *message*.
Message can be multi-line.
+Passing `-e -` reads (blocking) from standard in and displays this.
+
### File browser settings
File browser behavior can be controlled via the following options:
diff --git a/source/rofi.c b/source/rofi.c
index ff408027..b397723b 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -797,8 +797,26 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
if (find_arg("-markup") >= 0) {
markup = TRUE;
}
- if (!rofi_view_error_dialog(msg, markup)) {
- g_main_loop_quit(main_loop);
+ // When we pass -, we read from stdin.
+ if (g_strcmp0(msg, "-") == 0) {
+ size_t index = 0, i = 0;
+ size_t length = 1024;
+ msg = malloc(length * sizeof(char));
+ while ((i = fread(&msg[index], 1, 1024, stdin))>0) {
+ index+=i;
+ length+=i;
+ msg = realloc(msg,length * sizeof(char));
+ }
+
+ if (!rofi_view_error_dialog(msg, markup)) {
+ g_main_loop_quit(main_loop);
+ }
+ g_free(msg);
+ } else {
+ // Normal version
+ if (!rofi_view_error_dialog(msg, markup)) {
+ g_main_loop_quit(main_loop);
+ }
}
} else if (find_arg_str("-show", &sname) == TRUE) {
int index = mode_lookup(sname);