terminal.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /* Terminal: prompt, datetime (top right), blinking cursor, echo loop, command dispatch.
  2. Commands are spawned as separate processes for preemptive multitasking. */
  3. #include "io.h"
  4. #include "fbtext.h"
  5. #include "idle.h"
  6. #include "process.h"
  7. #include "rtc.h"
  8. #include "terminal.h"
  9. #include "timer.h"
  10. extern void program_hello_main(void);
  11. extern void program_reboot_main(void);
  12. extern void program_ls_main(void);
  13. extern void program_cat_main(const char *filename);
  14. extern void program_run_main(const char *filename);
  15. extern void program_clock_main(void);
  16. extern void program_colors_main(void);
  17. extern void program_display_main(void);
  18. extern void program_cpuinfo_main(void);
  19. extern void program_power_main(const char *args);
  20. extern void disk_set_drive(unsigned int drive);
  21. extern unsigned int disk_get_drive(void);
  22. #define DATETIME_MS 1000
  23. #define LINE_MAX 64
  24. #define HISTORY_SIZE 32
  25. static unsigned int last_datetime_tick;
  26. static char datetime_buf[IO_DATETIME_LEN + 1];
  27. static char history[HISTORY_SIZE][LINE_MAX];
  28. static unsigned int history_count;
  29. static unsigned int history_next;
  30. static int cursor_visible;
  31. static unsigned int last_cursor_tick;
  32. static void redraw_datetime(void)
  33. {
  34. rtc_read_datetime(datetime_buf);
  35. {
  36. unsigned int i;
  37. for (i = 0; i < IO_DATETIME_LEN && datetime_buf[i]; i++)
  38. io_vga_write(IO_DATETIME_POS + i,
  39. (unsigned short)((0x0A << 8) | (unsigned char)datetime_buf[i]));
  40. }
  41. }
  42. static void update_datetime(void)
  43. {
  44. unsigned int t = get_ticks_ms();
  45. if (t - last_datetime_tick >= DATETIME_MS) {
  46. last_datetime_tick = t;
  47. redraw_datetime();
  48. }
  49. }
  50. static void update_cursor_blink(void)
  51. {
  52. unsigned int t = get_ticks_ms();
  53. if (t - last_cursor_tick >= CURSOR_MS) {
  54. last_cursor_tick = t;
  55. cursor_visible = !cursor_visible;
  56. }
  57. if (cursor_visible)
  58. io_cursor_show_block();
  59. else
  60. io_cursor_hide_block();
  61. }
  62. static const char banner[] __attribute__((section(".text"))) = "Nebs OS |o|";
  63. #define BANNER_LEN 12
  64. static const char prompt[] __attribute__((section(".text"))) = "\n> ";
  65. static const char prompt_first[] __attribute__((section(".text"))) = "> ";
  66. /* Draw row 0: banner left, datetime right. Call when terminal is active. */
  67. static void draw_header_row(void)
  68. {
  69. unsigned int i;
  70. for (i = 0; i < BANNER_LEN && banner[i]; i++)
  71. io_vga_write(i, (unsigned short)((0x0A << 8) | (unsigned char)banner[i]));
  72. for (; i < IO_DATETIME_POS; i++)
  73. io_vga_write(i, (unsigned short)(0x0A << 8));
  74. redraw_datetime();
  75. fbtext_draw_rainbow_separator();
  76. }
  77. static int is_cmd_hello(const char *line, unsigned int line_len)
  78. {
  79. unsigned int i = 0;
  80. while (i < line_len && line[i] == ' ')
  81. i++;
  82. if (i + 5 > line_len)
  83. return 0;
  84. if (line[i] != 'h' || line[i+1] != 'e' || line[i+2] != 'l' || line[i+3] != 'l' || line[i+4] != 'o')
  85. return 0;
  86. i += 5;
  87. while (i < line_len && line[i] == ' ')
  88. i++;
  89. return (i == line_len);
  90. }
  91. static int is_cmd_reboot(const char *line, unsigned int line_len)
  92. {
  93. unsigned int i = 0;
  94. while (i < line_len && line[i] == ' ')
  95. i++;
  96. if (i + 6 > line_len)
  97. return 0;
  98. if (line[i] != 'r' || line[i+1] != 'e' || line[i+2] != 'b' || line[i+3] != 'o' || line[i+4] != 'o' || line[i+5] != 't')
  99. return 0;
  100. i += 6;
  101. while (i < line_len && line[i] == ' ')
  102. i++;
  103. return (i == line_len);
  104. }
  105. static int is_cmd_ls(const char *line, unsigned int line_len)
  106. {
  107. unsigned int i = 0;
  108. while (i < line_len && line[i] == ' ')
  109. i++;
  110. if (i + 2 > line_len)
  111. return 0;
  112. if (line[i] != 'l' || line[i+1] != 's')
  113. return 0;
  114. i += 2;
  115. while (i < line_len && line[i] == ' ')
  116. i++;
  117. return (i == line_len);
  118. }
  119. static int is_cmd_clock(const char *line, unsigned int line_len)
  120. {
  121. unsigned int i = 0;
  122. while (i < line_len && line[i] == ' ')
  123. i++;
  124. if (i + 5 > line_len)
  125. return 0;
  126. if (line[i] != 'c' || line[i+1] != 'l' || line[i+2] != 'o' ||
  127. line[i+3] != 'c' || line[i+4] != 'k')
  128. return 0;
  129. i += 5;
  130. while (i < line_len && line[i] == ' ')
  131. i++;
  132. return (i == line_len);
  133. }
  134. static int is_cmd_colors(const char *line, unsigned int line_len)
  135. {
  136. unsigned int i = 0;
  137. while (i < line_len && line[i] == ' ')
  138. i++;
  139. if (i + 6 > line_len)
  140. return 0;
  141. if (line[i] != 'c' || line[i+1] != 'o' || line[i+2] != 'l' ||
  142. line[i+3] != 'o' || line[i+4] != 'r' || line[i+5] != 's')
  143. return 0;
  144. i += 6;
  145. while (i < line_len && line[i] == ' ')
  146. i++;
  147. return (i == line_len);
  148. }
  149. static int is_cmd_display(const char *line, unsigned int line_len)
  150. {
  151. unsigned int i = 0;
  152. while (i < line_len && line[i] == ' ')
  153. i++;
  154. if (i + 7 > line_len)
  155. return 0;
  156. if (line[i] != 'd' || line[i+1] != 'i' || line[i+2] != 's' || line[i+3] != 'p' ||
  157. line[i+4] != 'l' || line[i+5] != 'a' || line[i+6] != 'y')
  158. return 0;
  159. i += 7;
  160. while (i < line_len && line[i] == ' ')
  161. i++;
  162. return (i == line_len);
  163. }
  164. static int is_cmd_cpuinfo(const char *line, unsigned int line_len)
  165. {
  166. unsigned int i = 0;
  167. while (i < line_len && line[i] == ' ')
  168. i++;
  169. if (i + 7 > line_len)
  170. return 0;
  171. if (line[i] != 'c' || line[i+1] != 'p' || line[i+2] != 'u' || line[i+3] != 'i' ||
  172. line[i+4] != 'n' || line[i+5] != 'f' || line[i+6] != 'o')
  173. return 0;
  174. i += 7;
  175. while (i < line_len && line[i] == ' ')
  176. i++;
  177. return (i == line_len);
  178. }
  179. static int is_cmd_space(const char *line, unsigned int line_len)
  180. {
  181. unsigned int i = 0;
  182. while (i < line_len && line[i] == ' ')
  183. i++;
  184. if (i + 5 > line_len)
  185. return 0;
  186. if (line[i] != 's' || line[i+1] != 'p' || line[i+2] != 'a' ||
  187. line[i+3] != 'c' || line[i+4] != 'e')
  188. return 0;
  189. i += 5;
  190. while (i < line_len && line[i] == ' ')
  191. i++;
  192. return (i == line_len);
  193. }
  194. #define CAT_FNAME_MAX 64
  195. static int is_cmd_cat(const char *line, unsigned int line_len, char *filename_buf, unsigned int buf_size)
  196. {
  197. unsigned int i = 0, j;
  198. while (i < line_len && line[i] == ' ')
  199. i++;
  200. if (i + 3 > line_len)
  201. return 0;
  202. if (line[i] != 'c' || line[i+1] != 'a' || line[i+2] != 't')
  203. return 0;
  204. i += 3;
  205. while (i < line_len && line[i] == ' ')
  206. i++;
  207. if (i >= line_len)
  208. return 0;
  209. j = 0;
  210. while (i < line_len && line[i] != ' ' && j < buf_size - 1)
  211. filename_buf[j++] = line[i++];
  212. filename_buf[j] = '\0';
  213. return (j > 0);
  214. }
  215. static int is_cmd_run(const char *line, unsigned int line_len, char *filename_buf, unsigned int buf_size)
  216. {
  217. unsigned int i = 0, j;
  218. while (i < line_len && line[i] == ' ')
  219. i++;
  220. if (i + 3 > line_len)
  221. return 0;
  222. if (line[i] != 'r' || line[i+1] != 'u' || line[i+2] != 'n')
  223. return 0;
  224. i += 3;
  225. while (i < line_len && line[i] == ' ')
  226. i++;
  227. if (i >= line_len)
  228. return 0;
  229. j = 0;
  230. while (i < line_len && line[i] != ' ' && j < buf_size - 1)
  231. filename_buf[j++] = line[i++];
  232. filename_buf[j] = '\0';
  233. return (j > 0);
  234. }
  235. static int is_cmd_drive(const char *line, unsigned int line_len, unsigned int *drive_num)
  236. {
  237. unsigned int i = 0;
  238. while (i < line_len && line[i] == ' ')
  239. i++;
  240. if (i + 5 > line_len)
  241. return 0;
  242. if (line[i] != 'd' || line[i+1] != 'r' || line[i+2] != 'i' || line[i+3] != 'v' || line[i+4] != 'e')
  243. return 0;
  244. i += 5;
  245. while (i < line_len && line[i] == ' ')
  246. i++;
  247. if (i >= line_len || line[i] < '0' || line[i] > '1')
  248. return 0;
  249. *drive_num = (unsigned int)(line[i] - '0');
  250. i++;
  251. while (i < line_len && line[i] == ' ')
  252. i++;
  253. return (i == line_len);
  254. }
  255. static int is_cmd_help(const char *line, unsigned int line_len)
  256. {
  257. unsigned int i = 0;
  258. while (i < line_len && line[i] == ' ')
  259. i++;
  260. if (i + 4 > line_len)
  261. return 0;
  262. if (line[i] != 'h' || line[i+1] != 'e' || line[i+2] != 'l' || line[i+3] != 'p')
  263. return 0;
  264. i += 4;
  265. while (i < line_len && line[i] == ' ')
  266. i++;
  267. return (i == line_len);
  268. }
  269. static int is_cmd_clear(const char *line, unsigned int line_len)
  270. {
  271. unsigned int i = 0;
  272. while (i < line_len && line[i] == ' ')
  273. i++;
  274. if (i + 5 > line_len)
  275. return 0;
  276. if (line[i] != 'c' || line[i+1] != 'l' || line[i+2] != 'e' ||
  277. line[i+3] != 'a' || line[i+4] != 'r')
  278. return 0;
  279. i += 5;
  280. while (i < line_len && line[i] == ' ')
  281. i++;
  282. return (i == line_len);
  283. }
  284. static int is_cmd_ps(const char *line, unsigned int line_len)
  285. {
  286. unsigned int i = 0;
  287. while (i < line_len && line[i] == ' ')
  288. i++;
  289. if (i + 2 > line_len)
  290. return 0;
  291. if (line[i] != 'p' || line[i+1] != 's')
  292. return 0;
  293. i += 2;
  294. while (i < line_len && line[i] == ' ')
  295. i++;
  296. return (i == line_len);
  297. }
  298. static int is_cmd_kill(const char *line, unsigned int line_len, unsigned int *pid_out)
  299. {
  300. unsigned int i = 0, num = 0;
  301. int has_digit = 0;
  302. while (i < line_len && line[i] == ' ')
  303. i++;
  304. if (i + 4 > line_len)
  305. return 0;
  306. if (line[i] != 'k' || line[i+1] != 'i' || line[i+2] != 'l' || line[i+3] != 'l')
  307. return 0;
  308. i += 4;
  309. while (i < line_len && line[i] == ' ')
  310. i++;
  311. while (i < line_len && line[i] >= '0' && line[i] <= '9') {
  312. num = num * 10 + (unsigned int)(line[i] - '0');
  313. has_digit = 1;
  314. i++;
  315. }
  316. if (!has_digit)
  317. return 0;
  318. while (i < line_len && line[i] == ' ')
  319. i++;
  320. if (i != line_len)
  321. return 0;
  322. *pid_out = num;
  323. return 1;
  324. }
  325. #define POWER_ARGS_MAX 32
  326. static int is_cmd_power(const char *line, unsigned int line_len, char *args_buf, unsigned int buf_size)
  327. {
  328. unsigned int i = 0, j = 0;
  329. while (i < line_len && line[i] == ' ')
  330. i++;
  331. if (i + 5 > line_len)
  332. return 0;
  333. if (line[i] != 'p' || line[i+1] != 'o' || line[i+2] != 'w' || line[i+3] != 'e' || line[i+4] != 'r')
  334. return 0;
  335. i += 5;
  336. while (i < line_len && line[i] == ' ')
  337. i++;
  338. if (i == line_len) {
  339. if (buf_size > 0)
  340. args_buf[0] = '\0';
  341. return 1;
  342. }
  343. while (i < line_len && j + 1 < buf_size)
  344. args_buf[j++] = line[i++];
  345. while (j > 0 && args_buf[j - 1] == ' ')
  346. j--;
  347. args_buf[j] = '\0';
  348. while (i < line_len && line[i] == ' ')
  349. i++;
  350. return (i == line_len);
  351. }
  352. /* Redraw line from index `from` to end, clear one cell after, set cursor to line_pos. */
  353. static void redraw_line_from(const char *line, unsigned int line_len,
  354. unsigned int line_pos, unsigned int line_start, unsigned int from)
  355. {
  356. unsigned int i;
  357. io_set_cursor(line_start + from);
  358. for (i = from; i < line_len; i++)
  359. io_putchar(line[i]);
  360. io_putchar(' ');
  361. io_set_cursor(line_start + line_pos);
  362. }
  363. /* Redraw entire line and clear through clear_through (so leftover chars are erased). */
  364. static void redraw_line_clear(const char *line, unsigned int line_len,
  365. unsigned int line_pos, unsigned int line_start, unsigned int clear_through)
  366. {
  367. unsigned int i;
  368. io_set_cursor(line_start);
  369. for (i = 0; i < line_len; i++)
  370. io_putchar(line[i]);
  371. for (i = line_len; i <= clear_through; i++)
  372. io_putchar(' ');
  373. io_set_cursor(line_start + line_pos);
  374. }
  375. /* Copy history entry (1 = newest) into line, set line_len/line_pos, redraw from start. */
  376. static void history_load_into_line(char *line, unsigned int *line_len, unsigned int *line_pos,
  377. unsigned int line_start, unsigned int browse)
  378. {
  379. unsigned int slot, len, old_len;
  380. const char *src;
  381. if (browse < 1 || browse > history_count)
  382. return;
  383. old_len = *line_len;
  384. slot = (history_next + HISTORY_SIZE - browse) % HISTORY_SIZE;
  385. src = history[slot];
  386. for (len = 0; len < LINE_MAX - 1 && src[len]; len++)
  387. line[len] = src[len];
  388. line[len] = '\0';
  389. *line_len = len;
  390. *line_pos = len;
  391. redraw_line_clear(line, len, len, line_start, old_len > len ? old_len : len);
  392. }
  393. /* Push current line to history if non-empty (and not duplicate of newest). */
  394. static void history_push(const char *line, unsigned int line_len)
  395. {
  396. unsigned int i, slot;
  397. int all_spaces = 1;
  398. if (line_len == 0)
  399. return;
  400. for (i = 0; i < line_len; i++) {
  401. if (line[i] != ' ') {
  402. all_spaces = 0;
  403. break;
  404. }
  405. }
  406. if (all_spaces)
  407. return;
  408. if (history_count > 0) {
  409. slot = (history_next + HISTORY_SIZE - 1) % HISTORY_SIZE;
  410. for (i = 0; i < line_len && i < LINE_MAX - 1 && history[slot][i]; i++) {
  411. if (history[slot][i] != line[i])
  412. break;
  413. }
  414. if (i == line_len && history[slot][i] == '\0')
  415. return; /* duplicate of newest */
  416. }
  417. slot = history_next;
  418. for (i = 0; i < line_len && i < LINE_MAX - 1; i++)
  419. history[slot][i] = line[i];
  420. history[slot][i] = '\0';
  421. history_next = (history_next + 1) % HISTORY_SIZE;
  422. if (history_count < HISTORY_SIZE)
  423. history_count++;
  424. }
  425. void terminal_run(void)
  426. {
  427. static char line[LINE_MAX];
  428. static unsigned int line_len;
  429. static unsigned int line_pos; /* cursor index in line, 0..line_len */
  430. static unsigned int line_start; /* VGA position of first char of line */
  431. static unsigned int history_browse; /* 0 = not browsing, 1 = newest, 2 = older, ... */
  432. last_cursor_tick = get_ticks_ms();
  433. last_datetime_tick = get_ticks_ms();
  434. cursor_visible = 1;
  435. line_len = 0;
  436. line_pos = 0;
  437. line[0] = '\0';
  438. history_browse = 0;
  439. io_drain_keyboard();
  440. draw_header_row();
  441. io_putstr(prompt_first);
  442. line_start = io_get_cursor();
  443. for (;;) {
  444. update_datetime();
  445. update_cursor_blink();
  446. {
  447. int k = io_poll_key();
  448. if (k) {
  449. if (k == IO_KEY_LEFT) {
  450. if (line_pos > 0) {
  451. line_pos--;
  452. io_set_cursor(line_start + line_pos);
  453. }
  454. } else if (k == IO_KEY_RIGHT) {
  455. if (line_pos < line_len) {
  456. line_pos++;
  457. io_set_cursor(line_start + line_pos);
  458. }
  459. } else if (k == IO_KEY_UP) {
  460. if (history_count > 0) {
  461. if (history_browse < history_count)
  462. history_browse++;
  463. history_load_into_line(line, &line_len, &line_pos, line_start, history_browse);
  464. }
  465. } else if (k == IO_KEY_DOWN) {
  466. if (history_browse > 0) {
  467. history_browse--;
  468. if (history_browse == 0) {
  469. {
  470. unsigned int clear_len = line_len;
  471. line_len = 0;
  472. line_pos = 0;
  473. line[0] = '\0';
  474. redraw_line_clear(line, 0, 0, line_start, clear_len);
  475. }
  476. } else {
  477. history_load_into_line(line, &line_len, &line_pos, line_start, history_browse);
  478. }
  479. }
  480. } else if (k == '\b') {
  481. if (line_pos > 0) {
  482. unsigned int i;
  483. line_pos--;
  484. for (i = line_pos; i < line_len; i++)
  485. line[i] = line[i + 1];
  486. line_len--;
  487. line[line_len] = '\0';
  488. redraw_line_from(line, line_len, line_pos, line_start, line_pos);
  489. }
  490. } else if (k == '\n') {
  491. static char cat_fname[CAT_FNAME_MAX];
  492. static char power_args[POWER_ARGS_MAX];
  493. unsigned int drive_sel, kill_pid;
  494. int skip_prompt = 0;
  495. io_putchar('\n');
  496. history_push(line, line_len);
  497. history_browse = 0;
  498. if (is_cmd_hello(line, line_len)) {
  499. if (process_create("hello", program_hello_main) < 0)
  500. io_putstr("error: too many processes\n");
  501. } else if (is_cmd_reboot(line, line_len)) {
  502. program_reboot_main();
  503. } else if (is_cmd_ls(line, line_len)) {
  504. if (process_create("ls", program_ls_main) < 0)
  505. io_putstr("error: too many processes\n");
  506. } else if (is_cmd_clock(line, line_len)) {
  507. if (process_create("clock", program_clock_main) < 0)
  508. io_putstr("error: too many processes\n");
  509. } else if (is_cmd_colors(line, line_len)) {
  510. if (process_create("colors", program_colors_main) < 0)
  511. io_putstr("error: too many processes\n");
  512. } else if (is_cmd_cat(line, line_len, cat_fname, CAT_FNAME_MAX)) {
  513. if (process_create_arg("cat", program_cat_main, cat_fname) < 0)
  514. io_putstr("error: too many processes\n");
  515. } else if (is_cmd_run(line, line_len, cat_fname, CAT_FNAME_MAX)) {
  516. if (process_create_arg("run", program_run_main, cat_fname) < 0)
  517. io_putstr("error: too many processes\n");
  518. } else if (is_cmd_space(line, line_len)) {
  519. if (process_create_arg("space", program_run_main, "space.bin") < 0)
  520. io_putstr("error: too many processes\n");
  521. } else if (is_cmd_display(line, line_len)) {
  522. if (process_create("display", program_display_main) < 0)
  523. io_putstr("error: too many processes\n");
  524. } else if (is_cmd_cpuinfo(line, line_len)) {
  525. if (process_create("cpuinfo", program_cpuinfo_main) < 0)
  526. io_putstr("error: too many processes\n");
  527. } else if (is_cmd_power(line, line_len, power_args, POWER_ARGS_MAX)) {
  528. if (process_create_arg("power", program_power_main, power_args) < 0)
  529. io_putstr("error: too many processes\n");
  530. } else if (is_cmd_drive(line, line_len, &drive_sel)) {
  531. disk_set_drive(drive_sel);
  532. io_putstr("drive ");
  533. io_putchar((char)('0' + disk_get_drive()));
  534. io_putstr(" selected\n");
  535. } else if (is_cmd_ps(line, line_len)) {
  536. process_ps();
  537. } else if (is_cmd_kill(line, line_len, &kill_pid)) {
  538. if (process_kill(kill_pid) < 0)
  539. io_putstr("kill: no such process\n");
  540. else
  541. io_putstr("killed\n");
  542. } else if (is_cmd_help(line, line_len)) {
  543. io_putstr("hello reboot\n");
  544. io_putstr("ls cat <file>\n");
  545. io_putstr("run <file> space\n");
  546. io_putstr("clock colors\n");
  547. io_putstr("display cpuinfo\n");
  548. io_putstr("power [info|set <low|balanced|max>]\n");
  549. io_putstr("drive <0|1>\n");
  550. io_putstr("ps kill <pid>\n");
  551. io_putstr("help clear\n");
  552. } else if (is_cmd_clear(line, line_len)) {
  553. io_clear_screen();
  554. draw_header_row();
  555. io_set_cursor(IO_CONTENT_OFFSET);
  556. io_putstr(prompt_first);
  557. line_start = io_get_cursor();
  558. skip_prompt = 1;
  559. } else {
  560. unsigned int i = 0;
  561. while (i < line_len && line[i] == ' ')
  562. i++;
  563. if (i < line_len)
  564. io_putstr("command not found\n");
  565. }
  566. line_len = 0;
  567. line_pos = 0;
  568. line[0] = '\0';
  569. if (!skip_prompt) {
  570. io_putstr(prompt);
  571. line_start = io_get_cursor();
  572. }
  573. if (io_did_scroll())
  574. redraw_datetime();
  575. } else {
  576. {
  577. unsigned char u = (unsigned char)k;
  578. if (u >= 0x20 && u < 0x7F && line_len < LINE_MAX - 1) {
  579. unsigned int i;
  580. history_browse = 0;
  581. for (i = line_len; i > line_pos; i--)
  582. line[i] = line[i - 1];
  583. line[line_pos] = (char)k;
  584. line_len++;
  585. line[line_len] = '\0';
  586. line_pos++;
  587. redraw_line_from(line, line_len, line_pos, line_start, line_pos - 1);
  588. }
  589. }
  590. }
  591. } else {
  592. cpu_idle();
  593. }
  594. }
  595. }
  596. }