blob: 62d419bb36a723a681bf15fadb104a57686aa840 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass6493ccc2014-04-10 20:01:26 -06002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * Add to readline cmdline-editing by
7 * (C) Copyright 2005
8 * JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
Simon Glass6493ccc2014-04-10 20:01:26 -06009 */
10
11#include <common.h>
Simon Glass0098e172014-04-10 20:01:30 -060012#include <bootretry.h>
Simon Glass6493ccc2014-04-10 20:01:26 -060013#include <cli.h>
Simon Glass09140112020-05-10 11:40:03 -060014#include <command.h>
Simon Glass10453152019-11-14 12:57:30 -070015#include <time.h>
Simon Glass6493ccc2014-04-10 20:01:26 -060016#include <watchdog.h>
Simon Glass401d1c42020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glass6493ccc2014-04-10 20:01:26 -060018
19DECLARE_GLOBAL_DATA_PTR;
20
21static const char erase_seq[] = "\b \b"; /* erase sequence */
22static const char tab_seq[] = " "; /* used to expand TABs */
23
Simon Glass6493ccc2014-04-10 20:01:26 -060024char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */
25
Simon Glass6493ccc2014-04-10 20:01:26 -060026static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)
27{
28 char *s;
29
30 if (*np == 0)
31 return p;
32
33 if (*(--p) == '\t') { /* will retype the whole line */
34 while (*colp > plen) {
35 puts(erase_seq);
36 (*colp)--;
37 }
38 for (s = buffer; s < p; ++s) {
39 if (*s == '\t') {
40 puts(tab_seq + ((*colp) & 07));
41 *colp += 8 - ((*colp) & 07);
42 } else {
43 ++(*colp);
44 putc(*s);
45 }
46 }
47 } else {
48 puts(erase_seq);
49 (*colp)--;
50 }
51 (*np)--;
52
53 return p;
54}
55
56#ifdef CONFIG_CMDLINE_EDITING
57
58/*
59 * cmdline-editing related codes from vivi.
60 * Author: Janghoon Lyu <nandy@mizi.com>
61 */
62
63#define putnstr(str, n) printf("%.*s", (int)n, str)
64
Simon Glass6493ccc2014-04-10 20:01:26 -060065#define CTL_BACKSPACE ('\b')
66#define DEL ((char)255)
67#define DEL7 ((char)127)
68#define CREAD_HIST_CHAR ('!')
69
70#define getcmd_putch(ch) putc(ch)
Heinrich Schuchardtc670aee2020-10-07 18:11:48 +020071#define getcmd_getch() getchar()
Simon Glass6493ccc2014-04-10 20:01:26 -060072#define getcmd_cbeep() getcmd_putch('\a')
73
Sean Anderson069f0d72022-08-30 16:40:37 -040074#ifdef CONFIG_SPL_BUILD
75#define HIST_MAX 3
76#define HIST_SIZE 32
77#else
Simon Glass6493ccc2014-04-10 20:01:26 -060078#define HIST_MAX 20
79#define HIST_SIZE CONFIG_SYS_CBSIZE
Sean Anderson069f0d72022-08-30 16:40:37 -040080#endif
Simon Glass6493ccc2014-04-10 20:01:26 -060081
82static int hist_max;
83static int hist_add_idx;
84static int hist_cur = -1;
85static unsigned hist_num;
86
87static char *hist_list[HIST_MAX];
88static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
89
90#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
91
Simon Glassdcc18ce2023-10-01 19:13:09 -060092static void getcmd_putchars(int count, int ch)
93{
94 int i;
95
96 for (i = 0; i < count; i++)
97 getcmd_putch(ch);
98}
99
Simon Glass6493ccc2014-04-10 20:01:26 -0600100static void hist_init(void)
101{
102 int i;
103
104 hist_max = 0;
105 hist_add_idx = 0;
106 hist_cur = -1;
107 hist_num = 0;
108
109 for (i = 0; i < HIST_MAX; i++) {
110 hist_list[i] = hist_lines[i];
111 hist_list[i][0] = '\0';
112 }
113}
114
115static void cread_add_to_hist(char *line)
116{
117 strcpy(hist_list[hist_add_idx], line);
118
119 if (++hist_add_idx >= HIST_MAX)
120 hist_add_idx = 0;
121
122 if (hist_add_idx > hist_max)
123 hist_max = hist_add_idx;
124
125 hist_num++;
126}
127
128static char *hist_prev(void)
129{
130 char *ret;
131 int old_cur;
132
133 if (hist_cur < 0)
134 return NULL;
135
136 old_cur = hist_cur;
137 if (--hist_cur < 0)
138 hist_cur = hist_max;
139
140 if (hist_cur == hist_add_idx) {
141 hist_cur = old_cur;
142 ret = NULL;
143 } else {
144 ret = hist_list[hist_cur];
145 }
146
147 return ret;
148}
149
150static char *hist_next(void)
151{
152 char *ret;
153
154 if (hist_cur < 0)
155 return NULL;
156
157 if (hist_cur == hist_add_idx)
158 return NULL;
159
160 if (++hist_cur > hist_max)
161 hist_cur = 0;
162
163 if (hist_cur == hist_add_idx)
164 ret = "";
165 else
166 ret = hist_list[hist_cur];
167
168 return ret;
169}
170
Simon Glass33eb0b92023-10-01 19:13:06 -0600171void cread_print_hist_list(void)
Simon Glass6493ccc2014-04-10 20:01:26 -0600172{
173 int i;
Simon Glassfedd3722023-10-01 19:13:10 -0600174 uint n;
Simon Glass6493ccc2014-04-10 20:01:26 -0600175
176 n = hist_num - hist_max;
177
178 i = hist_add_idx + 1;
179 while (1) {
180 if (i > hist_max)
181 i = 0;
182 if (i == hist_add_idx)
183 break;
184 printf("%s\n", hist_list[i]);
185 n++;
186 i++;
187 }
188}
Simon Glass6493ccc2014-04-10 20:01:26 -0600189
190#define BEGINNING_OF_LINE() { \
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600191 while (cls->num) { \
Simon Glass6493ccc2014-04-10 20:01:26 -0600192 getcmd_putch(CTL_BACKSPACE); \
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600193 cls->num--; \
Simon Glass6493ccc2014-04-10 20:01:26 -0600194 } \
195}
196
197#define ERASE_TO_EOL() { \
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600198 if (cls->num < cls->eol_num) { \
199 printf("%*s", (int)(cls->eol_num - cls->num), ""); \
Simon Glass6493ccc2014-04-10 20:01:26 -0600200 do { \
201 getcmd_putch(CTL_BACKSPACE); \
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600202 } while (--cls->eol_num > cls->num); \
Simon Glass6493ccc2014-04-10 20:01:26 -0600203 } \
204}
205
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600206#define REFRESH_TO_EOL() { \
207 if (cls->num < cls->eol_num) { \
208 uint wlen = cls->eol_num - cls->num; \
209 putnstr(buf + cls->num, wlen); \
210 cls->num = cls->eol_num; \
211 } \
Simon Glass6493ccc2014-04-10 20:01:26 -0600212}
213
Simon Glassfedd3722023-10-01 19:13:10 -0600214static void cread_add_char(char ichar, int insert, uint *num,
215 uint *eol_num, char *buf, uint len)
Simon Glass6493ccc2014-04-10 20:01:26 -0600216{
Simon Glassfedd3722023-10-01 19:13:10 -0600217 uint wlen;
Simon Glass6493ccc2014-04-10 20:01:26 -0600218
219 /* room ??? */
220 if (insert || *num == *eol_num) {
221 if (*eol_num > len - 1) {
222 getcmd_cbeep();
223 return;
224 }
225 (*eol_num)++;
226 }
227
228 if (insert) {
229 wlen = *eol_num - *num;
230 if (wlen > 1)
231 memmove(&buf[*num+1], &buf[*num], wlen-1);
232
233 buf[*num] = ichar;
234 putnstr(buf + *num, wlen);
235 (*num)++;
236 while (--wlen)
237 getcmd_putch(CTL_BACKSPACE);
238 } else {
239 /* echo the character */
240 wlen = 1;
241 buf[*num] = ichar;
242 putnstr(buf + *num, wlen);
243 (*num)++;
244 }
245}
246
247static void cread_add_str(char *str, int strsize, int insert,
Simon Glassfedd3722023-10-01 19:13:10 -0600248 uint *num, uint *eol_num, char *buf, uint len)
Simon Glass6493ccc2014-04-10 20:01:26 -0600249{
250 while (strsize--) {
251 cread_add_char(*str, insert, num, eol_num, buf, len);
252 str++;
253 }
254}
255
Simon Glasse5509ce2023-10-01 19:13:13 -0600256int cread_line_process_ch(struct cli_line_state *cls, char ichar)
Simon Glass6493ccc2014-04-10 20:01:26 -0600257{
Simon Glasse5509ce2023-10-01 19:13:13 -0600258 char *buf = cls->buf;
Simon Glass6493ccc2014-04-10 20:01:26 -0600259
Simon Glass8d997aa2023-10-01 19:13:12 -0600260 /* ichar=0x0 when error occurs in U-Boot getc */
261 if (!ichar)
Simon Glasse5509ce2023-10-01 19:13:13 -0600262 return -EAGAIN;
Patrick Delaunay555e3782018-08-03 13:38:45 +0200263
Simon Glass8d997aa2023-10-01 19:13:12 -0600264 if (ichar == '\n') {
265 putc('\n');
Simon Glasse5509ce2023-10-01 19:13:13 -0600266 return 0;
Simon Glass8d997aa2023-10-01 19:13:12 -0600267 }
268
269 switch (ichar) {
270 case CTL_CH('a'):
271 BEGINNING_OF_LINE();
272 break;
273 case CTL_CH('c'): /* ^C - break */
274 *buf = '\0'; /* discard input */
Simon Glasse5509ce2023-10-01 19:13:13 -0600275 return -EINTR;
Simon Glass8d997aa2023-10-01 19:13:12 -0600276 case CTL_CH('f'):
277 if (cls->num < cls->eol_num) {
278 getcmd_putch(buf[cls->num]);
279 cls->num++;
Simon Glass6493ccc2014-04-10 20:01:26 -0600280 }
Simon Glass8d997aa2023-10-01 19:13:12 -0600281 break;
282 case CTL_CH('b'):
283 if (cls->num) {
284 getcmd_putch(CTL_BACKSPACE);
285 cls->num--;
286 }
287 break;
288 case CTL_CH('d'):
289 if (cls->num < cls->eol_num) {
290 uint wlen;
Simon Glass6493ccc2014-04-10 20:01:26 -0600291
Simon Glass8d997aa2023-10-01 19:13:12 -0600292 wlen = cls->eol_num - cls->num - 1;
293 if (wlen) {
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600294 memmove(&buf[cls->num], &buf[cls->num + 1],
295 wlen);
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600296 putnstr(buf + cls->num, wlen);
Simon Glass6493ccc2014-04-10 20:01:26 -0600297 }
298
Simon Glass8d997aa2023-10-01 19:13:12 -0600299 getcmd_putch(' ');
300 do {
301 getcmd_putch(CTL_BACKSPACE);
302 } while (wlen--);
303 cls->eol_num--;
304 }
305 break;
306 case CTL_CH('k'):
307 ERASE_TO_EOL();
308 break;
309 case CTL_CH('e'):
310 REFRESH_TO_EOL();
311 break;
312 case CTL_CH('o'):
313 cls->insert = !cls->insert;
314 break;
315 case CTL_CH('w'):
316 if (cls->num) {
317 uint base, wlen;
Simon Glass6493ccc2014-04-10 20:01:26 -0600318
Simon Glass8d997aa2023-10-01 19:13:12 -0600319 for (base = cls->num - 1;
320 base >= 0 && buf[base] == ' ';)
321 base--;
322 for (; base > 0 && buf[base - 1] != ' ';)
323 base--;
Simon Glass6493ccc2014-04-10 20:01:26 -0600324
Simon Glass8d997aa2023-10-01 19:13:12 -0600325 /* now delete chars from base to cls->num */
326 wlen = cls->num - base;
327 cls->eol_num -= wlen;
328 memmove(&buf[base], &buf[cls->num],
329 cls->eol_num - base + 1);
330 cls->num = base;
331 getcmd_putchars(wlen, CTL_BACKSPACE);
332 puts(buf + base);
333 getcmd_putchars(wlen, ' ');
334 getcmd_putchars(wlen + cls->eol_num - cls->num,
335 CTL_BACKSPACE);
336 }
337 break;
338 case CTL_CH('x'):
339 case CTL_CH('u'):
340 BEGINNING_OF_LINE();
341 ERASE_TO_EOL();
342 break;
343 case DEL:
344 case DEL7:
345 case 8:
346 if (cls->num) {
347 uint wlen;
348
349 wlen = cls->eol_num - cls->num;
350 cls->num--;
351 memmove(&buf[cls->num], &buf[cls->num + 1], wlen);
352 getcmd_putch(CTL_BACKSPACE);
353 putnstr(buf + cls->num, wlen);
354 getcmd_putch(' ');
355 do {
356 getcmd_putch(CTL_BACKSPACE);
357 } while (wlen--);
358 cls->eol_num--;
359 }
360 break;
361 case CTL_CH('p'):
362 case CTL_CH('n'):
363 {
364 char *hline;
365
366 if (ichar == CTL_CH('p'))
367 hline = hist_prev();
368 else
369 hline = hist_next();
370
371 if (!hline) {
372 getcmd_cbeep();
Simon Glasse5509ce2023-10-01 19:13:13 -0600373 break;
Simon Glass6493ccc2014-04-10 20:01:26 -0600374 }
Simon Glass6493ccc2014-04-10 20:01:26 -0600375
Simon Glass8d997aa2023-10-01 19:13:12 -0600376 /* nuke the current line */
377 /* first, go home */
378 BEGINNING_OF_LINE();
Simon Glass63213912023-10-01 19:13:08 -0600379
Simon Glass8d997aa2023-10-01 19:13:12 -0600380 /* erase to end of line */
381 ERASE_TO_EOL();
382
383 /* copy new line into place and display */
384 strcpy(buf, hline);
385 cls->eol_num = strlen(buf);
386 REFRESH_TO_EOL();
Simon Glasse5509ce2023-10-01 19:13:13 -0600387 break;
Simon Glass8d997aa2023-10-01 19:13:12 -0600388 }
389 case '\t':
390 if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
391 int num2, col;
392
393 /* do not autocomplete when in the middle */
394 if (cls->num < cls->eol_num) {
395 getcmd_cbeep();
Simon Glass6493ccc2014-04-10 20:01:26 -0600396 break;
397 }
Simon Glass8d997aa2023-10-01 19:13:12 -0600398
399 buf[cls->num] = '\0';
Simon Glasse5509ce2023-10-01 19:13:13 -0600400 col = strlen(cls->prompt) + cls->eol_num;
Simon Glass8d997aa2023-10-01 19:13:12 -0600401 num2 = cls->num;
Simon Glasse5509ce2023-10-01 19:13:13 -0600402 if (cmd_auto_complete(cls->prompt, buf, &num2, &col)) {
Simon Glass8d997aa2023-10-01 19:13:12 -0600403 col = num2 - cls->num;
404 cls->num += col;
405 cls->eol_num += col;
406 }
Simon Glass6493ccc2014-04-10 20:01:26 -0600407 break;
408 }
Simon Glass8d997aa2023-10-01 19:13:12 -0600409 fallthrough;
410 default:
411 cread_add_char(ichar, cls->insert, &cls->num, &cls->eol_num,
Simon Glasse5509ce2023-10-01 19:13:13 -0600412 buf, cls->len);
Simon Glass8d997aa2023-10-01 19:13:12 -0600413 break;
414 }
Simon Glasse5509ce2023-10-01 19:13:13 -0600415
416 return -EAGAIN;
417}
418
419static int cread_line(const char *const prompt, char *buf, unsigned int *len,
420 int timeout)
421{
422 struct cli_ch_state s_cch, *cch = &s_cch;
423 struct cli_line_state s_cls, *cls = &s_cls;
424 char ichar;
425 int init_len = strlen(buf);
426 int first = 1;
427
428 cli_ch_init(cch);
429 memset(cls, '\0', sizeof(struct cli_line_state));
430 cls->insert = true;
431 cls->len = *len;
432 cls->prompt = prompt;
433 cls->buf = buf;
434
435 if (init_len)
436 cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf,
437 *len);
438
439 while (1) {
440 int ret;
441
442 /* Check for saved characters */
443 ichar = cli_ch_process(cch, 0);
444
445 if (!ichar) {
446 if (bootretry_tstc_timeout())
447 return -2; /* timed out */
448 if (first && timeout) {
449 u64 etime = endtick(timeout);
450
451 while (!tstc()) { /* while no incoming data */
452 if (get_ticks() >= etime)
453 return -2; /* timed out */
454 schedule();
455 }
456 first = 0;
457 }
458
459 ichar = getcmd_getch();
460 ichar = cli_ch_process(cch, ichar);
461 }
462
463 ret = cread_line_process_ch(cls, ichar);
464 if (ret == -EINTR)
465 return -1;
466 else if (!ret)
467 break;
Simon Glass6493ccc2014-04-10 20:01:26 -0600468 }
Simon Glassbe5c2ed2023-10-01 19:13:11 -0600469 *len = cls->eol_num;
470 buf[cls->eol_num] = '\0'; /* lose the newline */
Simon Glass6493ccc2014-04-10 20:01:26 -0600471
472 if (buf[0] && buf[0] != CREAD_HIST_CHAR)
473 cread_add_to_hist(buf);
474 hist_cur = hist_add_idx;
475
476 return 0;
477}
478
Simon Glass039f8cc2023-10-01 19:13:07 -0600479#else /* !CONFIG_CMDLINE_EDITING */
480
481static inline void hist_init(void)
482{
483}
484
485static int cread_line(const char *const prompt, char *buf, unsigned int *len,
486 int timeout)
487{
488 return 0;
489}
490
Simon Glass6493ccc2014-04-10 20:01:26 -0600491#endif /* CONFIG_CMDLINE_EDITING */
492
493/****************************************************************************/
494
Simon Glasse1bf8242014-04-10 20:01:27 -0600495int cli_readline(const char *const prompt)
Simon Glass6493ccc2014-04-10 20:01:26 -0600496{
497 /*
498 * If console_buffer isn't 0-length the user will be prompted to modify
499 * it instead of entering it from scratch as desired.
500 */
501 console_buffer[0] = '\0';
502
Simon Glasse1bf8242014-04-10 20:01:27 -0600503 return cli_readline_into_buffer(prompt, console_buffer, 0);
Simon Glass6493ccc2014-04-10 20:01:26 -0600504}
505
Simon Glass0f97e942023-10-01 19:13:05 -0600506/**
507 * cread_line_simple() - Simple (small) command-line reader
508 *
509 * This supports only basic editing, with no cursor movement
510 *
511 * @prompt: Prompt to display
512 * @p: Text buffer to edit
513 * Return: length of text buffer, or -1 if input was cannncelled (Ctrl-C)
514 */
515static int cread_line_simple(const char *const prompt, char *p)
Simon Glass6493ccc2014-04-10 20:01:26 -0600516{
Simon Glass6493ccc2014-04-10 20:01:26 -0600517 char *p_buf = p;
Simon Glass0f97e942023-10-01 19:13:05 -0600518 int n = 0; /* buffer index */
519 int plen = 0; /* prompt length */
520 int col; /* output column cnt */
521 char c;
Simon Glass6493ccc2014-04-10 20:01:26 -0600522
523 /* print prompt */
524 if (prompt) {
525 plen = strlen(prompt);
526 puts(prompt);
527 }
528 col = plen;
529
530 for (;;) {
Simon Glass0098e172014-04-10 20:01:30 -0600531 if (bootretry_tstc_timeout())
532 return -2; /* timed out */
Stefan Roese29caf932022-09-02 14:10:46 +0200533 schedule(); /* Trigger watchdog, if needed */
Simon Glass6493ccc2014-04-10 20:01:26 -0600534
Heinrich Schuchardtc670aee2020-10-07 18:11:48 +0200535 c = getchar();
Simon Glass6493ccc2014-04-10 20:01:26 -0600536
537 /*
538 * Special character handling
539 */
540 switch (c) {
541 case '\r': /* Enter */
542 case '\n':
543 *p = '\0';
544 puts("\r\n");
545 return p - p_buf;
546
547 case '\0': /* nul */
548 continue;
549
550 case 0x03: /* ^C - break */
551 p_buf[0] = '\0'; /* discard input */
552 return -1;
553
554 case 0x15: /* ^U - erase line */
555 while (col > plen) {
556 puts(erase_seq);
557 --col;
558 }
559 p = p_buf;
560 n = 0;
561 continue;
562
563 case 0x17: /* ^W - erase word */
564 p = delete_char(p_buf, p, &col, &n, plen);
565 while ((n > 0) && (*p != ' '))
566 p = delete_char(p_buf, p, &col, &n, plen);
567 continue;
568
569 case 0x08: /* ^H - backspace */
570 case 0x7F: /* DEL - backspace */
571 p = delete_char(p_buf, p, &col, &n, plen);
572 continue;
573
574 default:
Simon Glass63213912023-10-01 19:13:08 -0600575 /* Must be a normal character then */
576 if (n >= CONFIG_SYS_CBSIZE - 2) { /* Buffer full */
577 putc('\a');
578 break;
579 }
580 if (c == '\t') { /* expand TABs */
581 if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
Simon Glass6493ccc2014-04-10 20:01:26 -0600582 /*
Simon Glass63213912023-10-01 19:13:08 -0600583 * if auto-completion triggered just
Simon Glass6493ccc2014-04-10 20:01:26 -0600584 * continue
585 */
586 *p = '\0';
587 if (cmd_auto_complete(prompt,
588 console_buffer,
589 &n, &col)) {
590 p = p_buf + n; /* reset */
591 continue;
592 }
Simon Glass6493ccc2014-04-10 20:01:26 -0600593 }
Simon Glass63213912023-10-01 19:13:08 -0600594 puts(tab_seq + (col & 07));
595 col += 8 - (col & 07);
596 } else {
597 char __maybe_unused buf[2];
598
599 /*
600 * Echo input using puts() to force an LCD
601 * flush if we are using an LCD
602 */
603 ++col;
604 buf[0] = c;
605 buf[1] = '\0';
606 puts(buf);
Simon Glass6493ccc2014-04-10 20:01:26 -0600607 }
Simon Glass63213912023-10-01 19:13:08 -0600608 *p++ = c;
609 ++n;
610 break;
Simon Glass6493ccc2014-04-10 20:01:26 -0600611 }
612 }
Simon Glass0f97e942023-10-01 19:13:05 -0600613}
614
615int cli_readline_into_buffer(const char *const prompt, char *buffer,
616 int timeout)
617{
618 char *p = buffer;
Simon Glass039f8cc2023-10-01 19:13:07 -0600619 uint len = CONFIG_SYS_CBSIZE;
Simon Glass0f97e942023-10-01 19:13:05 -0600620 int rc;
621 static int initted;
622
623 /*
624 * History uses a global array which is not
625 * writable until after relocation to RAM.
626 * Revert to non-history version if still
627 * running from flash.
628 */
Simon Glass039f8cc2023-10-01 19:13:07 -0600629 if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) {
Simon Glass0f97e942023-10-01 19:13:05 -0600630 if (!initted) {
631 hist_init();
632 initted = 1;
633 }
634
635 if (prompt)
636 puts(prompt);
637
638 rc = cread_line(prompt, p, &len, timeout);
639 return rc < 0 ? rc : len;
640
641 } else {
Simon Glass0f97e942023-10-01 19:13:05 -0600642 return cread_line_simple(prompt, p);
Simon Glass6493ccc2014-04-10 20:01:26 -0600643 }
Simon Glass6493ccc2014-04-10 20:01:26 -0600644}