| 76 |
|
|
| 77 |
int press_any_key() |
int press_any_key() |
| 78 |
{ |
{ |
|
igetch(1); |
|
|
|
|
| 79 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 80 |
clrtoeol(); |
clrtoeol(); |
| 81 |
|
|
| 112 |
offset++; |
offset++; |
| 113 |
} |
} |
| 114 |
|
|
|
igetch(1); |
|
|
|
|
| 115 |
while (c = igetch_t(60)) |
while (c = igetch_t(60)) |
| 116 |
{ |
{ |
| 117 |
if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) |
if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) |
| 118 |
{ |
{ |
| 119 |
|
igetch(1); // Cleanup remaining '\n' in the buffer |
| 120 |
break; |
break; |
| 121 |
} |
} |
| 122 |
if (c == LF) |
if (c == LF) |
| 235 |
long *p_line_offsets; |
long *p_line_offsets; |
| 236 |
int len; |
int len; |
| 237 |
int percentile; |
int percentile; |
| 238 |
|
int loop = 1; |
| 239 |
|
|
| 240 |
if ((fin = fopen(filename, "r")) == NULL) |
if ((fin = fopen(filename, "r")) == NULL) |
| 241 |
{ |
{ |
| 251 |
line = begin_line; |
line = begin_line; |
| 252 |
max_lines = screen_rows - 1; |
max_lines = screen_rows - 1; |
| 253 |
|
|
| 254 |
while (c_line_current < c_line_total) |
while (loop) |
| 255 |
{ |
{ |
| 256 |
if (line >= max_lines) |
if (c_line_current >= c_line_total && c_line_total <= screen_rows - 2) |
| 257 |
{ |
{ |
| 258 |
percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; |
if (wait) |
| 259 |
|
{ |
| 260 |
|
ch = press_any_key(); |
| 261 |
|
} |
| 262 |
|
else |
| 263 |
|
{ |
| 264 |
|
iflush(); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
loop = 0; |
| 268 |
|
break; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
if (c_line_current >= c_line_total || line >= max_lines) |
| 272 |
|
{ |
| 273 |
|
if (c_line_current - (line - 1) + (screen_rows - 2) < c_line_total) |
| 274 |
|
{ |
| 275 |
|
percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; |
| 276 |
|
} |
| 277 |
|
else |
| 278 |
|
{ |
| 279 |
|
percentile = 100; |
| 280 |
|
} |
| 281 |
|
|
| 282 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 283 |
prints("\033[1;44;32m下面还有喔 (%d%%)\033[33m │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", |
prints("\033[1;44;32m%s (%d%%)%s\033[33m │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", |
| 284 |
percentile); |
(percentile < 100 ? "下面还有喔" : "没有更多了"), percentile, |
| 285 |
|
(percentile < 10 ? " " : (percentile < 100 ? " " : ""))); |
| 286 |
iflush(); |
iflush(); |
| 287 |
|
|
| 288 |
input_ok = 0; |
input_ok = 0; |
| 300 |
c_line_current -= line; |
c_line_current -= line; |
| 301 |
line = begin_line; |
line = begin_line; |
| 302 |
max_lines = begin_line + 1; |
max_lines = begin_line + 1; |
| 303 |
prints("\033[1T"); // Scroll down 1 line |
prints("\033[T"); // Scroll down 1 line |
| 304 |
|
// max_lines = screen_rows - 1; // Legacy Fterm only works with this line |
| 305 |
break; |
break; |
| 306 |
case KEY_DOWN: |
case KEY_DOWN: |
| 307 |
case CR: |
case CR: |
| 314 |
max_lines = screen_rows - 1; |
max_lines = screen_rows - 1; |
| 315 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 316 |
clrtoeol(); |
clrtoeol(); |
| 317 |
prints("\033[1S"); // Scroll up 1 line |
prints("\033[S"); // Scroll up 1 line |
| 318 |
break; |
break; |
| 319 |
case KEY_PGUP: |
case KEY_PGUP: |
| 320 |
case Ctrl('B'): |
case Ctrl('B'): |
| 353 |
case KEY_LEFT: |
case KEY_LEFT: |
| 354 |
case 'q': |
case 'q': |
| 355 |
case 'Q': |
case 'Q': |
| 356 |
c_line_current = c_line_total; |
loop = 0; |
|
wait = 0; |
|
| 357 |
break; |
break; |
| 358 |
case '?': |
case '?': |
| 359 |
case 'h': |
case 'h': |
| 397 |
line++; |
line++; |
| 398 |
} |
} |
| 399 |
|
|
|
iflush(); |
|
|
|
|
|
if (wait) |
|
|
{ |
|
|
ch = press_any_key(); |
|
|
} |
|
|
|
|
| 400 |
free(p_line_offsets); |
free(p_line_offsets); |
| 401 |
fclose(fin); |
fclose(fin); |
| 402 |
|
|