Added feature to read page content from stdin.
authorHironao Komatsu <hirkmt@gmail.com>
Thu, 4 Sep 2014 02:11:22 +0000 (11:11 +0900)
committerHironao Komatsu <hirkmt@gmail.com>
Thu, 4 Sep 2014 02:11:22 +0000 (11:11 +0900)
src/main.c

index a9130a3..3191577 100644 (file)
@@ -186,9 +186,25 @@ gboolean vb_load_uri(const Arg *arg)
         path = GET_CHAR("home-page");
     }
 
-    /* If path contains :// but no space we open it direct. This is required
-     * to use :// also with shortcuts */
-    if ((strstr(path, "://") && !strchr(path, ' ')) || !strncmp(path, "about:", 6)) {
+    if (strcmp(path, "-") == 0) {
+        /* read content from stdin */
+        GIOChannel *ch = g_io_channel_unix_new(fileno(stdin));
+        gchar *buf = NULL; gsize len; GError *err = NULL;
+        g_io_channel_read_to_end(ch, &buf, &len, &err);
+        g_io_channel_unref(ch);
+        if (err) {
+            g_warning("Error loading from stdin: %s\n", err->message);
+            g_error_free(err);
+            g_free(buf);
+        } else {
+            webkit_web_view_load_string(
+                vb.gui.webview, buf, "text/html", NULL, "(stdin)");
+            g_free(buf);
+            return true;
+        }
+    } else if ((strstr(path, "://") && !strchr(path, ' ')) || !strncmp(path, "about:", 6)) {
+        /* If path contains :// but no space we open it direct. This is required
+         * to use :// also with shortcuts */
         uri = g_strdup(path);
     } else if (stat(path, &st) == 0) {
         /* check if the path is a file path */