Clean up command summary printing

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
wayvncctl-polishing
Jim Ramsay 2023-01-11 22:32:46 -05:00
parent cc27b127d1
commit 749b64666a
5 changed files with 29 additions and 15 deletions

View File

@ -63,3 +63,5 @@ const char* option_parser_get_value(const struct option_parser* self,
const char* name);
const char* option_parser_get_value_no_default(const struct option_parser* self,
const char* name);
void option_parser_print_cmd_summary(const char* summary, FILE* stream);

View File

@ -670,10 +670,10 @@ static size_t param_render_length(const struct cmd_param_info* param)
static void print_event_info(const struct cmd_info* info)
{
printf("%s\n\n", info->name);
table_printer_indent_and_reflow_text(stdout, info->description, 80, 0, 0);
printf("%s\n", info->name);
option_parser_print_cmd_summary(info->description, stdout);
if (info->params[0].name != NULL) {
printf("\nData fields:\n");
printf("Data fields:\n");
size_t max_namelen = 0;
for (int i = 0; info->params[i].name != NULL; ++i)
max_namelen = MAX(max_namelen, param_render_length(&info->params[i]));
@ -684,6 +684,7 @@ static void print_event_info(const struct cmd_info* info)
table_printer_print_fmtline(&printer,
info->params[i].description,
"%s=%s", info->params[i].name, info->params[i].schema);
printf("\n");
}
}
@ -740,17 +741,17 @@ static int print_command_usage(struct ctl_client* self,
}
printf("Usage: wayvncctl [options] %s", info->name);
option_parser_print_usage(cmd_options, stdout);
printf("\n\n");
table_printer_indent_and_reflow_text(stdout, info->description, 80, 0, 0);
printf("\n");
option_parser_print_cmd_summary(info->description, stdout);
if (option_parser_print_arguments(cmd_options, stdout))
printf("\n");
option_parser_print_options(cmd_options, stdout);
printf("\n");
option_parser_print_options(parent_options, stdout);
printf("\n");
if (cmd == CMD_EVENT_RECEIVE) {
printf("\n");
ctl_client_print_event_list(stdout);
printf("\n");
}
return 0;
}

View File

@ -910,14 +910,15 @@ void on_capture_done(struct screencopy* sc)
int wayvnc_usage(struct option_parser* parser, FILE* stream, int rc)
{
fputs("Usage: wayvnc", stream);
fprintf(stream, "Usage: wayvnc");
option_parser_print_usage(parser, stream);
fputs("\n\n", stream);
fprintf(stream, "Starts a VNC server for $WAYLAND_DISPLAY\n\n");
fprintf(stream, "\n");
option_parser_print_cmd_summary("Starts a VNC server for $WAYLAND_DISPLAY",
stream);
if (option_parser_print_arguments(parser, stream))
fputc('\n', stream);
fprintf(stream, "\n");
option_parser_print_options(parser, stream);
fputc('\n', stream);
fprintf(stream, "\n");
return rc;
}

View File

@ -424,3 +424,12 @@ const char* option_parser_get_value(const struct option_parser* self,
return NULL;
}
void option_parser_print_cmd_summary(const char* summary, FILE* stream)
{
struct table_printer printer;
table_printer_init(&printer, stream, 0);
fprintf(stream, "\n");
table_printer_indent_and_reflow_text(stream, summary, printer.max_width, 0, 0);
fprintf(stream, "\n");
}

View File

@ -43,12 +43,13 @@ struct wayvncctl {
static int wayvncctl_usage(FILE* stream, struct option_parser* options, int rc)
{
fputs("Usage: wayvncctl", stream);
fprintf(stream, "Usage: wayvncctl");
option_parser_print_usage(options, stream);
fputs(" [parameters]\n\n", stream);
fputs("Connects to and interacts with a running wayvnc instance.\n\n", stream);
fprintf(stream, " [parameters]\n");
option_parser_print_cmd_summary(
"Connects to and interacts with a running wayvnc instance.", stream);
option_parser_print_options(options, stream);
fputc('\n', stream);
fprintf(stream, "\n");
ctl_client_print_command_list(stream);
return rc;
}