Skip to content

Commit

Permalink
[ROFI] -e '-' reads from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveDavenport committed Jun 15, 2023
1 parent 635fbd0 commit 7814da7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/rofi.1
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions doc/rofi.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 20 additions & 2 deletions source/rofi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7814da7

Please sign in to comment.