commit 91900aac4aeaff9b08e66a9b51c3a9723db5ed26
parent 772ecb60cf54c48e5bc8fb815afbb9ddbb19b408
Author: Sophie <info@soophie.de>
Date: Sun, 2 Feb 2025 10:24:32 +0100
feat: Added responsive rendering
Diffstat:
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/rx.c b/src/rx.c
@@ -181,16 +181,24 @@ void rx_draw(rx_t *self) {
term_write("\x1b[2J");
term_write("\x1b[H");
term_write("\r\n");
- for (size_t i = 0; i < self->stations_len; i++) {
- const rx_station_t *station = &self->stations[i];
- if (i == (size_t) self->idx) {
+ int rows = 0;
+ int cols = 0;
+ term_read_window_size(&rows, &cols);
+ size_t len = rows - 5;
+ for (size_t i = 0; i < len; i++) {
+ if (i + self->idx >= self->stations_len) {
+ term_write("\r\n");
+ continue;
+ }
+ const rx_station_t *station = &self->stations[i + self->idx];
+ if (i + self->idx == (size_t) self->idx) {
term_write("> ");
}
else {
term_write(" ");
}
int pad = 3; // floor(log10(self->stations_len) + 1);
- term_writef("%0*d ", pad, i + 1);
+ term_writef("%0*d ", pad, i + self->idx + 1);
term_writef("[%s] %s", station->uid, station->name);
if (station->addr != NULL) {
term_writef(" (%s)", station->addr);
@@ -218,6 +226,10 @@ void rx_draw(rx_t *self) {
}
}
}
+ else {
+ term_write("[???] no station\r\n");
+ term_write("...\r\n");
+ }
term_flush();
}