about summary refs log tree commit diff
path: root/lr.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-07-27 14:09:10 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-07-27 14:09:10 +0200
commitedb2abe085f47b35c9379ee6deccf9223cb95d21 (patch)
treeb768ee0bf86a52b8aba395713dd9457639f80d3f /lr.c
parenta6f21a1f4e70a1db354c9927c4b3938759faf033 (diff)
downloadlr-edb2abe085f47b35c9379ee6deccf9223cb95d21.tar.gz
lr-edb2abe085f47b35c9379ee6deccf9223cb95d21.tar.xz
lr-edb2abe085f47b35c9379ee6deccf9223cb95d21.zip
lr: add action "color <num>" to override colors
Diffstat (limited to 'lr.c')
-rw-r--r--lr.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lr.c b/lr.c
index d26e963..a92dcb8 100644
--- a/lr.c
+++ b/lr.c
@@ -165,6 +165,7 @@ enum op {
 	EXPR_REGEXI,
 	EXPR_PRUNE,
 	EXPR_PRINT,
+	EXPR_COLOR,
 	EXPR_TYPE,
 	EXPR_ALLSET,
 	EXPR_ANYSET,
@@ -397,6 +398,16 @@ parse_inner()
 	} else if (token("print")) {
 		struct expr *e = mkexpr(EXPR_PRINT);
 		return e;
+	} else if (token("color")) {
+		struct expr *e = mkexpr(EXPR_COLOR);
+		int64_t n;
+		if (parse_num(&n) && n >= 0 && n <= 255) {
+			e->a.num = n;
+			return e;
+		} else {
+			parse_error("invalid 256-color at '%.15s'", pos);
+			return 0;
+		}
 	} else if (token("!")) {
 		struct expr *e = parse_cmp();
 		struct expr *not = mkexpr(EXPR_NOT);
@@ -1140,6 +1151,9 @@ eval(struct expr *e, struct fileinfo *fi)
 		return 1;
 	case EXPR_PRINT:
 		return 1;
+	case EXPR_COLOR:
+		fi->color = e->a.num;
+		return 1;
 	case EXPR_LT:
 	case EXPR_LE:
 	case EXPR_EQ:
@@ -1217,6 +1231,8 @@ eval(struct expr *e, struct fileinfo *fi)
 		case EXPR_REGEXI: return regexec(e->b.regex, s, 0, 0, 0) == 0;
 		}
 	}
+	default:
+		parse_error("invalid operation %d, please file a bug.", e->op);
 	}
 
 	return 0;