/*
* Copyright (C) 1996-2002,2010,2012-2013 Michael R. Elkins <me@mutt.org>
* Copyright (C) 2004 g10 Code GmbH
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "mutt.h"
#include "mutt_menu.h"
#include "mutt_curses.h"
#include "pager.h"
#include "mbyte.h"
#include <termios.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#include <time.h>
#ifdef HAVE_LANGINFO_YESEXPR
#include <langinfo.h>
#endif
/* not possible to unget more than one char under some curses libs, and it
* is impossible to unget function keys in SLang, so roll our own input
* buffering routines.
*/
/* These are used for macros and exec/push commands.
* They can be temporarily ignored by setting OPTIGNOREMACROEVENTS
*/
static size_t MacroBufferCount = 0;
static size_t MacroBufferLen = 0;
static event_t *MacroEvents;
/* These are used in all other "normal" situations, and are not
* ignored when setting OPTIGNOREMACROEVENTS
*/
static size_t UngetCount = 0;
static size_t UngetLen = 0;
static event_t *UngetKeyEvents;
mutt_window_t *MuttHelpWindow = NULL;
mutt_window_t *MuttIndexWindow = NULL;
mutt_window_t *MuttStatusWindow = NULL;
mutt_window_t *MuttMessageWindow = NULL;
#ifdef USE_SIDEBAR
mutt_window_t *MuttSidebarWindow = NULL;
#endif
void mutt_refresh (void)
{
/* don't refresh when we are waiting for a child. */
if (option (OPTKEEPQUIET))
return;
/* don't refresh in the middle of macros unless necessary */
if (UngetCount && !option (OPTFORCEREFRESH))
return;
/* else */
refresh ();
}
/* Make sure that the next refresh does a full refresh. This could be
optimized by not doing it at all if DISPLAY is set as this might
indicate that a GUI based pinentry was used. Having an option to
customize this is of course the Mutt way. */
void mutt_need_hard_redraw (void)
{
keypad (stdscr, TRUE);
clearok (stdscr, TRUE);
set_option (OPTNEEDREDRAW);
}
event_t mutt_getch (void)
{
int ch;
event_t err = {-1, OP_NULL }, ret;
event_t timeout = {-2, OP_NULL};
if (UngetCount)
return (UngetKeyEvents[--UngetCount]);
if (!option(OPTIGNOREMACROEVENTS) && MacroBufferCount)
return (MacroEvents[--MacroBufferCount]);
SigInt = 0;
mutt_allow_interrupt (1);
#ifdef KEY_RESIZE
/* ncurses 4.2 sends this when the screen is resized */
ch = KEY_RESIZE;
while (ch == KEY_RESIZE)
#endif /* KEY_RESIZE */
ch = getch ();
mutt_allow_interrupt (0);
if (SigInt)
{
mutt_query_exit ();
return err;
}
if(ch == ERR)
{
/* either timeout or the terminal has been lost */
if (!isatty (0))
{
endwin ();
exit (1);
}
return timeout;
}
if ((ch & 0x80) && option (OPTMETAKEY))
{
/* send ALT-x as ESC-x */
ch &=