aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-28 00:22:13 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-28 00:22:13 -0700
commit00a1977ad6e28ddfc59064accba0801e1627915b (patch)
treec5593782d980c5138cb5694df66376caaddebcd2 /pw.c
parent12073e3c27b0b571dd340fd7a587c90427042ff3 (diff)
downloadpw-00a1977ad6e28ddfc59064accba0801e1627915b.tar.gz
pw-00a1977ad6e28ddfc59064accba0801e1627915b.tar.bz2
pw-00a1977ad6e28ddfc59064accba0801e1627915b.zip
grep: show patterns in status rather than stack depth.
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/pw.c b/pw.c
index 34e5feb..8aa8cf9 100644
--- a/pw.c
+++ b/pw.c
@@ -31,7 +31,7 @@ typedef struct grep {
int inv;
} grep;
-#define cmdsize 100
+#define cmdsize 256
#define maxgrep 64
typedef struct dstr {
@@ -210,26 +210,44 @@ static void clrline()
printf("\r\033[J");
}
-static void drawstatus(unsigned stat, char *cmd)
+static void drawstatus(int columns, unsigned stat, char *cmd)
{
+ char status[cmdsize] = "", *ptr = status;
+ size_t lim = sizeof status;
+
+ if (columns - 1 < (int) lim)
+ lim = columns - 1;
+
+ char *end = ptr + lim;
+
if (cmd) {
- printf("%s", cmd);
+ snprintf(status, lim, "%s", cmd);
} else if ((stat & (stat_eof | stat_susp | stat_htmode | stat_ttmode |
stat_grep)))
{
if ((stat & stat_eof))
- printf("EOF ");
- if ((stat & stat_grep))
- printf("GREP (%d) ", ngrep);
+ ptr += snprintf(ptr, end - ptr, "EOF ");
+
+ if ((stat & stat_grep)) {
+ ptr += snprintf(ptr, end - ptr, "GREP (");
+ for (int i = 0; i < ngrep; i++) {
+ grep *gr = &grepstack[i];
+ ptr += snprintf(ptr, end - ptr, "%s%s%c ",
+ gr->inv ? "!" : "", gr->pat,
+ (i < ngrep - 1) ? ',' : ')');
+ }
+ }
+
if ((stat & stat_htmode))
- printf("TRIG (/%s) ", trigpat);
+ ptr += snprintf(ptr, end - ptr, "TRIG (/%s) ", trigpat);
else if ((stat & stat_ttmode))
- printf("TRIG (?%s) ", trigpat);
+ ptr += snprintf(ptr, end - ptr, "TRIG (?%s) ", trigpat);
+
if ((stat & stat_susp))
- printf("SUSPENDED ");
- } else {
- clrline();
+ ptr += snprintf(ptr, end - ptr, "SUSPENDED ");
}
+
+ fputs(status, stdout);
fflush(stdout);
}
@@ -255,7 +273,7 @@ static void redraw(char **circbuf, int nlines, int hpos,
for (int i = 0; i < snaplines; i++)
drawline(snapshot[i], hpos, columns);
}
- drawstatus(stat, cmd);
+ drawstatus(columns, stat, cmd);
}
static void execute(char *cmd, unsigned *pstat)
@@ -524,7 +542,7 @@ int main(int argc, char **argv)
snapshot[snaplines++] = dsref(line);
clrline();
drawline(line, hpos, columns);
- drawstatus(stat, curcmd);
+ drawstatus(columns, stat, curcmd);
}
}
line = 0;
@@ -577,7 +595,7 @@ int main(int argc, char **argv)
kbd_state = kbd_cmd;
curcmd = 0;
clrline();
- drawstatus(stat, curcmd);
+ drawstatus(columns, stat, curcmd);
}
}
} else {
@@ -751,7 +769,7 @@ int main(int argc, char **argv)
} else switch (kbd_state) {
case kbd_colon: case kbd_htrig: case kbd_ttrig: case kbd_result:
clrline();
- drawstatus(stat, curcmd);
+ drawstatus(columns, stat, curcmd);
}
}
}