1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +02:00

exec: add options "-ln"/"-noln" (line numbers) in command /exec

This commit is contained in:
Sebastien Helleu
2014-03-12 19:52:04 +01:00
parent 08bffd6f5a
commit ed6ea18c30
4 changed files with 40 additions and 6 deletions
+16 -2
View File
@@ -247,6 +247,14 @@ exec_command_parse_options (struct t_exec_cmd_options *cmd_options,
{
cmd_options->switch_to_buffer = 0;
}
else if (weechat_strcasecmp (argv[i], "-ln") == 0)
{
cmd_options->line_numbers = 1;
}
else if (weechat_strcasecmp (argv[i], "-noln") == 0)
{
cmd_options->line_numbers = 0;
}
else if (weechat_strcasecmp (argv[i], "-timeout") == 0)
{
if (i + 1 >= argc)
@@ -464,6 +472,7 @@ exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
cmd_options.output_to_buffer = 0;
cmd_options.new_buffer = 0;
cmd_options.switch_to_buffer = 1;
cmd_options.line_numbers = -1;
cmd_options.ptr_command_name = NULL;
/* parse default options */
@@ -567,6 +576,8 @@ exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
if (cmd_options.switch_to_buffer)
weechat_buffer_set (cmd_options.ptr_buffer, "display", "1");
}
new_exec_cmd->line_numbers = (cmd_options.line_numbers < 0) ?
cmd_options.new_buffer : cmd_options.line_numbers;
/* execute the command */
if (weechat_exec_plugin->debug >= 1)
@@ -624,7 +635,8 @@ exec_command_init ()
N_("execute external commands"),
N_("-list"
" || [-sh|-nosh] [-bg|-nobg] [-stdin|-nostdin] [-buffer <name>] "
"[-l|-o|-n] |-sw|-nosw] [-timeout <timeout>] [-name <name>] <command>"
"[-l|-o|-n] |-sw|-nosw] [-ln|-noln] [-timeout <timeout>] "
"[-name <name>] <command>"
" || -in <id> <text>"
" || -inclose <id> [<text>]"
" || -signal <id> <signal>"
@@ -653,6 +665,8 @@ exec_command_init ()
"with -bg)\n"
" -sw: switch to the output buffer (default)\n"
" -nosw: don't switch to the output buffer\n"
" -ln: display line numbers (default in new buffer only)\n"
" -noln: don't display line numbers\n"
"-timeout: set a timeout for the command (in seconds)\n"
" -name: set a name for the command (to name it later with /exec)\n"
" command: the command to execute; if beginning with \"url:\", the "
@@ -678,7 +692,7 @@ exec_command_init ()
"exec.command.default_options."),
"-list"
" || -sh|-nosh|-bg|-nobg|-stdin|-nostdin|-buffer|-l|-o|-n|-sw|-nosw|"
"-timeout|-name|%*"
"-ln|-noln|-timeout|-name|%*"
" || -in|-inclose|-signal|-kill %(exec_commands_ids)"
" || -killall"
" || -set %(exec_commands_ids) stdin|stdin_close|signal"
+1
View File
@@ -32,6 +32,7 @@ struct t_exec_cmd_options
int output_to_buffer; /* 1 if output is sent to buffer */
int new_buffer; /* output in a new buffer */
int switch_to_buffer; /* switch to the output buffer */
int line_numbers; /* 1 to display line numbers */
const char *ptr_command_name; /* name of command */
};
+22 -4
View File
@@ -124,6 +124,7 @@ exec_add ()
new_exec_cmd->end_time = 0;
new_exec_cmd->output_to_buffer = 0;
new_exec_cmd->buffer_full_name = NULL;
new_exec_cmd->line_numbers = 0;
new_exec_cmd->stdout_size = 0;
new_exec_cmd->stdout = NULL;
new_exec_cmd->stderr_size = 0;
@@ -193,8 +194,8 @@ void
exec_command_display_output (struct t_exec_cmd *exec_cmd,
struct t_gui_buffer *buffer, int stdout)
{
char *ptr_output, **lines, str_number[32], str_tags[1024];
int i, num_lines;
char *ptr_output, **lines, *line, str_number[32], str_tags[1024];
int i, num_lines, length;
ptr_output = (stdout) ? exec_cmd->stdout : exec_cmd->stderr;
if (!ptr_output)
@@ -214,17 +215,33 @@ exec_command_display_output (struct t_exec_cmd *exec_cmd,
for (i = 0; i < num_lines; i++)
{
if (exec_cmd->output_to_buffer)
weechat_command (buffer, lines[i]);
{
if (exec_cmd->line_numbers)
{
length = 32 + strlen (lines[i]) + 1;
line = malloc (length);
if (line)
{
snprintf (line, length, "%d. %s", i + 1, lines[i]);
weechat_command (buffer, line);
free (line);
}
}
else
weechat_command (buffer, lines[i]);
}
else
{
snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number);
snprintf (str_tags, sizeof (str_tags),
"exec_%s,exec_cmd_%s",
(stdout) ? "stdout" : "stderr",
(exec_cmd->name) ? exec_cmd->name : str_number);
snprintf (str_number, sizeof (str_number), "%d\t", i + 1);
weechat_printf_tags (buffer, str_tags,
"%s%s",
(stdout) ? " \t" : weechat_prefix ("error"),
(exec_cmd->line_numbers) ? str_number : " \t",
lines[i]);
}
}
@@ -416,6 +433,7 @@ exec_print_log ()
weechat_log_printf (" end_time. . . . . . . . : %ld", ptr_exec_cmd->end_time);
weechat_log_printf (" output_to_buffer. . . . : %d", ptr_exec_cmd->output_to_buffer);
weechat_log_printf (" buffer_full_name. . . . : '%s'", ptr_exec_cmd->buffer_full_name);
weechat_log_printf (" line_numbers. . . . . . : %d", ptr_exec_cmd->line_numbers);
weechat_log_printf (" stdout_size . . . . . . : %d", ptr_exec_cmd->stdout_size);
weechat_log_printf (" stdout. . . . . . . . . : '%s'", ptr_exec_cmd->stdout);
weechat_log_printf (" stderr_size . . . . . . : %d", ptr_exec_cmd->stderr_size);
+1
View File
@@ -40,6 +40,7 @@ struct t_exec_cmd
/* buffer */
int output_to_buffer; /* 1 if output is sent to buffer */
char *buffer_full_name; /* buffer where output is displayed */
int line_numbers; /* 1 if lines numbers are displayed */
/* command output */
int stdout_size; /* number of bytes in stdout */