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) | |
download | messenger-cli-0365e093104248439c6df595fcf38d102b2c2fb9.tar.gz messenger-cli-0365e093104248439c6df595fcf38d102b2c2fb9.zip |
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 | |||
6 | SOURCES = messenger_cli.c | 6 | SOURCES = messenger_cli.c |
7 | HEADERS = | 7 | HEADERS = |
8 | 8 | ||
9 | LIBRARIES = gnunetchat gnunetutil | 9 | LIBRARIES = gnunetchat gnunetutil ncurses |
10 | 10 | ||
11 | CC ?= gcc | 11 | GNU_CC ?= gcc |
12 | LD ?= gcc | 12 | GNU_LD ?= gcc |
13 | RM ?= rm | 13 | GNU_RM ?= rm |
14 | 14 | ||
15 | CFLAGS += -pedantic -Wall -Wextra -march=native -ggdb3 | 15 | CFLAGS += -pedantic -Wall -Wextra -ggdb3 -Wno-overlength-strings |
16 | LDFLAGS += | 16 | LDFLAGS += |
17 | 17 | ||
18 | DEBUGFLAGS = -O0 -D _DEBUG | 18 | DEBUGFLAGS = -O0 -D _DEBUG |
19 | RELEASEFLAGS = -O2 -D NDEBUG -fwhole-program | 19 | RELEASEFLAGS = -O2 -D NDEBUG |
20 | 20 | ||
21 | SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES)) | 21 | SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES)) |
22 | OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) | 22 | OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) |
@@ -32,10 +32,10 @@ release: CFLAGS += $(RELEASEFLAGS) | |||
32 | release: $(BINARY) | 32 | release: $(BINARY) |
33 | 33 | ||
34 | %.o: %.c | 34 | %.o: %.c |
35 | $(CC) $(CFLAGS) -c $< -o $@ $(LIBRARY_FLAGS) | 35 | $(GNU_CC) $(CFLAGS) -c $< -o $@ $(LIBRARY_FLAGS) |
36 | 36 | ||
37 | $(BINARY): $(OBJECT_FILES) | 37 | $(BINARY): $(OBJECT_FILES) |
38 | $(LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) | 38 | $(GNU_LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) |
39 | 39 | ||
40 | .PHONY: install | 40 | .PHONY: install |
41 | 41 | ||
@@ -45,10 +45,10 @@ install: | |||
45 | .PHONY: uninstall | 45 | .PHONY: uninstall |
46 | 46 | ||
47 | uninstall: | 47 | uninstall: |
48 | $(RM) -f $(addsuffix $(BINARY), $(addprefix $(INSTALL_DIR), bin/)) | 48 | $(GNU_RM) -f $(addsuffix $(BINARY), $(addprefix $(INSTALL_DIR), bin/)) |
49 | 49 | ||
50 | .PHONY: clean | 50 | .PHONY: clean |
51 | 51 | ||
52 | clean: | 52 | clean: |
53 | $(RM) -f $(BINARY) | 53 | $(GNU_RM) -f $(BINARY) |
54 | $(RM) -f $(OBJECT_FILES) | 54 | $(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 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021--2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -22,10 +22,14 @@ | |||
22 | * @file messenger_cli.c | 22 | * @file messenger_cli.c |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <stdlib.h> | ||
26 | #include <curses.h> | ||
27 | |||
25 | #include <gnunet/platform.h> | 28 | #include <gnunet/platform.h> |
26 | #include <gnunet/gnunet_chat_lib.h> | 29 | #include <gnunet/gnunet_chat_lib.h> |
27 | #include <gnunet/gnunet_util_lib.h> | 30 | #include <gnunet/gnunet_util_lib.h> |
28 | 31 | ||
32 | |||
29 | static void | 33 | static void |
30 | run (void *cls, char* const* args, | 34 | run (void *cls, char* const* args, |
31 | const char *cfgfile, | 35 | const char *cfgfile, |
@@ -34,12 +38,60 @@ run (void *cls, char* const* args, | |||
34 | struct GNUNET_CHAT_Handle *handle = GNUNET_CHAT_start( | 38 | struct GNUNET_CHAT_Handle *handle = GNUNET_CHAT_start( |
35 | cfg, | 39 | cfg, |
36 | "appdir", | 40 | "appdir", |
37 | "username", | ||
38 | NULL, NULL, | ||
39 | NULL, NULL | 41 | NULL, NULL |
40 | ); | 42 | ); |
41 | 43 | ||
42 | // | 44 | initscr(); |
45 | noecho(); | ||
46 | |||
47 | int bx, by, mx, my; | ||
48 | getbegyx(stdscr, by, bx); | ||
49 | getmaxyx(stdscr, my, mx); | ||
50 | |||
51 | WINDOW *win = newwin(15, 30, by + (my - by - 15) / 2, bx + (mx - bx - 30) / 2); | ||
52 | |||
53 | char c; | ||
54 | do { | ||
55 | getbegyx(stdscr, by, bx); | ||
56 | getmaxyx(stdscr, my, mx); | ||
57 | |||
58 | int x = bx + (mx - bx - 30) / 2; | ||
59 | int y = by + (my - by - 15) / 2; | ||
60 | |||
61 | int w = 30; | ||
62 | int h = 15; | ||
63 | |||
64 | if (mx - x < w) | ||
65 | w = (mx - x > 0? mx - x : 0); | ||
66 | |||
67 | if (my - y < h) | ||
68 | h = (my - y > 0? my - y : 0); | ||
69 | |||
70 | if (w * h > 0) | ||
71 | { | ||
72 | mvwin(win, y, x); | ||
73 | wresize(win, h, w); | ||
74 | |||
75 | werase(win); | ||
76 | box(win, 0, 0); | ||
77 | |||
78 | wmove(win, 1, 1); | ||
79 | wprintw(win, "%d %d, %d %d", bx, by, mx, my); | ||
80 | |||
81 | c = wgetch(win); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | c = getch(); | ||
86 | } | ||
87 | |||
88 | clear(); | ||
89 | refresh(); | ||
90 | } while (c != 'q'); | ||
91 | |||
92 | delwin(win); | ||
93 | |||
94 | endwin(); | ||
43 | 95 | ||
44 | GNUNET_CHAT_stop(handle); | 96 | GNUNET_CHAT_stop(handle); |
45 | } | 97 | } |