Example #1
0
File: menu.c Project: ryanlee/mc
static void
menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
{
    const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
    const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
    const int y = 2 + idx;
    int x = menu->start_x;

    if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
        x = menubar->widget.cols - menu->max_entry_len - 4;

    if (entry == NULL)
    {
        /* menu separator */
        tty_setcolor (MENU_ENTRY_COLOR);

        widget_move (&menubar->widget, y, x - 1);
        tty_print_alt_char (ACS_LTEE, FALSE);

        tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
                        ACS_HLINE, menu->max_entry_len + 3);

        widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
        tty_print_alt_char (ACS_RTEE, FALSE);
    }
    else
    {
        int yt, xt;

        /* menu text */
        tty_setcolor (color);
        widget_move (&menubar->widget, y, x);
        tty_print_char ((unsigned char) entry->first_letter);
        tty_getyx (&yt, &xt);
        tty_draw_hline (yt, xt, ' ', menu->max_entry_len + 2);  /* clear line */
        tty_print_string (entry->text.start);

        if (entry->text.hotkey != NULL)
        {
            tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
            tty_print_string (entry->text.hotkey);
            tty_setcolor (color);
        }

        if (entry->text.end != NULL)
            tty_print_string (entry->text.end);

        if (entry->shortcut != NULL)
        {
            widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
            tty_print_string (entry->shortcut);
        }

        /* move cursor to the start of entry text */
        widget_move (&menubar->widget, y, x + 1);
    }
}
Example #2
0
static inline void
edit_status_window (WEdit * edit)
{
    int y, x;
    int cols = edit->widget.cols;

    tty_setcolor (STATUSBAR_COLOR);

    if (cols > 5)
    {
        const char *fname = N_("NoName");
        char *full_fname = NULL;

        if (edit->filename_vpath != NULL)
        {
            full_fname = vfs_path_to_str (edit->filename_vpath);
            fname = x_basename (full_fname);
        }
#ifdef ENABLE_NLS
        else
            fname = _(fname);
#endif

        edit_move (2, 0);
        tty_printf ("[%s]", str_term_trim (fname, edit->widget.cols - 8 - 6));
        g_free (full_fname);
    }

    tty_getyx (&y, &x);
    x -= edit->widget.x;
    x += 4;
    if (x + 6 <= cols - 2 - 6)
    {
        edit_move (x, 0);
        tty_printf ("[%c%c%c%c]",
                    edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
                    edit->modified ? 'M' : '-',
                    macro_index < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O');
    }

    if (cols > 30)
    {
        edit_move (2, edit->widget.lines - 1);
        tty_printf ("%3ld %5ld/%ld %6ld/%ld",
                    edit->curs_col + edit->over_col,
                    edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte);
    }

    /*
     * If we are at the end of file, print <EOF>,
     * otherwise print the current character as is (if printable),
     * as decimal and as hex.
     */
    if (cols > 46)
    {
        edit_move (32, edit->widget.lines - 1);
        if (edit->curs1 >= edit->last_byte)
            tty_print_string ("[<EOF>       ]");
#ifdef HAVE_CHARSET
        else if (edit->utf8)
        {
            unsigned int cur_utf;
            int cw = 1;

            cur_utf = edit_get_utf (edit, edit->curs1, &cw);
            if (cw <= 0)
                cur_utf = edit_get_byte (edit, edit->curs1);
            tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf);
        }
#endif
        else
        {
            unsigned char cur_byte;

            cur_byte = edit_get_byte (edit, edit->curs1);
            tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte);
        }
    }
}