}
/* Erase the rest of the prompt, assuming we are starting at column col. */
-static void erase_prompt(struct more_control *ctl, int col)
+static void erase_to_col(struct more_control *ctl, int col)
{
if (ctl->prompt_len == 0)
return;
- if (ctl->hard_tty) {
+ if (col == 0 && ctl->clear_line_ends)
+ puts(ctl->erase_line);
+ else if (ctl->hard_tty)
putchar('\n');
- } else {
+ else {
if (col == 0)
putchar('\r');
if (!ctl->dumb_tty && ctl->erase_line)
putp(ctl->erase_line);
- else
+ else {
printf("%*s", ctl->prompt_len - col, "");
+ if (col == 0)
+ putchar('\r');
+ }
}
- ctl->prompt_len = 0;
+ ctl->prompt_len = col;
}
#ifdef HAVE_WIDECHAR
}
}
-/* Erase the current line entirely */
-static void kill_line(struct more_control *ctl)
-{
- erase_prompt(ctl, 0);
- if (!ctl->erase_line || ctl->dumb_tty)
- putchar('\r');
-}
-
static void output_prompt(struct more_control *ctl, char *filename)
{
if (ctl->clear_line_ends)
putp(ctl->erase_line);
else if (ctl->prompt_len > 0)
- kill_line(ctl);
+ erase_to_col(ctl, 0);
if (!ctl->hard_tty) {
ctl->prompt_len = 0;
if (ctl->enter_std) {
putp(ctl->erase_line);
fflush(stdout);
} else if (!ctl->clear_line_ends && (ctl->prompt_len > 0)) {
- kill_line(ctl);
+ erase_to_col(ctl, 0);
fflush(stdout);
}
free(ctl->previous_search);
if (ctl->clear_line_ends)
putp(ctl->erase_line);
else
- kill_line(ctl);
+ erase_to_col(ctl, 0);
ctl->prompt_len += strlen(mess);
if (ctl->enter_std)
putp(ctl->enter_std);
putchar('\r');
putchar(pchar);
if (ctl->erase_line)
- erase_prompt(ctl, 1);
+ erase_to_col(ctl, 1);
else if (ctl->erase_input_ok)
while (ctl->prompt_len-- > 1)
fprintf(stderr, "%s %s", ctl->backspace_ch, ctl->backspace_ch);
{
char cmdbuf[COMMAND_BUF];
- kill_line(ctl);
+ erase_to_col(ctl, 0);
putchar('!');
fflush(stdout);
ctl->prompt_len = 1;
free(ctl->shell_line);
ctl->shell_line = xstrdup(cmdbuf);
}
- kill_line(ctl);
+ erase_to_col(ctl, 0);
ctl->prompt_len = printf("!%s", ctl->shell_line);
}
fflush(stdout);
ctl->last_colon_command = ch;
switch (ch) {
case 'f':
- kill_line(ctl);
+ erase_to_col(ctl, 0);
if (!ctl->no_tty_in)
ctl->prompt_len =
printf(_("\"%s\" line %d"), ctl->file_names[ctl->argv_position], ctl->current_line);
nlines++;
}
putchar('\r');
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
change_file(ctl, nlines);
return 0;
case 'p':
return -1;
}
putchar('\r');
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
if (nlines == 0)
nlines++;
change_file(ctl, -nlines);
more_clear_screen(ctl);
}
} else {
- kill_line(ctl);
+ erase_to_col(ctl, 0);
if (ctl->no_scroll) {
if (ctl->clear_line_ends) {
putp(ctl->go_home);
} else
sprintf(cmdbuf, "+%d", n);
- kill_line(ctl);
+ erase_to_col(ctl, 0);
printf("%s %s %s", editor, cmdbuf, ctl->file_names[ctl->argv_position]);
if (split) {
cmdbuf[2] = 0;
nlines++;
putchar('\r');
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
putchar('\n');
if (ctl->clear_line_ends)
putp(ctl->erase_line);
if (comchar == 'f')
nlines *= ctl->lines_per_screen;
putchar('\r');
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
putchar('\n');
if (ctl->clear_line_ends)
putp(ctl->erase_line);
ctl->last_key_command = comchar;
ctl->last_key_arg = nlines;
if (comchar == ctl->output_tty.c_cc[VERASE]) {
- kill_line(ctl);
+ erase_to_col(ctl, 0);
output_prompt(ctl, filename);
continue;
}
}
case '\'':
if (!ctl->no_tty_in) {
- kill_line(ctl);
+ erase_to_col(ctl, 0);
fputs(_("\n***Back***\n\n"), stdout);
more_fseek(ctl, ctl->context.row_num);
ctl->current_line = ctl->context.line_num;
break;
}
case '=':
- kill_line(ctl);
+ erase_to_col(ctl, 0);
ctl->prompt_len = printf("%d", ctl->current_line);
fflush(stdout);
break;
ctl->search_called = 1;
if (nlines == 0)
nlines++;
- kill_line(ctl);
+ erase_to_col(ctl, 0);
putchar('/');
ctl->prompt_len = 1;
fflush(stdout);
case 'h':
if (ctl->no_scroll)
more_clear_screen(ctl);
- kill_line(ctl);
+ erase_to_col(ctl, 0);
runtime_usage();
output_prompt(ctl, filename);
break;
/* fallthrough */
default:
if (ctl->suppress_bell) {
- kill_line(ctl);
+ erase_to_col(ctl, 0);
if (ctl->enter_std)
putp(ctl->enter_std);
ctl->prompt_len =
prev_len = length;
if (ctl->bad_stdout
|| ((ctl->enter_std && *ctl->enter_std == ' ') && (ctl->prompt_len > 0)))
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
/* must clear before drawing line since tabs on
* some terminals do not erase what they tab
* over. */
putp(ctl->erase_line);
print_buf(ctl, ctl->line_buf, length);
if (nchars < ctl->prompt_len)
- erase_prompt(ctl, nchars); /* erase_prompt () sets prompt_len to 0 */
- else
- ctl->prompt_len = 0;
+ erase_to_col(ctl, nchars);
+ ctl->prompt_len = 0;
if (nchars < ctl->num_columns || !ctl->fold_long_lines)
print_buf(ctl, "\n", 1); /* will turn off UL if necessary */
num_lines--;
return;
} while (ctl->search_called && !ctl->previous_search);
if (ctl->hard_tty && ctl->prompt_len > 0)
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
if (ctl->no_scroll && num_lines >= ctl->lines_per_screen) {
if (ctl->clear_line_ends)
putp(ctl->go_home);
}
if (ctl->print_banner) {
if (ctl->bad_stdout)
- erase_prompt(ctl, 0);
+ erase_to_col(ctl, 0);
if (ctl->clear_line_ends)
putp(ctl->erase_line);
if (ctl->prompt_len > 14)
- erase_prompt(ctl, 14);
+ erase_to_col(ctl, 14);
if (ctl->clear_line_ends)
putp(ctl->erase_line);
print_separator(':', 14);