summaryrefslogtreecommitdiffstats
path: root/tis-curses.c
diff options
context:
space:
mode:
Diffstat (limited to 'tis-curses.c')
-rw-r--r--tis-curses.c86
1 files changed, 49 insertions, 37 deletions
diff --git a/tis-curses.c b/tis-curses.c
index ea108a3..157b102 100644
--- a/tis-curses.c
+++ b/tis-curses.c
@@ -42,6 +42,10 @@ enum {
COLOR_VAL
};
+static const char *mode_repr[] = {
+ "IDL", "RUN", "REA", "WRI"
+};
+
static int scrx = 0;
static int scry = 0;
static int scrw = 80;
@@ -60,21 +64,6 @@ static struct tpu *tpu_sel = NULL;
int (*cleanup)(void) = endwin;
const char *progname = "tis-curses";
-static const char *
-tpu_mode_str(struct tpu *tpu)
-{
- switch (tpu->status) {
- case STATUS_READ:
- return "=R=";
- case STATUS_WRITE:
- return "=W=";
- case STATUS_IDLE:
- return "=I=";
- case STATUS_RUN:
- return "=X=";
- }
-}
-
static enum tpu_port_dir
key_to_dir(int key)
{
@@ -92,11 +81,19 @@ key_to_dir(int key)
}
}
-static const char *
-tpu_last_str(struct tpu *tpu)
+static const cchar_t *
+dir_to_arrow(enum tpu_port_dir dir)
{
- if (tpu->last < 0) return "N/A";
- return dir_reprs[tpu->last];
+ switch (dir) {
+ case DIR_UP:
+ return WACS_UARROW;
+ case DIR_DOWN:
+ return WACS_DARROW;
+ case DIR_LEFT:
+ return WACS_LARROW;
+ case DIR_RIGHT:
+ return WACS_RARROW;
+ }
}
static int
@@ -226,12 +223,21 @@ tui_draw_tpu(struct tpu *tpu)
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_LTEE, WACS_D_RTEE);
tui_draw_text(x + 2, y + 1, A_BOLD, "LST");
- tui_draw_text(x + 2, y + 2, 0, "%s", tpu_last_str(tpu));
+ if (tpu->last < 0) {
+ tui_draw_text(x + 2, y + 2, 0, "N/A");
+ } else {
+ tui_draw_wch(x + 2, y + 2, 0,
+ dir_to_arrow((enum tpu_port_dir) tpu->last));
+ tui_draw_wch(x + 3, y + 2, 0,
+ dir_to_arrow((enum tpu_port_dir) tpu->last));
+ tui_draw_wch(x + 4, y + 2, 0,
+ dir_to_arrow((enum tpu_port_dir) tpu->last));
+ }
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_LTEE, WACS_D_RTEE);
tui_draw_text(x + 2, y + 1, A_BOLD, "MOD");
- tui_draw_text(x + 2, y + 2, 0, "%s", tpu_mode_str(tpu));
+ tui_draw_text(x + 2, y + 2, 0, "%s", mode_repr[tpu->status]);
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_BTEE, WACS_D_LRCORNER);
@@ -292,18 +298,18 @@ tui_draw_tpu(struct tpu *tpu)
if (tpu->ports[DIR_DOWN].attached) {
port = &tpu->ports[DIR_DOWN];
- if (port->out >= 0)
+ if (port->in >= 0)
tui_draw_text(sx + 9, sy + TPU_H,
- A_BOLD, "%03i", port->out);
+ A_BOLD, "%03i", port->in);
if (port->type & PORT_IN)
tui_draw_wch(sx + 13, sy + TPU_H,
port->in >= 0 ? A_BOLD : 0, WACS_UARROW);
if (port->type & PORT_OUT)
tui_draw_wch(sx + 15, sy + TPU_H,
port->out >= 0 ? A_BOLD : 0, WACS_DARROW);
- if (port->in >= 0)
+ if (port->out >= 0)
tui_draw_text(sx + 17, sy + TPU_H,
- A_BOLD, "%03i", port->in);
+ A_BOLD, "%03i", port->out);
}
}
@@ -397,13 +403,15 @@ handlekey(int key)
scrx += 4;
break;
case 's':
- if (tis.stdin_port.attached && tis.stdin_port.out < 0) {
+ if (tis_stdin && tis.stdin_port.attached
+ && tis.stdin_port.out < 0) {
c = getc(tis_stdin);
if (c >= 0) tis.stdin_port.out = c;
}
if (tis.stdout_port.attached && tis.stdout_port.in >= 0) {
- putc(tis.stdout_port.in, tis_stdout);
+ if (tis_stdout)
+ putc(tis.stdout_port.in, tis_stdout);
tis.stdout_port.in = -1;
}
@@ -450,13 +458,17 @@ reset(int ifd, int argc, char **argv, bool watch)
if (inotify_add_watch(ifd, argv[1], IN_MODIFY) < 0)
die("inotify_add_watch '%s':", argv[1]);
- if (tis_stdin) fclose(tis_stdin);
- tis_stdin = fopen(argv[2], "r");
- if (!tis_stdin) die("fopen '%s':", argv[2]);
+ if (argc >= 3) {
+ if (tis_stdin) fclose(tis_stdin);
+ tis_stdin = fopen(argv[2], "r");
+ if (!tis_stdin) die("fopen '%s':", argv[2]);
+ }
- if (tis_stdout) fclose(tis_stdout);
- tis_stdout = fopen(argv[3], "w+");
- if (!tis_stdout) die("fopen '%s':", argv[3]);
+ if (argc >= 4) {
+ if (tis_stdout) fclose(tis_stdout);
+ tis_stdout = fopen(argv[3], "w+");
+ if (!tis_stdout) die("fopen '%s':", argv[3]);
+ }
if (tis.stdin_port.attached) {
tpu_sel = tis.stdin_port.dst_tpu;
@@ -476,8 +488,8 @@ main(int argc, char **argv)
int key;
int ifd;
- if (argc != 4) {
- fprintf(stderr, "Usage: tis-curses FILE STDIN STDOUT\n");
+ if (argc < 2 || argc > 4) {
+ fprintf(stderr, "Usage: tis-curses FILE [STDIN] [STDOUT]\n");
exit(1);
}
@@ -546,8 +558,8 @@ main(int argc, char **argv)
close(ifd);
- fclose(tis_stdin);
- fclose(tis_stdout);
+ if (tis_stdin) fclose(tis_stdin);
+ if (tis_stdout) fclose(tis_stdout);
endwin();
}