Browse Source

degesch: add a --format switch

tags/v0.9.3
Přemysl Janouch 3 years ago
parent
commit
f96fa66168
2 changed files with 24 additions and 0 deletions
  1. +2
    -0
      NEWS
  2. +22
    -0
      degesch.c

+ 2
- 0
NEWS View File

@@ -21,6 +21,8 @@
* degesch: M-! and M-@ to go to the next buffer in order with
a highlight or new activity respectively

* degesch: added --format for previewing things like MOTD files

* kike: add support for IRCv3.2 server-time

* ZyklonB: plugins now run in a dedicated data directory

+ 22
- 0
degesch.c View File

@@ -12803,6 +12803,21 @@ show_logo (struct app_context *ctx)
log_global_indent (ctx, "#m", g_logo[i]);
}

static void
format_input_and_die (struct app_context *ctx)
{
char buf[513];
while (fgets (buf, sizeof buf, stdin))
{
struct formatter f;
formatter_init (&f, ctx, NULL);
formatter_add (&f, "#m", buf);
formatter_flush (&f, stdout, false);
formatter_free (&f);
}
exit (EXIT_SUCCESS);
}

int
main (int argc, char *argv[])
{
@@ -12814,11 +12829,14 @@ main (int argc, char *argv[])
{
{ 'h', "help", NULL, 0, "display this help and exit" },
{ 'V', "version", NULL, 0, "output version information and exit" },
// This is mostly intended for previewing formatted MOTD files
{ 'f', "format", NULL, OPT_LONG_ONLY, "format IRC text from stdin" },
{ 0, NULL, NULL, 0, NULL }
};

struct opt_handler oh;
opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC client.");
bool format_mode = false;

int c;
while ((c = opt_handler_get (&oh)) != -1)
@@ -12830,6 +12848,9 @@ main (int argc, char *argv[])
case 'V':
printf (PROGRAM_NAME " " PROGRAM_VERSION "\n");
exit (EXIT_SUCCESS);
case 'f':
format_mode = true;
break;
default:
print_error ("wrong options");
opt_handler_usage (&oh, stderr);
@@ -12855,6 +12876,7 @@ main (int argc, char *argv[])

// The following part is a bit brittle because of interdependencies
init_colors (&ctx);
if (format_mode) format_input_and_die (&ctx);
init_global_buffer (&ctx);
show_logo (&ctx);
setup_signal_handlers ();

Loading…
Cancel
Save