Allow passing drawings to open on the command line

The UI deserves an overhaul.
This commit is contained in:
Přemysl Eric Janouch 2023-05-22 05:47:03 +02:00
parent e08c63fe89
commit dd71ce5ca0
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 16 additions and 11 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2014, Přemysl Eric Janouch <p@janouch.name>
Copyright (c) 2014 - 2023, Přemysl Eric Janouch <p@janouch.name>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

View File

@ -1,7 +1,7 @@
/*
* neetdraw.c: terminal drawing application with multiplayer support
*
* Copyright (c) 2014, Přemysl Eric Janouch <p@janouch.name>
* Copyright (c) 2014 - 2023, Přemysl Eric Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@ -766,7 +766,7 @@ export_irc (struct app_context *app)
// --- Loading, saving ---------------------------------------------------------
static void
load (struct app_context *app)
load (struct app_context *app, const char *filename)
{
// Client cannot load at all, the server would have send the new bitmap out
if (app->mode != NETWORK_MODE_STANDALONE)
@ -776,7 +776,7 @@ load (struct app_context *app)
return;
}
FILE *fp = fopen ("drawing.bin", "rb");
FILE *fp = fopen (filename, "rb");
if (!fp)
{
display ("Error opening file for reading.");
@ -830,9 +830,9 @@ error:
}
static void
save (struct app_context *app)
save (struct app_context *app, const char *filename)
{
FILE *fp = fopen ("drawing.bin", "wb");
FILE *fp = fopen (filename, "wb");
if (!fp)
{
display ("Error opening file for writing.");
@ -952,8 +952,8 @@ on_key (struct app_context *app, termo_key_t *key)
if (key->modifiers)
return true;
if (key->code.codepoint == 'l') load (app);
if (key->code.codepoint == 's') save (app);
if (key->code.codepoint == 'l') load (app, "drawing.bin");
if (key->code.codepoint == 's') save (app, "drawing.bin");
if (key->code.codepoint == 'e') export_ansi (app);
if (key->code.codepoint == 'E') export_irc (app);
return true;
@ -1342,6 +1342,7 @@ struct app_options
struct addrinfo *client_address; ///< Address to connect to
struct addrinfo *server_address; ///< Address to listen at
bool no_wait; ///< Don't wait for server confirmations
const char *filename; ///< A filename to preload
};
static void
@ -1414,8 +1415,8 @@ parse_program_arguments (struct app_options *options, int argc, char **argv)
{ 0, NULL, NULL, 0, NULL }
};
struct opt_handler oh = opt_handler_make (argc, argv, opts,
NULL, "Terminal drawing application with multiplayer support");
struct opt_handler oh = opt_handler_make (argc, argv, opts, "[drawing.bin]",
"Terminal drawing application with multiplayer support");
int c;
while ((c = opt_handler_get (&oh)) != -1)
@ -1454,7 +1455,8 @@ parse_program_arguments (struct app_options *options, int argc, char **argv)
argc -= optind;
argv += optind;
if (argc)
options->filename = argv[0];
if (argc > 1)
{
opt_handler_usage (&oh, stderr);
exit (EXIT_FAILURE);
@ -1598,6 +1600,9 @@ main (int argc, char *argv[])
redraw (&app);
redraw_canvas (&app);
if (options.filename)
load (&app, options.filename);
ev_run (loop, 0);
endwin ();