From d000d3d4642b2202d126743cf766e24d85176f22 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 6 Mar 2016 03:24:05 +0100 Subject: Read file list from standard input continuosly This reduces delay before initial draw in case of slow input, opening possibilities for use cases like: $ curl -Osw "%{filename_effective}\n" "http://www.example.com/[1-10].jpg" which will download all images and start showing them once first arrives. --- src/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index fdbd866..426a12e 100644 --- a/src/main.c +++ b/src/main.c @@ -19,11 +19,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include #include #include #include #include #include +#include #include #include "loader.h" @@ -179,19 +181,31 @@ int main(int argc, char** argv) g_options.stdin_list = 1; } - /* if the user asked us to load paths from stdin, now is the time */ + /* if the user asked to load paths from stdin, set up poll(2)ing and read + the first path */ + struct pollfd rfds[1]; if(g_options.stdin_list) { - fprintf(stderr, "Reading paths from stdin...\n"); + rfds[0].fd = STDIN_FILENO; + rfds[0].events = POLLIN; + fprintf(stderr, "Reading paths from stdin..."); + char buf[PATH_MAX]; - while(fgets(buf, sizeof(buf), stdin)) { + char *stdin_ok; + while((stdin_ok = fgets(buf, sizeof(buf), stdin)) != NULL) { size_t len = strlen(buf); if(buf[len-1] == '\n') { buf[--len] = 0; } if(len > 0) { imv_navigator_add(&nav, buf, g_options.recursive); + break; } } + if(!stdin_ok) { + fprintf(stderr, " no input!\n"); + return -1; + } + fprintf(stderr, "\n"); } void *stdin_buffer = NULL; @@ -450,6 +464,9 @@ int main(int argc, char** argv) if(imv_navigator_poll_changed(&nav, poll_countdown--)) { const char *current_path = imv_navigator_selection(&nav); if(!current_path) { + if(g_options.stdin_list) { + continue; + } fprintf(stderr, "No input files left. Exiting.\n"); exit(1); } @@ -593,7 +610,35 @@ int main(int argc, char** argv) } /* sleep a little bit so we don't waste CPU time */ - SDL_Delay(10); + if(g_options.stdin_list) { + if(poll(rfds, 1, 10) != 1 || rfds[0].revents & (POLLERR|POLLNVAL)) { + fprintf(stderr, "error polling stdin"); + return 1; + } + if(rfds[0].revents & (POLLIN|POLLHUP)) { + char buf[PATH_MAX]; + if(fgets(buf, sizeof(buf), stdin) == NULL && ferror(stdin)) { + clearerr(stdin); + continue; + } + if(feof(stdin)) { + g_options.stdin_list = 0; + fprintf(stderr, "done with stdin\n"); + continue; + } + + size_t len = strlen(buf); + if(buf[len-1] == '\n') { + buf[--len] = 0; + } + if(len > 0) { + imv_navigator_add(&nav, buf, g_options.recursive); + need_redraw = 1; + } + } + } else { + SDL_Delay(10); + } } while(g_options.list) { const char *path = imv_navigator_selection(&nav); -- cgit v1.2.3 From 01f9532d188aa9cb8d5c85a3862c4d974e443f08 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 6 Mar 2016 03:45:21 +0100 Subject: Note command for viewing images from the web --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f48598b..c443fd7 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ ones with `x`, then quit imv to pass the remaining images through" workflow. #### Choosing pictures to email find ./holiday_pics -type f -name '*.jpg' | imv | xargs cp -t ~/outbox +#### Viewing images from the web + curl -Osw '%{filename_effective}\n' 'http://www.example.com/[1-10].jpg' + ### Slideshow imv can be used to display slideshows. You can set the number of seconds to -- cgit v1.2.3 From 8a4f62af0a462b39650a657ff42174fba5dcf5c1 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 6 Mar 2016 03:49:47 +0100 Subject: Forgot "imv" in example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c443fd7..8f44605 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ ones with `x`, then quit imv to pass the remaining images through" workflow. find ./holiday_pics -type f -name '*.jpg' | imv | xargs cp -t ~/outbox #### Viewing images from the web - curl -Osw '%{filename_effective}\n' 'http://www.example.com/[1-10].jpg' + curl -Osw '%{filename_effective}\n' 'http://www.example.com/[1-10].jpg' | imv ### Slideshow -- cgit v1.2.3