From 7814da7ee42ee7763cbced5ac1dc0f6f39369ab2 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 15 Jun 2023 22:29:03 +0200 Subject: [ROFI] -e '-' reads from stdin --- doc/rofi.1 | 3 +++ doc/rofi.1.markdown | 2 ++ source/rofi.c | 22 ++++++++++++++++++++-- 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); -- cgit v1.2.3