Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of save and restore cursor #156

Merged
merged 1 commit into from
Sep 15, 2016
Merged
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
31 changes: 16 additions & 15 deletions src/pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ eager_strpbrk(const char *string, const char *separators)
const struct choice *
selected_choice(void)
{
size_t cursor_position, i, length;
size_t cursor_position, i, j, length;
size_t xscroll = 0;
char buf[6];
int choices_count, key, word_position;
Expand All @@ -285,7 +285,7 @@ selected_choice(void)

for (;;) {
tty_putp(cursor_invisible);
tty_putp(restore_cursor);
tty_putp(carriage_return); /* move cursor to first column */
if (cursor_position >= xscroll + columns)
xscroll = cursor_position - columns + 1;
if (cursor_position < xscroll)
Expand All @@ -308,12 +308,21 @@ selected_choice(void)
if (tty_putc('\n') == EOF)
err(1, "tty_putc");
tty_putp(clr_eos);
tty_putp(tparm(parm_up_cursor, choices_count + 1));
} else {
tty_putp(tparm(parm_up_cursor,
choices_count < choices_lines
? choices_count : choices_lines));
}
tty_putp(restore_cursor);
for (i = 0; i < cursor_position;) {
tty_putp(carriage_return); /* move cursor to first column */
for (i = j = 0; i < cursor_position; j++)
while (isu8cont(query[++i]));
tty_putp(cursor_right);
}
if (j > 0)
/*
* parm_right_cursor interprets 0 as 1, therefore only
* move the cursor if the position is non zero.
*/
tty_putp(tparm(parm_right_cursor, j));
tty_putp(cursor_normal);
fflush(tty_out);

Expand Down Expand Up @@ -596,7 +605,6 @@ void
tty_init(void)
{
struct termios new_attributes;
int i;

if ((tty_in = fopen("/dev/tty", "r")) == NULL)
err(1, "fopen");
Expand All @@ -616,13 +624,6 @@ tty_init(void)
if (use_alternate_screen)
tty_putp(enter_ca_mode);

/* Emit enough lines to fit all choices. */
for (i = 0; i < (ssize_t)choices.length && i < choices_lines; ++i)
tty_putp(cursor_down);
for (; i > 0; --i)
tty_putp(cursor_up);
tty_putp(save_cursor);

signal(SIGINT, handle_sigint);
}

Expand All @@ -645,7 +646,7 @@ tty_restore(void)
tcsetattr(fileno(tty_in), TCSANOW, &original_attributes);
fclose(tty_in);

tty_putp(restore_cursor);
tty_putp(carriage_return); /* move cursor to first column */
tty_putp(clr_eos);

if (use_alternate_screen)
Expand Down