/*
* Copyright (C) 1996-2000 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*/
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mbyte.h"
#ifdef USE_IMAP
#include "imap.h"
#endif
#include <string.h>
#include <stdlib.h>
extern int Charset_is_utf8; /* FIXME: bad modularisation */
static void print_enriched_string (int attr, unsigned char *s, int do_color)
{
wchar_t wc;
size_t k;
size_t n = mutt_strlen ((char *)s);
mbstate_t mbstate;
memset (&mbstate, 0, sizeof (mbstate));
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:
if (option (OPTASCIICHARS))
addch ('`');
else if (Charset_is_utf8)
addstr ("\342\224\224"); /* WACS_LLCORNER */
else
addch (ACS_LLCORNER);
break;
case M_TREE_ULCORNER:
if (option (OPTASCIICHARS))
addch (',');
else if (Charset_is_utf8)
addstr ("\342\224\214"); /* WACS_ULCORNER */
else
addch (ACS_ULCORNER);
break;
case M_TREE_LTEE:
if (option (OPTASCIICHARS))
addch ('|');
else if (Charset_is_utf8)
addstr ("\342\224\234"); /* WACS_LTEE */
else
addch (ACS_LTEE);
break;
case M_TREE_HLINE:
if (option (OPTASCIICHARS))
addch ('-');
else if (Charset_is_utf8)
addstr ("\342\224\200"); /* WACS_HLINE */
else
addch (ACS_HLINE);
break;
case M_TREE_VLINE:
if (option (OPTASCIICHARS))
addch ('|');
else if (Charset_is_utf8)
addstr ("\342\224\202"); /* WACS_VLINE */
else
addch (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++, n--;
}
if (do_color) attrset(attr);
}
else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0)
{
addnstr ((char *)s, k);
s += k, n-= k;
}
else
break;
}
}
static void menu_make_entry (char *s, int l, MUTTMENU *menu, int i)
{
if (menu->dialog)
{
strncpy (s, menu->dialog[i], l);
menu->current = -1; /* hide menubar */
}
else
menu->make_entry (s, l, menu, i);
}
void menu_pad_string (char *s, size_t l)
{
size_t n = mutt_strlen (s);
int shift = option (OPTARROWCURSOR) ? 3 : 0;
l--; /* save room for the terminal \0 */
if (l > COLS - shift)
l = COLS - shift;
/* Let's just pad the string anyway ... */
mutt_format_string (s, INT_MAX, l, l, 0, ' ', s, n);
return;
#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