summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-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 = {
='logmsg'> Use Git string lists instead of str{spn,cspn,ncmp}() magic. This significantly improves readability. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer Since the introduction of selective snapshot format configuration in dc3c9b5 (allow selective enabling of snapshots, 2007-07-21), we allowed seven different delimiters for snapshot formats, while the documentation has always been clear about spaces being the only valid delimiter: The value is a space-separated list of zero or more of the values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". Supporting the undocumented delimiters makes the code unnecessarily complex. Remove them. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer This is a preparation for replacing all prefix checks with either strip_prefix() or starts_with() when Git 1.8.6 is released. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-09README: Fix dependenciesLukas Fleischer * Remove the dependency on Git (which can be obtained automatically when building, using either the Git submodule or `make get-git`). * Use proper upstream names of dependencies. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-08README: Spelling and formatting fixesLukas Fleischer * Several small spelling and capitalization fixes. * Use consistent and better-looking formatting that is compatible with AsciiDoc (and partly compatible with RST). Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch Previously the script tried to encode output from Pygments with the ASCII codec, which failed. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Add a suggestion to the manpagePřemysl Janouch So that people wishing to use "enable-http-clone" don't have to find out the correct settings on their own. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Fix the example configurationPřemysl Janouch "enable-git-clone" doesn't exist, replaced with "enable-http-clone". Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Fix about-formatting.shPřemysl Janouch dash failed to parse the script. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Fix some spelling errorsPřemysl Janouch Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts