messenger-cli

Command-line user interface for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 8d5d4608797179606cba833af4a58d6f4576c8d4
parent 8d7153893870141cd374922837bca7c4fb31c729
Author: Jacki <jacki@thejackimonster.de>
Date:   Thu,  7 Mar 2024 05:32:17 +0100

Print version and binary information

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Mmeson.build | 6++++++
Msrc/application.c | 56++++++++++++++++++++++++++++++++++++++++++++------------
Msrc/chat.c | 17+++++++++++++++++
Msrc/util.c | 18+++++++++++++++++-
Msrc/util.h | 13++++++++++++-
5 files changed, 96 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build @@ -35,11 +35,17 @@ messenger_cli_deps = [ dependency('ncurses'), ] +messenger_cli_args = [ + '-DMESSENGER_CLI_BINARY="@0@"'.format(meson.project_name()), + '-DMESSENGER_CLI_VERSION="@0@"'.format(meson.project_version()), +] + subdir('src') messenger_cli_exec = executable( 'messenger-cli', messenger_cli_sources, + c_args: messenger_cli_args, install: true, dependencies: messenger_cli_deps, include_directories: src_directory, diff --git a/src/application.c b/src/application.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2023 GNUnet e.V. + Copyright (C) 2022--2024 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 @@ -26,6 +26,18 @@ #include "util.h" +#ifndef MESSENGER_CLI_BINARY +#define MESSENGER_CLI_BINARY "messenger_cli" +#endif + +#ifndef MESSENGER_CLI_VERSION +#define MESSENGER_CLI_VERSION "unknown" +#endif + +#ifndef MESSENGER_CLI_DESC +#define MESSENGER_CLI_DESC "A CLI for the Messenger service of GNUnet." +#endif + void application_clear(MESSENGER_Application *app) { @@ -37,14 +49,34 @@ application_clear(MESSENGER_Application *app) void application_init(MESSENGER_Application *app, - int argc, - char **argv) + int argc, + char **argv) { + const struct GNUNET_GETOPT_CommandLineOption options [] = { + GNUNET_GETOPT_option_version(MESSENGER_CLI_VERSION), + GNUNET_GETOPT_option_help(MESSENGER_CLI_DESC), + GNUNET_GETOPT_OPTION_END + }; + memset(app, 0, sizeof(*app)); app->argc = argc; app->argv = argv; + const int parsing = GNUNET_GETOPT_run( + MESSENGER_CLI_BINARY, + options, + app->argc, + app->argv + ); + + if (parsing <= 0) + { + app->window = NULL; + app->status = GNUNET_SYSERR == parsing? GNUNET_SYSERR : GNUNET_OK; + return; + } + app->window = initscr(); if (!(app->window)) @@ -92,18 +124,18 @@ run (void *cls, void application_run(MESSENGER_Application *app) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END + const struct GNUNET_GETOPT_CommandLineOption options [] = { + GNUNET_GETOPT_OPTION_END }; app->status = GNUNET_PROGRAM_run( - app->argc, - app->argv, - "messenger_cli", - gettext_noop("A CLI for the Messenger service of GNUnet."), - options, - &run, - app + 1, + app->argv, + MESSENGER_CLI_BINARY, + gettext_noop(MESSENGER_CLI_DESC), + options, + &run, + app ); members_clear(&(app->current.members)); diff --git a/src/chat.c b/src/chat.c @@ -26,8 +26,17 @@ #include "application.h" #include "util.h" +#include <curses.h> #include <gnunet/gnunet_chat_lib.h> +#ifndef MESSENGER_CLI_BINARY +#define MESSENGER_CLI_BINARY "messenger_cli" +#endif + +#ifndef MESSENGER_CLI_VERSION +#define MESSENGER_CLI_VERSION "unknown" +#endif + static void _chat_refresh(MESSENGER_Application *app) { @@ -46,6 +55,14 @@ _chat_refresh(MESSENGER_Application *app) wmove(app->ui.logo, 0, 0); util_print_logo(app->ui.logo); + + int x = getcurx(app->ui.logo); + int y = getcury(app->ui.logo); + + util_print_info(app->ui.logo, MESSENGER_CLI_VERSION); + + wmove(app->ui.logo, --y, x); + util_print_info(app->ui.logo, MESSENGER_CLI_BINARY); } static bool diff --git a/src/util.c b/src/util.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022 GNUnet e.V. + Copyright (C) 2022--2024 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 @@ -23,6 +23,7 @@ */ #include "util.h" +#include <string.h> void util_print_logo(WINDOW *window) @@ -41,3 +42,18 @@ util_print_logo(WINDOW *window) wmove(window, y++, x); wprintw(window, " oooo "); wmove(window, y++, x); wprintw(window, " "); } + +void +util_print_info(WINDOW *window, + const char *info) +{ + const int x = getmaxx(window) - strlen(info) - 1; + + if (x < UTIL_LOGO_COLS) + return; + + const int y = getcury(window); + + wmove(window, y, x); + wprintw(window, "%s", info); +} diff --git a/src/util.h b/src/util.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022 GNUnet e.V. + Copyright (C) 2022--2024 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 @@ -43,4 +43,15 @@ void util_print_logo(WINDOW *window); +/** + * Print information on the right side of + * the application besides the main logo. + * + * @param[in,out] window Window view + * @param[in] info Information + */ +void +util_print_info(WINDOW *window, + const char *info); + #endif /* UTIL_H_ */