Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,37 @@


#ifndef NOT_USER_COLOR
// RL_PROMPT_START_IGNORE RL_PROMPT_END_IGNORE
#define ANSI_COLOR_RED "\001\x1b[31m\002"
#define ANSI_COLOR_GREEN "\001\x1b[32m\002"
#define ANSI_COLOR_YELLOW "\001\x1b[33m\002"
#define ANSI_COLOR_BLUE "\001\x1b[34m\002"
#define ANSI_COLOR_MAGENTA "\001\x1b[35m\002"
#define ANSI_COLOR_CYAN "\001\x1b[36m\002"

#define ANSI_COLOR_BOLD "\001\x1b[1m\002"
#define ANSI_COLOR_RED_BOLD "\001\x1b[31;1m\002"
#define ANSI_COLOR_GREEN_BOLD "\001\x1b[32;1m\002"
#define ANSI_COLOR_YELLOW_BOLD "\001\x1b[33;1m\002"
#define ANSI_COLOR_BLUE_BOLD "\001\x1b[34;1m\002"
#define ANSI_COLOR_MAGENTA_BOLD "\001\x1b[35;1m\002"
#define ANSI_COLOR_CYAN_BOLD "\001\x1b[36;1m\002"

#define ANSI_COLOR_RESET "\001\x1b[0m\001"
// Use \001 and \002 (RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE) to wrap ANSI escape sequences
// This tells readline to ignore these characters when calculating prompt length
// Works on both Linux (GNU readline) and macOS (libedit/readline)
// Note: RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE are char constants, so we use string literals
#define ANSI_COLOR_RED "\001\033[0;31m\002"
#define ANSI_COLOR_GREEN "\001\033[0;32m\002"
#define ANSI_COLOR_YELLOW "\001\033[0;33m\002"
#define ANSI_COLOR_BLUE "\001\033[0;34m\002"
#define ANSI_COLOR_MAGENTA "\001\033[0;35m\002"
#define ANSI_COLOR_CYAN "\001\033[0;36m\002"

#define ANSI_COLOR_BOLD "\001\033[1m\002"
#define ANSI_COLOR_RED_BOLD "\001\033[1;31m\002"
#define ANSI_COLOR_GREEN_BOLD "\001\033[1;32m\002"
#define ANSI_COLOR_YELLOW_BOLD "\001\033[1;33m\002"
#define ANSI_COLOR_BLUE_BOLD "\001\033[1;34m\002"
#define ANSI_COLOR_MAGENTA_BOLD "\001\033[1;35m\002"
#define ANSI_COLOR_CYAN_BOLD "\001\033[1;36m\002"

#define ANSI_COLOR_RESET "\001\033[0m\002"

/* Color array for per-host output cycling */
static const char *HOST_COLORS[] = {
ANSI_COLOR_GREEN,
ANSI_COLOR_YELLOW,
ANSI_COLOR_BLUE,
ANSI_COLOR_MAGENTA,
ANSI_COLOR_CYAN
};
#define HOST_COLORS_COUNT 5

#else
#define ANSI_COLOR_RED
#define ANSI_COLOR_GREEN
Expand Down
6 changes: 5 additions & 1 deletion completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ filepath_generator(const char *text, int state) {
list_index++;
if (strncmp(name, text, len) == 0) {
if (name[strlen(name) - 1] == '/') {
/* default space will not be appended if the matched path is directory */
/* avoid appending space for directories when supported */
#if defined(RL_READLINE_VERSION) && (RL_READLINE_VERSION >= 0x0500)
rl_completion_suppress_append = 1;
#endif
} else {
#if defined(RL_READLINE_VERSION) && (RL_READLINE_VERSION >= 0x0500)
rl_completion_suppress_append = 0;
#endif
}
return name;
}
Expand Down
14 changes: 12 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ update_completion_function() {
static char *
gets_interactive() {
char *line;
int rows = 0;
int cols = 0;

#if defined(RL_READLINE_VERSION) && (RL_READLINE_VERSION >= 0x0600)
rl_reset_screen_size();
#else
rl_get_screen_size(&rows, &cols);
if (rows > 0 && cols > 0) {
rl_set_screen_size(rows, cols);
}
#endif

sigint_interrupt_enabled = true;
line = readline(get_prompt());
Expand Down Expand Up @@ -167,7 +177,7 @@ parse_opts(int argc, char **argv) {
usage(NULL);
break;
case 'i':
rl_editing_mode = 0;
rl_variable_bind("editing-mode", "vi");
break;
case 'f':
add_hostfile(optarg);
Expand Down Expand Up @@ -278,7 +288,7 @@ main(int argc, char **argv) {
}
exec_remote_cmd(slots, line, pconfig->concurrency);
}
rl_free(line);
free(line);
}

return 0;
Expand Down
1 change: 1 addition & 0 deletions sstring.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "common.h"
#include <ctype.h>
#include "sstring.h"

#define STRING_MAX_PREALLOC (1024*1024)
Expand Down