/*
* Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include <string.h>
#include <stdlib.h>
static void print_enriched_string (int attr, unsigned char *s, int do_color)
{
while (*s)
{
if (*s < M_TREE_MAX)
{
if (do_color)
SETCOLOR (MT_COLOR_TREE);
while (*s && *s < M_TREE_MAX)
{
switch (*s)
{
case M_TREE_LLCORNER:
addch (option (OPTASCIICHARS) ? '`' : ACS_LLCORNER);
break;
case M_TREE_ULCORNER:
addch (option (OPTASCIICHARS) ? ',' : ACS_ULCORNER);
break;
case M_TREE_LTEE:
addch (option (OPTASCIICHARS) ? '|' : ACS_LTEE);
break;
case M_TREE_HLINE:
addch (option (OPTASCIICHARS) ? '-' : ACS_HLINE);
break;
case M_TREE_VLINE:
addch (option (OPTASCIICHARS) ? '|' : ACS_VLINE);
break;
case M_TREE_SPACE:
addch (' ');
break;
case M_TREE_RARROW:
addch ('>');
break;
case M_TREE_STAR:
addch ('*'); /* fake thread indicator */
break;
case M_TREE_HIDDEN:
addch ('&');
break;
}
s++;
}
if (do_color) attrset(attr);
}
else
{
addch (*s);
s++;
}
}
}
void menu_pad_string (char *s, size_t l)
{
#if !defined(HAVE_BKGDSET) && !defined (USE_SLANG_CURSES)
int n = strlen (s);
#endif
int shift = option (OPTARROWCURSOR) ? 3 : 0;
l--; /* save room for the terminal \0 */
if (l > COLS - shift)
l = COLS - shift;
#if !defined (HAVE_BKGDSET) && !defined (USE_SLANG_CURSES)
/* we have to pad the string with blanks to the end of line */
if (n < l)
{
while (n < l)
s[n++] = ' ';
s[n] = 0;
}
else
#endif
s[l] = 0;
}
void menu_redraw_full (MUTTMENU *menu)
{
SETCOLOR (MT_COLOR_NORMAL);
/* clear() doesn't optimize screen redraws */
move (0, 0);
clrtobot ();
if (option (OPTHELP))
{
SETCOLOR (MT_COLOR_STATUS);
mvprintw (option (OPTSTATUSONTOP) ? LINES-2 : 0, 0, "%-*.*s", COLS, COLS, menu->help);
SETCOLOR (MT_COLOR_NORMAL);
menu->offset = 1;
menu->pagelen = LINES - 3;
}
else
{
menu->offset = option (OPTSTATUSONTOP) ? 1 : 0;
menu->pagelen = LINES - 2;
}
mutt_show_error ();
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
}
void menu_redraw_index (MUTTMENU *menu)
{
char buf[STRING];
int i;
for (i = menu->top; i < menu->top + menu->pagelen; i++)
{
if (i < menu->max)
{
menu->make_entry (buf, sizeof (buf), menu, i);
menu_pad_string (buf, sizeof (buf));
if (option (OPTARROWCURSOR))
{
attrset (menu->color (i));
CLEARLINE (i - menu->top + menu->offset);
if (i == menu->current)
{
SETCOLOR (MT_COLOR_INDICATOR);
addstr ("->");
attrset (menu->color (i));
addch (' ');
}
else
move (i - menu->top + menu->offset, 3);
print_enriched_string (menu->color(i), (unsigned char *) buf, 1);
SETCOLOR (MT_COLOR_NORMAL);
}
else
{
if (i == menu->current)
{
SETCOLOR (MT_COLOR_INDICATOR);
BKGDSET (MT_COLOR_INDICATOR);
}
else
attrset (menu->color (i));
CLEARLINE (i - menu->top + menu->offset);
print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (MT_COLOR_NORMAL);
}
}
else
CLEARLINE (i - menu->top + menu->offset);
}
menu->redraw =