Minor, coding style fixups

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-28 06:58:37 +01:00
parent f35af9f20d
commit 35506cd22e

View File

@ -137,7 +137,6 @@ extern char *tgetstr(const char *, char **);
extern int tgetent(char *, const char *); extern int tgetent(char *, const char *);
extern int tgetnum(const char *); extern int tgetnum(const char *);
#endif #endif
/* /*
** Misc. local helper functions. ** Misc. local helper functions.
@ -210,6 +209,7 @@ static void tty_show(unsigned char c)
static void tty_string(char *p) static void tty_string(char *p)
{ {
int i = rl_point + prompt_len + 1; int i = rl_point + prompt_len + 1;
while (*p) { while (*p) {
tty_show(*p++); tty_show(*p++);
if ((i++) % tty_cols == 0) if ((i++) % tty_cols == 0)
@ -262,7 +262,6 @@ static void tty_info(void)
{ {
rl_reset_terminal(NULL); rl_reset_terminal(NULL);
} }
/* /*
** Glue routines to rl_ttyset() ** Glue routines to rl_ttyset()
@ -298,6 +297,7 @@ void el_print_columns(int ac, char **av)
if ((j = strlen((char *)av[i])) > longest) if ((j = strlen((char *)av[i])) > longest)
longest = j; longest = j;
} }
colwidth = longest + 3; colwidth = longest + 3;
if (colwidth > tty_cols) if (colwidth > tty_cols)
colwidth = tty_cols; colwidth = tty_cols;
@ -321,49 +321,62 @@ void el_print_columns(int ac, char **av)
static void reposition(int key) static void reposition(int key)
{ {
int i = 0;
int len_with_prompt = prompt_len + rl_end; int len_with_prompt = prompt_len + rl_end;
int n = len_with_prompt / tty_cols; // determine the number of lines int n = len_with_prompt / tty_cols; /* determine the number of lines */
int i = 0;
tty_put('\r'); tty_put('\r');
if (n > 0) { if (n > 0) {
int line; int line;
/* determine num of current line */
if (key == CTL('A') || key == CTL('E') || key == rl_kill) if (key == CTL('A') || key == CTL('E') || key == rl_kill)
line = (prompt_len + old_point) / tty_cols; // determine num of current line line = (prompt_len + old_point) / tty_cols;
else else
line = len_with_prompt / tty_cols; line = len_with_prompt / tty_cols;
if (key == CTL('E')) { // move to end of line(s) /* move to end of line(s) */
for(int k = line; k < n; k++) if (key == CTL('E')) {
int k;
for (k = line; k < n; k++)
tty_puts(line_down); tty_puts(line_down);
i = rl_point - (len_with_prompt % tty_cols); // determine reminder of last line and redraw only it
/* determine reminder of last line and redraw only it */
i = rl_point - (len_with_prompt % tty_cols);
} else { } else {
for(int k = line; k > 0; k--) // CTRL-A, CTRL-U, insert (end, middle), remove (end, middle) int k;
tty_puts(line_up); // redraw characters until changed data
/* CTRL-A, CTRL-U, insert (end, middle), remove (end, middle) */
for (k = line; k > 0; k--)
tty_puts(line_up); /* redraw characters until changed data */
tty_puts(rl_prompt); tty_puts(rl_prompt);
} }
} } else if (n == 0) {
else if (n == 0) {
tty_puts(rl_prompt); tty_puts(rl_prompt);
} }
for (i; i < rl_point; i++) { for (i; i < rl_point; i++) {
tty_show(rl_line_buffer[i]); tty_show(rl_line_buffer[i]);
if ((i + prompt_len + 1) % tty_cols == 0) { // move to the next line
/* move to the next line */
if ((i + prompt_len + 1) % tty_cols == 0)
tty_put('\n'); tty_put('\n');
} }
}
} }
void itoa(int val, char* buf) void itoa(int val, char* buf)
{ {
int digits = 0; int digits = 0;
int temp = val; int temp = val;
while (temp != 0) { while (temp != 0) {
temp = temp / 10; temp = temp / 10;
++digits; ++digits;
} }
*(buf+digits) = 'C'; *(buf+digits) = 'C';
int i = 5; digits--; int i = 5; digits--;
for(; val && i ; --i, val /= 10) { for(; val && i ; --i, val /= 10) {
@ -374,10 +387,11 @@ void itoa(int val, char* buf)
static void move_cursor_forward(int columns) static void move_cursor_forward(int columns)
{ {
char buf[12] = {0};
const char* line_forward = "\x1b["; const char* line_forward = "\x1b[";
char buf[12] = {0};
strcpy(buf, line_forward); strcpy(buf, line_forward);
itoa(columns, buf+2); itoa(columns, buf + 2);
tty_puts(buf); tty_puts(buf);
} }
@ -390,6 +404,7 @@ static void left(el_status_t Change)
} else { } else {
tty_back(); tty_back();
} }
if (ISMETA(rl_line_buffer[rl_point - 1])) { if (ISMETA(rl_line_buffer[rl_point - 1])) {
if (rl_meta_chars) { if (rl_meta_chars) {
tty_back(); tty_back();
@ -655,7 +670,6 @@ static el_status_t toggle_meta_mode(void)
rl_meta_chars = ! rl_meta_chars; rl_meta_chars = ! rl_meta_chars;
return redisplay(0); return redisplay(0);
} }
const char *el_next_hist(void) const char *el_next_hist(void)
{ {
@ -1623,7 +1637,6 @@ int write_history(const char *filename)
return errno; return errno;
} }
/* /*
** Move back to the beginning of the current word and return an ** Move back to the beginning of the current word and return an