| ... | ... |
@@ -95,7 +95,7 @@ char search[SEARCH_SIZE_MAX + 1] = {0};
|
| 95 | 95 |
void clear(tty_t *tty){
|
| 96 | 96 |
tty_setcol(tty, 0); |
| 97 | 97 |
int line = 0; |
| 98 |
- while(line++ < NUMLINES + 1){
|
|
| 98 |
+ while(line++ < NUMLINES){
|
|
| 99 | 99 |
tty_newline(tty); |
| 100 | 100 |
} |
| 101 | 101 |
tty_moveup(tty, line-1); |
| ... | ... |
@@ -132,24 +132,23 @@ void draw(tty_t *tty){
|
| 132 | 132 |
if(current_selection + SCROLLOFF >= NUMLINES){
|
| 133 | 133 |
start = current_selection + SCROLLOFF - NUMLINES + 1; |
| 134 | 134 |
if(start + NUMLINES >= choices_available){
|
| 135 |
- start = choices_available - NUMLINES + 1; |
|
| 135 |
+ start = choices_available - NUMLINES; |
|
| 136 | 136 |
} |
| 137 | 137 |
} |
| 138 | 138 |
const char *prompt = "> "; |
| 139 | 139 |
tty_setcol(tty, 0); |
| 140 | 140 |
tty_printf(tty, "%s%s", prompt, search); |
| 141 |
- tty_newline(tty); |
|
| 142 | 141 |
for(size_t i = start; i < start + NUMLINES; i++){
|
| 142 |
+ tty_newline(tty); |
|
| 143 | 143 |
if(i < choices_available){
|
| 144 | 144 |
size_t choice_idx = choices_sorted[i]; |
| 145 | 145 |
if(flag_show_scores) |
| 146 | 146 |
tty_printf(tty, "(%5.2f) ", choices_score[choice_idx]); |
| 147 | 147 |
draw_match(tty, choices[choice_idx], i == current_selection); |
| 148 |
- }else{
|
|
| 149 |
- tty_newline(tty); |
|
| 150 | 148 |
} |
| 151 | 149 |
} |
| 152 |
- tty_moveup(tty, NUMLINES + 1); |
|
| 150 |
+ tty_clearline(tty); |
|
| 151 |
+ tty_moveup(tty, NUMLINES); |
|
| 153 | 152 |
tty_setcol(tty, strlen(prompt) + strlen(search)); |
| 154 | 153 |
tty_flush(tty); |
| 155 | 154 |
} |
| ... | ... |
@@ -64,6 +64,10 @@ void tty_newline(tty_t *tty){
|
| 64 | 64 |
tty_printf(tty, "%c%cK\n", 0x1b, '['); |
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 |
+void tty_clearline(tty_t *tty){
|
|
| 68 |
+ tty_printf(tty, "%c%cK", 0x1b, '['); |
|
| 69 |
+} |
|
| 70 |
+ |
|
| 67 | 71 |
void tty_setcol(tty_t *tty, int col){
|
| 68 | 72 |
tty_printf(tty, "%c%c%iG", 0x1b, '[', col + 1); |
| 69 | 73 |
} |
| ... | ... |
@@ -34,6 +34,11 @@ void tty_setnormal(tty_t *tty); |
| 34 | 34 |
*/ |
| 35 | 35 |
void tty_newline(tty_t *tty); |
| 36 | 36 |
|
| 37 |
+/* tty_clearline |
|
| 38 |
+ * Clear to the end of the current line without advancing the cursor. |
|
| 39 |
+ */ |
|
| 40 |
+void tty_clearline(tty_t *tty); |
|
| 41 |
+ |
|
| 37 | 42 |
void tty_moveup(tty_t *tty, int i); |
| 38 | 43 |
void tty_setcol(tty_t *tty, int col); |
| 39 | 44 |
|