Example #1
0
File: main.c Project: BrEacK/mc
int
load_prompt (int fd, void *unused)
{
    (void) fd;
    (void) unused;

    do_load_prompt ();
    return 0;
}
Example #2
0
File: command.c Project: V07D/mc
static cb_ret_t
enter (WInput * lc_cmdline)
{
    char *cmd = lc_cmdline->buffer;

    if (!command_prompt)
        return MSG_HANDLED;

    /* Any initial whitespace should be removed at this point */
    while (*cmd == ' ' || *cmd == '\t' || *cmd == '\n')
        cmd++;

    if (!*cmd)
        return MSG_HANDLED;

    if (strncmp (cmd, "cd ", 3) == 0 || strcmp (cmd, "cd") == 0)
    {
        do_cd_command (cmd);
        input_clean (lc_cmdline);
        return MSG_HANDLED;
    }
    else if (strcmp (cmd, "exit") == 0)
    {
        input_assign_text (lc_cmdline, "");
        if (!quiet_quit_cmd ())
            return MSG_NOT_HANDLED;
    }
    else
    {
        GString *command;
        size_t i;

        if (!vfs_current_is_local ())
        {
            message (D_ERROR, MSG_ERROR, _("Cannot execute commands on non-local filesystems"));
            return MSG_NOT_HANDLED;
        }
#ifdef ENABLE_SUBSHELL
        /* Check this early before we clean command line
         * (will be checked again by shell_execute) */
        if (mc_global.tty.use_subshell && subshell_state != INACTIVE)
        {
            message (D_ERROR, MSG_ERROR, _("The shell is already running a command"));
            return MSG_NOT_HANDLED;
        }
#endif
        command = g_string_sized_new (32);

        for (i = 0; cmd[i] != '\0'; i++)
        {
            if (cmd[i] != '%')
                g_string_append_c (command, cmd[i]);
            else
            {
                char *s;

                s = expand_format (NULL, cmd[++i], TRUE);
                g_string_append (command, s);
                g_free (s);
            }
        }

        input_clean (lc_cmdline);
        shell_execute (command->str, 0);
        g_string_free (command, TRUE);

#ifdef ENABLE_SUBSHELL
        if ((quit & SUBSHELL_EXIT) != 0)
        {
            if (quiet_quit_cmd ())
                return MSG_HANDLED;

            quit = 0;
            /* restart subshell */
            if (mc_global.tty.use_subshell)
                init_subshell ();
        }

        if (mc_global.tty.use_subshell)
            do_load_prompt ();
#endif
    }
    return MSG_HANDLED;
}
Example #3
0
File: layout.c Project: m32/mc
void
setup_panels (void)
{
    int start_y;

    if (mc_global.tty.console_flag != '\0')
    {
        int minimum;

        if (output_lines < 0)
            output_lines = 0;
        height =
            LINES - mc_global.keybar_visible - (command_prompt ? 1 : 0) - menubar_visible -
            output_lines - mc_global.message_visible;
        minimum = MINHEIGHT * (1 + panels_layout.horizontal_split);
        if (height < minimum)
        {
            output_lines -= minimum - height;
            height = minimum;
        }
    }
    else
    {
        height =
            LINES - menubar_visible - (command_prompt ? 1 : 0) - mc_global.keybar_visible -
            mc_global.message_visible;
    }

    check_split (&panels_layout);
    start_y = menubar_visible;

    /* The column computing is deferred until panel_do_cols */
    if (panels_layout.horizontal_split)
    {
        widget_set_size (panels[0].widget, start_y, 0, panels_layout.top_panel_size, 0);
        widget_set_size (panels[1].widget, start_y + panels_layout.top_panel_size, 0,
                         height - panels_layout.top_panel_size, 0);
    }
    else
    {
        widget_set_size (panels[0].widget, start_y, 0, height, 0);
        widget_set_size (panels[1].widget, start_y, panels_layout.left_panel_size, height, 0);
    }

    panel_do_cols (0);
    panel_do_cols (1);

    widget_set_size (WIDGET (the_menubar), 0, 0, 1, COLS);

    if (command_prompt)
    {
#ifdef ENABLE_SUBSHELL
        if (!mc_global.tty.use_subshell || !do_load_prompt ())
#endif
            setup_cmdline ();
    }
    else
    {
        widget_set_size (WIDGET (cmdline), 0, 0, 0, 0);
        widget_set_size (WIDGET (the_prompt), LINES, COLS, 0, 0);
    }

    widget_set_size (WIDGET (the_bar), LINES - 1, 0, mc_global.keybar_visible, COLS);
    buttonbar_set_visible (the_bar, mc_global.keybar_visible);

    /* Output window */
    if (mc_global.tty.console_flag != '\0' && output_lines)
    {
        output_start_y = LINES - (command_prompt ? 1 : 0) - mc_global.keybar_visible - output_lines;
        show_console_contents (output_start_y,
                               LINES - output_lines - mc_global.keybar_visible - 1,
                               LINES - mc_global.keybar_visible - 1);
    }

    if (mc_global.message_visible)
        widget_set_size (WIDGET (the_hint), height + start_y, 0, 1, COLS);
    else
        widget_set_size (WIDGET (the_hint), 0, 0, 0, 0);

    update_xterm_title_path ();
}
Example #4
0
File: execute.c Project: LubkaB/mc
void
toggle_panels (void)
{
#ifdef ENABLE_SUBSHELL
    vfs_path_t *new_dir_vpath = NULL;
#endif /* ENABLE_SUBSHELL */

    SIG_ATOMIC_VOLATILE_T was_sigwinch = 0;

    channels_down ();
    disable_mouse ();
    disable_bracketed_paste ();
    if (clear_before_exec)
        clr_scr ();
    if (mc_global.tty.alternate_plus_minus)
        numeric_keypad_mode ();
#ifndef HAVE_SLANG
    /* With slang we don't want any of this, since there
     * is no raw_mode supported
     */
    tty_reset_shell_mode ();
#endif /* !HAVE_SLANG */
    tty_noecho ();
    tty_keypad (FALSE);
    tty_reset_screen ();
    do_exit_ca_mode ();
    tty_raw_mode ();
    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_RESTORE);

#ifdef ENABLE_SUBSHELL
    if (mc_global.tty.use_subshell)
    {
        vfs_path_t **new_dir_p;

        new_dir_p = vfs_current_is_local ()? &new_dir_vpath : NULL;
        invoke_subshell (NULL, VISIBLY, new_dir_p);
    }
    else
#endif /* ENABLE_SUBSHELL */
    {
        if (output_starts_shell)
        {
            fprintf (stderr, _("Type 'exit' to return to the Midnight Commander"));
            fprintf (stderr, "\n\r\n\r");

            my_system (EXECUTE_INTERNAL, mc_global.tty.shell, NULL);
        }
        else
            get_key_code (0);
    }

    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_SAVE);

    do_enter_ca_mode ();

    tty_reset_prog_mode ();
    tty_keypad (TRUE);

    /* Prevent screen flash when user did 'exit' or 'logout' within
       subshell */
    if ((quit & SUBSHELL_EXIT) != 0)
    {
        /* User did 'exit' or 'logout': quit MC */
        if (quiet_quit_cmd ())
            return;

        quit = 0;
#ifdef ENABLE_SUBSHELL
        /* restart subshell */
        if (mc_global.tty.use_subshell)
            init_subshell ();
#endif /* ENABLE_SUBSHELL */
    }

    enable_mouse ();
    enable_bracketed_paste ();
    channels_up ();
    if (mc_global.tty.alternate_plus_minus)
        application_keypad_mode ();

    /* HACK:
     * Save sigwinch flag that will be reset in mc_refresh() called via update_panels().
     * There is some problem with screen redraw in ncurses-based mc in this situation.
     */
    was_sigwinch = mc_global.tty.winch_flag;
    mc_global.tty.winch_flag = 0;

#ifdef ENABLE_SUBSHELL
    if (mc_global.tty.use_subshell)
    {
        do_load_prompt ();
        if (new_dir_vpath != NULL)
            do_possible_cd (new_dir_vpath);
        if (mc_global.tty.console_flag != '\0' && output_lines)
            show_console_contents (output_start_y,
                                   LINES - mc_global.keybar_visible - output_lines -
                                   1, LINES - mc_global.keybar_visible - 1);
    }

    vfs_path_free (new_dir_vpath);
#endif /* ENABLE_SUBSHELL */

    if (mc_global.mc_run_mode == MC_RUN_FULL)
    {
        update_panels (UP_OPTIMIZE, UP_KEEPSEL);
        update_xterm_title_path ();
    }

    if (was_sigwinch != 0 || mc_global.tty.winch_flag != 0)
        dialog_change_screen_size ();
    else
        repaint_screen ();
}