summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--scoop.111
-rw-r--r--scoop.c26
2 files changed, 32 insertions, 5 deletions
diff --git a/scoop.1 b/scoop.1
index 2dfdf09..82ac29a 100644
--- a/scoop.1
+++ b/scoop.1
@@ -15,6 +15,7 @@
 .Op Fl T Ar target
 .Op Fl c Ar context
 .Op Fl d Ar path
+.Op Fl f Ar format
 .Op Fl h Ar host
 .Op Fl l Ar limit
 .Op Fl n Ar nick
@@ -85,6 +86,16 @@ The database must have been initialized by
 The default path is as in
 .Xr litterbox 1 .
 .
+.It Fl f Ar format
+Set the output format to one of
+.Cm plain ,
+.Cm color .
+The default format is
+.Cm color
+if standard output is a terminal,
+.Cm plain
+otherwise.
+.
 .It Fl g
 Group events by context.
 .
diff --git a/scoop.c b/scoop.c
index 5c00c6b..55ee857 100644
--- a/scoop.c
+++ b/scoop.c
@@ -206,6 +206,21 @@ static enum Type parseType(const char *input) {
 	errx(EX_USAGE, "no such type %s", input);
 }
 
+static const struct {
+	const char *name;
+	Format *fn;
+} Formats[] = {
+	{ "plain", formatPlain },
+	{ "color", formatColor },
+};
+
+static Format *parseFormat(const char *name) {
+	for (size_t i = 0; i < ARRAY_LEN(Formats); ++i) {
+		if (!strcmp(name, Formats[i].name)) return Formats[i].fn;
+	}
+	errx(EX_USAGE, "no such format %s", name);
+}
+
 static struct Bind {
 	const char *param;
 	const char *text;
@@ -215,16 +230,19 @@ static struct Bind {
 }
 
 int main(int argc, char *argv[]) {
+	bool tty = isatty(STDOUT_FILENO);
+
 	char *path = NULL;
 	bool shell = false;
 	bool group = false;
+	Format *format = (tty ? formatColor : formatPlain);
 
 	int n = 0;
 	struct Bind binds[argc];
 	const char *search = NULL;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "D:F:N:T:c:d:gh:l:n:pqst:u:v"))) {
+	while (0 < (opt = getopt(argc, argv, "D:F:N:T:c:d:f:gh:l:n:pqst:u:v"))) {
 		switch (opt) {
 			break; case 'D': binds[n++] = Bind(":date", optarg, 0);
 			break; case 'F': binds[n++] = Bind(":format", optarg, 0);
@@ -232,6 +250,7 @@ int main(int argc, char *argv[]) {
 			break; case 'T': binds[n++] = Bind(":target", optarg, 0);
 			break; case 'c': binds[n++] = Bind(":context", optarg, 0);
 			break; case 'd': path = optarg;
+			break; case 'f': format = parseFormat(optarg);
 			break; case 'g': group = true;
 			break; case 'h': binds[n++] = Bind(":host", optarg, 0);
 			break; case 'l': binds[n++] = Bind(":limit", optarg, 0);
@@ -256,7 +275,6 @@ int main(int argc, char *argv[]) {
 		err(EX_UNAVAILABLE, "sqlite3");
 	}
 
-	bool tty = isatty(STDOUT_FILENO);
 	if (tty) {
 		const char *pager = getenv("PAGER");
 		if (!pager) pager = "less";
@@ -312,7 +330,7 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
-	if (tty) {
+	if (format == formatColor) {
 		dbBindText(stmt, ":open", "\33[7m");
 		dbBindText(stmt, ":close", "\33[27m");
 	} else {
@@ -328,8 +346,6 @@ int main(int argc, char *argv[]) {
 		sqlite3_free(expand);
 	}
 
-	Format *format = (tty ? formatColor : formatPlain);
-
 	int result;
 	while (SQLITE_ROW == (result = sqlite3_step(stmt))) {
 		struct Event event = {
ff32e7&follow=1'>configfile.c: don't include system headers directlyJohn Keeping 2015-08-13Remove redundant includesJohn Keeping 2015-08-13Makefile: include Git's config.mak.unameJohn Keeping 2015-08-13tests: allow shell to be overriddenJohn Keeping 2015-08-13redirect: cleanlinessJason A. Donenfeld 2015-08-13redirect: be more careful for different cgi setupsJason A. Donenfeld 2015-08-12ui-log: fix double countingJohn Keeping 2015-08-12log: allow users to follow a fileJohn Keeping 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld 2015-08-12filters: apply HTML escapingLazaros Koromilas 2015-08-12git: update to v2.5.0Christian Hesse 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt