aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build6
-rw-r--r--src/application.c56
-rw-r--r--src/chat.c17
-rw-r--r--src/util.c18
-rw-r--r--src/util.h13
5 files changed, 96 insertions, 14 deletions
diff --git a/meson.build b/meson.build
index 1470be3..d46f2f9 100644
--- a/meson.build
+++ b/meson.build
@@ -35,11 +35,17 @@ messenger_cli_deps = [
35 dependency('ncurses'), 35 dependency('ncurses'),
36] 36]
37 37
38messenger_cli_args = [
39 '-DMESSENGER_CLI_BINARY="@0@"'.format(meson.project_name()),
40 '-DMESSENGER_CLI_VERSION="@0@"'.format(meson.project_version()),
41]
42
38subdir('src') 43subdir('src')
39 44
40messenger_cli_exec = executable( 45messenger_cli_exec = executable(
41 'messenger-cli', 46 'messenger-cli',
42 messenger_cli_sources, 47 messenger_cli_sources,
48 c_args: messenger_cli_args,
43 install: true, 49 install: true,
44 dependencies: messenger_cli_deps, 50 dependencies: messenger_cli_deps,
45 include_directories: src_directory, 51 include_directories: src_directory,
diff --git a/src/application.c b/src/application.c
index 57fb45c..1b2bdbd 100644
--- a/src/application.c
+++ b/src/application.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2022--2023 GNUnet e.V. 3 Copyright (C) 2022--2024 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
@@ -26,6 +26,18 @@
26 26
27#include "util.h" 27#include "util.h"
28 28
29#ifndef MESSENGER_CLI_BINARY
30#define MESSENGER_CLI_BINARY "messenger_cli"
31#endif
32
33#ifndef MESSENGER_CLI_VERSION
34#define MESSENGER_CLI_VERSION "unknown"
35#endif
36
37#ifndef MESSENGER_CLI_DESC
38#define MESSENGER_CLI_DESC "A CLI for the Messenger service of GNUnet."
39#endif
40
29void 41void
30application_clear(MESSENGER_Application *app) 42application_clear(MESSENGER_Application *app)
31{ 43{
@@ -37,14 +49,34 @@ application_clear(MESSENGER_Application *app)
37 49
38void 50void
39application_init(MESSENGER_Application *app, 51application_init(MESSENGER_Application *app,
40 int argc, 52 int argc,
41 char **argv) 53 char **argv)
42{ 54{
55 const struct GNUNET_GETOPT_CommandLineOption options [] = {
56 GNUNET_GETOPT_option_version(MESSENGER_CLI_VERSION),
57 GNUNET_GETOPT_option_help(MESSENGER_CLI_DESC),
58 GNUNET_GETOPT_OPTION_END
59 };
60
43 memset(app, 0, sizeof(*app)); 61 memset(app, 0, sizeof(*app));
44 62
45 app->argc = argc; 63 app->argc = argc;
46 app->argv = argv; 64 app->argv = argv;
47 65
66 const int parsing = GNUNET_GETOPT_run(
67 MESSENGER_CLI_BINARY,
68 options,
69 app->argc,
70 app->argv
71 );
72
73 if (parsing <= 0)
74 {
75 app->window = NULL;
76 app->status = GNUNET_SYSERR == parsing? GNUNET_SYSERR : GNUNET_OK;
77 return;
78 }
79
48 app->window = initscr(); 80 app->window = initscr();
49 81
50 if (!(app->window)) 82 if (!(app->window))
@@ -92,18 +124,18 @@ run (void *cls,
92void 124void
93application_run(MESSENGER_Application *app) 125application_run(MESSENGER_Application *app)
94{ 126{
95 struct GNUNET_GETOPT_CommandLineOption options[] = { 127 const struct GNUNET_GETOPT_CommandLineOption options [] = {
96 GNUNET_GETOPT_OPTION_END 128 GNUNET_GETOPT_OPTION_END
97 }; 129 };
98 130
99 app->status = GNUNET_PROGRAM_run( 131 app->status = GNUNET_PROGRAM_run(
100 app->argc, 132 1,
101 app->argv, 133 app->argv,
102 "messenger_cli", 134 MESSENGER_CLI_BINARY,
103 gettext_noop("A CLI for the Messenger service of GNUnet."), 135 gettext_noop(MESSENGER_CLI_DESC),
104 options, 136 options,
105 &run, 137 &run,
106 app 138 app
107 ); 139 );
108 140
109 members_clear(&(app->current.members)); 141 members_clear(&(app->current.members));
diff --git a/src/chat.c b/src/chat.c
index 9cb8b7c..792f8eb 100644
--- a/src/chat.c
+++ b/src/chat.c
@@ -26,8 +26,17 @@
26 26
27#include "application.h" 27#include "application.h"
28#include "util.h" 28#include "util.h"
29#include <curses.h>
29#include <gnunet/gnunet_chat_lib.h> 30#include <gnunet/gnunet_chat_lib.h>
30 31
32#ifndef MESSENGER_CLI_BINARY
33#define MESSENGER_CLI_BINARY "messenger_cli"
34#endif
35
36#ifndef MESSENGER_CLI_VERSION
37#define MESSENGER_CLI_VERSION "unknown"
38#endif
39
31static void 40static void
32_chat_refresh(MESSENGER_Application *app) 41_chat_refresh(MESSENGER_Application *app)
33{ 42{
@@ -46,6 +55,14 @@ _chat_refresh(MESSENGER_Application *app)
46 wmove(app->ui.logo, 0, 0); 55 wmove(app->ui.logo, 0, 0);
47 56
48 util_print_logo(app->ui.logo); 57 util_print_logo(app->ui.logo);
58
59 int x = getcurx(app->ui.logo);
60 int y = getcury(app->ui.logo);
61
62 util_print_info(app->ui.logo, MESSENGER_CLI_VERSION);
63
64 wmove(app->ui.logo, --y, x);
65 util_print_info(app->ui.logo, MESSENGER_CLI_BINARY);
49} 66}
50 67
51static bool 68static bool
diff --git a/src/util.c b/src/util.c
index 6647fef..3f5d5a4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V. 3 Copyright (C) 2022--2024 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
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include "util.h" 25#include "util.h"
26#include <string.h>
26 27
27void 28void
28util_print_logo(WINDOW *window) 29util_print_logo(WINDOW *window)
@@ -41,3 +42,18 @@ util_print_logo(WINDOW *window)
41 wmove(window, y++, x); wprintw(window, " oooo "); 42 wmove(window, y++, x); wprintw(window, " oooo ");
42 wmove(window, y++, x); wprintw(window, " "); 43 wmove(window, y++, x); wprintw(window, " ");
43} 44}
45
46void
47util_print_info(WINDOW *window,
48 const char *info)
49{
50 const int x = getmaxx(window) - strlen(info) - 1;
51
52 if (x < UTIL_LOGO_COLS)
53 return;
54
55 const int y = getcury(window);
56
57 wmove(window, y, x);
58 wprintw(window, "%s", info);
59}
diff --git a/src/util.h b/src/util.h
index ba4c735..d1126a9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V. 3 Copyright (C) 2022--2024 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
@@ -43,4 +43,15 @@
43void 43void
44util_print_logo(WINDOW *window); 44util_print_logo(WINDOW *window);
45 45
46/**
47 * Print information on the right side of
48 * the application besides the main logo.
49 *
50 * @param[in,out] window Window view
51 * @param[in] info Information
52 */
53void
54util_print_info(WINDOW *window,
55 const char *info);
56
46#endif /* UTIL_H_ */ 57#endif /* UTIL_H_ */