410
posx = grub_getstringwidth (unicode_msg, last_position);
411
posx = (GRUB_TERM_WIDTH - posx) / 2;
412
grub_gotoxy (posx, 1);
427
posx = grub_getstringwidth (unicode_msg, last_position, term);
428
posx = (grub_term_width (term) - posx) / 2;
429
grub_term_gotoxy (term, posx, 1);
414
grub_print_ucs4 (unicode_msg, last_position);
431
grub_print_ucs4 (unicode_msg, last_position, term);
415
432
grub_printf("\n\n");
416
433
grub_free (unicode_msg);
419
static int reader_nested;
437
read_lists (struct grub_env_var *var __attribute__ ((unused)),
440
read_command_list ();
443
read_terminal_list ();
444
return val ? grub_strdup (val) : NULL;
421
447
/* Read the config file CONFIG and execute the menu interface or
422
448
the command line interface if BATCH is false. */
456
480
grub_enter_normal_mode (const char *config)
458
483
grub_normal_execute (config, 0, 0);
484
grub_cmdline_run (0);
486
if (grub_normal_exit_level)
487
grub_normal_exit_level--;
461
490
/* Enter normal mode from rescue mode. */
462
491
static grub_err_t
463
grub_cmd_normal (struct grub_command *cmd,
492
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
464
493
int argc, char *argv[])
466
grub_unregister_command (cmd);
470
497
/* Guess the config filename. It is necessary to make CONFIG static,
471
498
so that it won't get broken by longjmp. */
473
500
const char *prefix;
475
502
prefix = grub_env_get ("prefix");
497
grub_cmdline_run (int nested)
523
/* Exit from normal mode to rescue mode. */
525
grub_cmd_normal_exit (struct grub_command *cmd __attribute__ ((unused)),
526
int argc __attribute__ ((unused)),
527
char *argv[] __attribute__ ((unused)))
499
grub_reader_t reader;
500
grub_err_t err = GRUB_ERR_NONE;
502
err = grub_auth_check_authentication (NULL);
507
grub_errno = GRUB_ERR_NONE;
511
reader = grub_reader_get_current ();
513
reader_nested = nested;
516
grub_reader_loop (0);
529
if (nested_level <= grub_normal_exit_level)
530
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not in normal environment");
531
grub_normal_exit_level++;
532
return GRUB_ERR_NONE;
519
535
static grub_err_t
520
grub_normal_reader_init (void)
536
grub_normal_reader_init (int nested)
522
grub_normal_init_page ();
538
struct grub_term_output *term;
525
539
const char *msg = _("Minimal BASH-like line editing is supported. For "
526
540
"the first word, TAB lists possible command completions. Anywhere "
527
541
"else TAB lists possible device or file completions. %s");
529
542
const char *msg_esc = _("ESC at any time exits.");
531
543
char *msg_formatted = grub_malloc (sizeof (char) * (grub_strlen (msg) +
532
544
grub_strlen(msg_esc) + 1));
534
grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : "");
535
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN);
546
grub_sprintf (msg_formatted, msg, nested ? msg_esc : "");
548
FOR_ACTIVE_TERM_OUTPUTS(term)
550
grub_normal_init_page (term);
551
grub_term_setcursor (term, 1);
553
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term);
538
556
grub_free (msg_formatted);
543
static char cmdline[GRUB_MAX_CMDLINE];
545
562
static grub_err_t
546
grub_normal_read_line (char **line, int cont)
563
grub_normal_read_line_real (char **line, int cont, int nested)
548
565
grub_parser_t parser = grub_parser_get_current ();
549
566
char prompt[sizeof(">") + grub_strlen (parser->name)];
551
grub_sprintf (prompt, "%s>", parser->name);
569
grub_sprintf (prompt, ">");
571
grub_sprintf (prompt, "%s>", parser->name);
556
if (grub_cmdline_get (prompt, cmdline, sizeof (cmdline), 0, 1, 1))
575
*line = grub_cmdline_get (prompt);
559
if ((reader_nested) || (cont))
562
583
return grub_errno;
566
*line = grub_strdup (cmdline);
570
static struct grub_reader grub_normal_reader =
573
.init = grub_normal_reader_init,
574
.read_line = grub_normal_read_line
591
grub_normal_read_line (char **line, int cont)
593
return grub_normal_read_line_real (line, cont, 0);
597
grub_cmdline_run (int nested)
599
grub_err_t err = GRUB_ERR_NONE;
601
err = grub_auth_check_authentication (NULL);
606
grub_errno = GRUB_ERR_NONE;
610
grub_normal_reader_init (nested);
616
if (grub_normal_exit_level)
619
/* Print an error, if any. */
621
grub_errno = GRUB_ERR_NONE;
623
grub_normal_read_line_real (&line, 0, nested);
627
grub_parser_get_current ()->parse_line (line, grub_normal_read_line);
578
633
grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)),
589
644
grub_dl_ref (mod);
591
grub_menu_viewer_register (&grub_normal_text_menu_viewer);
593
646
grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
595
grub_reader_register ("normal", &grub_normal_reader);
596
grub_reader_set_current (&grub_normal_reader);
597
648
grub_register_variable_hook ("pager", 0, grub_env_write_pager);
599
650
/* Register a command "normal" for the rescue mode. */
600
grub_register_command_prio ("normal", grub_cmd_normal,
601
0, "Enter normal mode.", 0);
651
grub_register_command ("normal", grub_cmd_normal,
652
0, "Enter normal mode.");
653
grub_register_command ("normal_exit", grub_cmd_normal_exit,
654
0, "Exit from normal mode.");
603
656
/* Reload terminal colors when these variables are written to. */
604
657
grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal);