From c644597eac7cf97a71aef99103b499c71bd8fe99 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 28 Apr 2024 20:49:27 -0700
Subject: [PATCH] Fixed issue with delayed output

---
 src/modal.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/modal.c b/src/modal.c
index 8d20a94..ebc959a 100644
--- a/src/modal.c
+++ b/src/modal.c
@@ -132,7 +132,7 @@ write_reg(char r, char *reg)
 }
 
 static int
-write_tail(char *s)
+write_tail(char *s, Rule *r)
 {
 	while((*dst_++ = *s++))
 		;
@@ -141,6 +141,7 @@ write_tail(char *s)
 		src_ = bank_b, dst_ = bank_a;
 	else
 		src_ = bank_a, dst_ = bank_b;
+	if(!quiet && r) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
 	return 1;
 }
 
@@ -190,8 +191,7 @@ apply_rule(Rule *r, char *s)
 		while(*s == ' ') s++;
 		if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
 	}
-	if(!quiet && r) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
-	return write_tail(s);
+	return write_tail(s, r);
 }
 
 static char *
@@ -244,7 +244,7 @@ rewrite(void)
 					r->a = 0;
 				}
 				while(*cap == ' ') cap++;
-				return write_tail(cap);
+				return write_tail(cap, NULL);
 			}
 			/* phase: define */
 			if(c == '<' && s[1] == '>') {
@@ -255,7 +255,7 @@ rewrite(void)
 					rules_++;
 				}
 				while(*s == ' ') s++;
-				return write_tail(s);
+				return write_tail(s, NULL);
 			}
 			/* phase: lambda */
 			if(c == '?' && s[1] == '(') {
@@ -264,7 +264,7 @@ rewrite(void)
 				parse_frag(&r->b, parse_frag(&r->a, s + 2));
 				s = cap;
 				while(*s == ' ') s++;
-				if(!apply_rule(&lambda, s)) write_tail(s);
+				if(!apply_rule(&lambda, s)) write_tail(s, r);
 				return 1;
 			}
 			/* phase: match */