aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-11 22:21:47 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-11 22:21:47 +0300
commit6ea977db5faa9342c90a4feb81a19182b55ab574 (patch)
treeed675fddf40669cc36b682a6bee4f4c7dc745b46
parentd676ac91b1906f5de8695facb6b96bf0509e6e1f (diff)
downloadastar-6ea977db5faa9342c90a4feb81a19182b55ab574.tar.xz
Add macro to print a message
-rw-r--r--main.c6
-rw-r--r--map.c6
-rw-r--r--map.h5
-rw-r--r--path.c2
4 files changed, 10 insertions, 9 deletions
diff --git a/main.c b/main.c
index 74e283f..154fc9a 100644
--- a/main.c
+++ b/main.c
@@ -179,8 +179,7 @@ int main(int argc, char **argv) {
}
break;
case 's':
- move(height + map_offset_y + 1, map_offset_x - 2); clrtoeol(); /* Clears the line */
- mvprintw(height + map_offset_y + 1, map_offset_x - 2, "Filename: ");
+ message(height, "Filename: ");
/* TODO: figure out how to show the cursor and echo the characters */
curs_set(2); /* Hide the cursor */
echo(); /* Don't echo characters */
@@ -189,8 +188,7 @@ int main(int argc, char **argv) {
noecho(); /* Don't echo characters */
mvgetnstr(height + map_offset_y + 1, map_offset_x - 2, filename, FILENAME_BUF_SIZE - 1);
map_to_bmp(map, width, height, start_pos, end_pos, path, visited, filename);
- move(height + map_offset_y + 1, map_offset_x - 2); clrtoeol(); /* Clears the line */
- mvprintw(height + map_offset_y + 1, map_offset_x - 2, "Saved to %s", filename);
+ message(height, "Saved to %s", filename);
getch();
break;
case 'n':
diff --git a/map.c b/map.c
index 3bd7500..57f1c65 100644
--- a/map.c
+++ b/map.c
@@ -10,8 +10,6 @@
#include "path.h"
#include "priority_queue.h"
-/* TODO: function to print a message maybe */
-
int map_offset_x = 2;
int map_offset_y = 1;
@@ -348,7 +346,7 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
cur = path[cur.y][cur.x].parent;
}
attroff(COLOR_PAIR(PATH_COLOR));
- mvprintw(height + map_offset_y + 1, map_offset_x - 2, "Path cost: %zu", length);
+ message(height, "Path cost: %zu", length);
}
/* Draw the start */
@@ -400,7 +398,7 @@ void print_map_out(Map map, size_t width, size_t height) {
void map_editor(Map *map, size_t *width, size_t *height, Position *start, Position *goal) {
clear();
draw_map(*map, *width, *height, *start, *goal, NULL, NULL, NULL, NULL);
- mvprintw(*height + map_offset_y + 1, map_offset_x - 2, "You've entered the map editor. 'q' to quit");
+ message(*height, "You've entered the map editor. 'q' to quit");
MEVENT event;
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
diff --git a/map.h b/map.h
index fef684c..e9c5bc3 100644
--- a/map.h
+++ b/map.h
@@ -6,6 +6,11 @@
#include "path.h"
#include "priority_queue.h"
+/* Prints a message at the line right below the map. Multiline messages are undefined behaviour */
+#define message(height, ...) { \
+ if (move((height) + map_offset_y + 1, map_offset_x - 2) != ERR) { clrtoeol(); /* Clear the line */\
+ mvprintw((height) + map_offset_y + 1, map_offset_x - 2, __VA_ARGS__); }}
+
extern int map_offset_x;
extern int map_offset_y;
diff --git a/path.c b/path.c
index 8145c01..e27723b 100644
--- a/path.c
+++ b/path.c
@@ -18,7 +18,7 @@ int anim(Map map, size_t width, size_t height, Position start, Position end, Pos
static char automatic = 0;
while (1) {
draw_map(map, width, height, start, end, cur, NULL, visited, frontier);
- mvprintw(height+2 + map_offset_y - 1, map_offset_x - 2, "cur: %zu %zu", cur->x, cur->y);
+ message(height, "cur: %zu %zu", cur->x, cur->y);
if (automatic) { usleep(ANIM_DELAY_USEC); return 0; }
switch (getch()) {
case 'h': map_offset_x -= 2; break;