aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-25 10:35:06 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-01 17:10:09 +0100
commit0365e093104248439c6df595fcf38d102b2c2fb9 (patch)
tree82a66a25adfbf1a6c4f791f018a21a8f3597cab1
parentfff4901b230b314e34e738f26809ba7d675f45a5 (diff)
downloadmessenger-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--Makefile22
-rw-r--r--src/messenger_cli.c60
2 files changed, 67 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 8d96510..41fc57e 100644
--- a/Makefile
+++ b/Makefile
@@ -6,17 +6,17 @@ BINARY = messenger-cli
6SOURCES = messenger_cli.c 6SOURCES = messenger_cli.c
7HEADERS = 7HEADERS =
8 8
9LIBRARIES = gnunetchat gnunetutil 9LIBRARIES = gnunetchat gnunetutil ncurses
10 10
11CC ?= gcc 11GNU_CC ?= gcc
12LD ?= gcc 12GNU_LD ?= gcc
13RM ?= rm 13GNU_RM ?= rm
14 14
15CFLAGS += -pedantic -Wall -Wextra -march=native -ggdb3 15CFLAGS += -pedantic -Wall -Wextra -ggdb3 -Wno-overlength-strings
16LDFLAGS += 16LDFLAGS +=
17 17
18DEBUGFLAGS = -O0 -D _DEBUG 18DEBUGFLAGS = -O0 -D _DEBUG
19RELEASEFLAGS = -O2 -D NDEBUG -fwhole-program 19RELEASEFLAGS = -O2 -D NDEBUG
20 20
21SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES)) 21SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES))
22OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) 22OBJECT_FILES = $(SOURCE_FILES:%.c=%.o)
@@ -32,10 +32,10 @@ release: CFLAGS += $(RELEASEFLAGS)
32release: $(BINARY) 32release: $(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
47uninstall: 47uninstall:
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
52clean: 52clean:
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
29static void 33static void
30run (void *cls, char* const* args, 34run (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}