diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-25 10:35:06 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-01 17:10:09 +0100 |
commit | 0365e093104248439c6df595fcf38d102b2c2fb9 (patch) | |
tree | 82a66a25adfbf1a6c4f791f018a21a8f3597cab1 | |
parent | fff4901b230b314e34e738f26809ba7d675f45a5 (diff) |
Added a first box dynamically to the center
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 22 | ||||
-rw-r--r-- | src/messenger_cli.c | 60 |
2 files changed, 67 insertions, 15 deletions
@@ -6,17 +6,17 @@ BINARY = messenger-cli SOURCES = messenger_cli.c HEADERS = -LIBRARIES = gnunetchat gnunetutil +LIBRARIES = gnunetchat gnunetutil ncurses -CC ?= gcc -LD ?= gcc -RM ?= rm +GNU_CC ?= gcc +GNU_LD ?= gcc +GNU_RM ?= rm -CFLAGS += -pedantic -Wall -Wextra -march=native -ggdb3 +CFLAGS += -pedantic -Wall -Wextra -ggdb3 -Wno-overlength-strings LDFLAGS += DEBUGFLAGS = -O0 -D _DEBUG -RELEASEFLAGS = -O2 -D NDEBUG -fwhole-program +RELEASEFLAGS = -O2 -D NDEBUG SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES)) OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) @@ -32,10 +32,10 @@ release: CFLAGS += $(RELEASEFLAGS) release: $(BINARY) %.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ $(LIBRARY_FLAGS) + $(GNU_CC) $(CFLAGS) -c $< -o $@ $(LIBRARY_FLAGS) $(BINARY): $(OBJECT_FILES) - $(LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) + $(GNU_LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) .PHONY: install @@ -45,10 +45,10 @@ install: .PHONY: uninstall uninstall: - $(RM) -f $(addsuffix $(BINARY), $(addprefix $(INSTALL_DIR), bin/)) + $(GNU_RM) -f $(addsuffix $(BINARY), $(addprefix $(INSTALL_DIR), bin/)) .PHONY: clean clean: - $(RM) -f $(BINARY) - $(RM) -f $(OBJECT_FILES) + $(GNU_RM) -f $(BINARY) + $(GNU_RM) -f $(OBJECT_FILES) diff --git a/src/messenger_cli.c b/src/messenger_cli.c index 253a1ae..97ab83d 100644 --- a/src/messenger_cli.c +++ b/src/messenger_cli.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--2022 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -22,10 +22,14 @@ * @file messenger_cli.c */ +#include <stdlib.h> +#include <curses.h> + #include <gnunet/platform.h> #include <gnunet/gnunet_chat_lib.h> #include <gnunet/gnunet_util_lib.h> + static void run (void *cls, char* const* args, const char *cfgfile, @@ -34,12 +38,60 @@ run (void *cls, char* const* args, struct GNUNET_CHAT_Handle *handle = GNUNET_CHAT_start( cfg, "appdir", - "username", - NULL, NULL, NULL, NULL ); - // + initscr(); + noecho(); + + int bx, by, mx, my; + getbegyx(stdscr, by, bx); + getmaxyx(stdscr, my, mx); + + WINDOW *win = newwin(15, 30, by + (my - by - 15) / 2, bx + (mx - bx - 30) / 2); + + char c; + do { + getbegyx(stdscr, by, bx); + getmaxyx(stdscr, my, mx); + + int x = bx + (mx - bx - 30) / 2; + int y = by + (my - by - 15) / 2; + + int w = 30; + int h = 15; + + if (mx - x < w) + w = (mx - x > 0? mx - x : 0); + + if (my - y < h) + h = (my - y > 0? my - y : 0); + + if (w * h > 0) + { + mvwin(win, y, x); + wresize(win, h, w); + + werase(win); + box(win, 0, 0); + + wmove(win, 1, 1); + wprintw(win, "%d %d, %d %d", bx, by, mx, my); + + c = wgetch(win); + } + else + { + c = getch(); + } + + clear(); + refresh(); + } while (c != 'q'); + + delwin(win); + + endwin(); GNUNET_CHAT_stop(handle); } |