mirror of
https://github.com/irssi/irssi.git
synced 2026-08-16 07:02:12 +02:00
/SET scrollback_save_formats + /SB REDRAW is broken currently. There's some other minor things that might need to be changed. This time it allows the same window to be visible multiple times in screen, like you could make a new split window where to scroll back and find something while still seeing the new messages at the other window, this however doesn't work yet but it should be quite easy to make it :) I've tested that pretty much everything should work with this, new lines can be added at any position and lines can be removed from any position and screen should be updated properly. Screen resizing should also work perfectly now (maybe it did previously too, not sure) and hopefully now we won't see any of those ugly strange bugs some people were having. Also this time the same code isn't written 2-3 times to do some specific thing, like scrolling has now only one view_scroll() function instead of the 3 separate functions it used to have :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1442 dbcabf3a-b0e7-0310-adc4-f8d773084564
270 lines
5.7 KiB
C
270 lines
5.7 KiB
C
/*
|
|
screen.c : irssi
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
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-1307 USA
|
|
*/
|
|
|
|
#include "module.h"
|
|
#include "signals.h"
|
|
#include "misc.h"
|
|
#include "settings.h"
|
|
|
|
#include "screen.h"
|
|
#include "gui-readline.h"
|
|
#include "mainwindows.h"
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
#include <sys/ioctl.h>
|
|
#endif
|
|
#include <signal.h>
|
|
|
|
#ifndef COLOR_PAIRS
|
|
#define COLOR_PAIRS 64
|
|
#endif
|
|
|
|
#define MIN_SCREEN_WIDTH 20
|
|
|
|
static int scrx, scry;
|
|
static int use_colors;
|
|
static int freeze_refresh;
|
|
|
|
static int init_screen_int(void);
|
|
static void deinit_screen_int(void);
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
static void sig_winch(int p)
|
|
{
|
|
#if defined (TIOCGWINSZ) && defined (HAVE_CURSES_RESIZETERM)
|
|
struct winsize ws;
|
|
|
|
/* Get new window size */
|
|
if (ioctl(0, TIOCGWINSZ, &ws) < 0)
|
|
return;
|
|
|
|
if (ws.ws_row == LINES && ws.ws_col == COLS) {
|
|
/* Same size, abort. */
|
|
return;
|
|
}
|
|
|
|
if (ws.ws_col < MIN_SCREEN_WIDTH)
|
|
ws.ws_col = MIN_SCREEN_WIDTH;
|
|
|
|
/* Resize curses terminal */
|
|
resizeterm(ws.ws_row, ws.ws_col);
|
|
#else
|
|
deinit_screen_int();
|
|
init_screen_int();
|
|
mainwindows_recreate();
|
|
#endif
|
|
|
|
mainwindows_resize(COLS, LINES);
|
|
}
|
|
#endif
|
|
|
|
/* FIXME: SIGINT != ^C .. any better way to make this work? */
|
|
void sigint_handler(int p)
|
|
{
|
|
ungetch(3);
|
|
readline();
|
|
}
|
|
|
|
static void read_signals(void)
|
|
{
|
|
const char *ignores;
|
|
|
|
ignores = settings_get_str("ignore_signals");
|
|
#ifndef WIN32
|
|
signal(SIGHUP, find_substr(ignores, "hup") ? SIG_IGN : SIG_DFL);
|
|
signal(SIGQUIT, find_substr(ignores, "quit") ? SIG_IGN : SIG_DFL);
|
|
signal(SIGTERM, find_substr(ignores, "term") ? SIG_IGN : SIG_DFL);
|
|
signal(SIGALRM, find_substr(ignores, "alrm") ? SIG_IGN : SIG_DFL);
|
|
signal(SIGUSR1, find_substr(ignores, "usr1") ? SIG_IGN : SIG_DFL);
|
|
signal(SIGUSR2, find_substr(ignores, "usr2") ? SIG_IGN : SIG_DFL);
|
|
#endif
|
|
}
|
|
|
|
static void read_settings(void)
|
|
{
|
|
int old_colors = use_colors;
|
|
|
|
use_colors = settings_get_bool("colors");
|
|
read_signals();
|
|
if (use_colors && !has_colors())
|
|
use_colors = FALSE;
|
|
|
|
if (use_colors != old_colors)
|
|
irssi_redraw();
|
|
}
|
|
|
|
static int init_curses(void)
|
|
{
|
|
char ansi_tab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
|
int num;
|
|
#ifndef WIN32
|
|
struct sigaction act;
|
|
#endif
|
|
|
|
if (!initscr())
|
|
return FALSE;
|
|
|
|
if (COLS < MIN_SCREEN_WIDTH)
|
|
COLS = MIN_SCREEN_WIDTH;
|
|
|
|
#ifndef WIN32
|
|
sigemptyset (&act.sa_mask);
|
|
act.sa_flags = 0;
|
|
act.sa_handler = sigint_handler;
|
|
sigaction(SIGINT, &act, NULL);
|
|
#endif
|
|
#ifdef SIGWINCH
|
|
act.sa_handler = sig_winch;
|
|
sigaction(SIGWINCH, &act, NULL);
|
|
#endif
|
|
cbreak(); noecho(); idlok(stdscr, 1);
|
|
#ifdef HAVE_CURSES_IDCOK
|
|
idcok(stdscr, 1);
|
|
#endif
|
|
intrflush(stdscr, FALSE); nodelay(stdscr, TRUE); keypad(stdscr, 1);
|
|
|
|
if (has_colors())
|
|
start_color();
|
|
else if (use_colors)
|
|
use_colors = FALSE;
|
|
|
|
#ifdef HAVE_NCURSES_USE_DEFAULT_COLORS
|
|
/* this lets us to use the "default" background color for colors <= 7 so
|
|
background pixmaps etc. show up right */
|
|
use_default_colors();
|
|
|
|
for (num = 1; num < COLOR_PAIRS; num++)
|
|
init_pair(num, ansi_tab[num & 7], num <= 7 ? -1 : ansi_tab[num >> 3]);
|
|
|
|
init_pair(63, 0, -1); /* hm.. not THAT good idea, but probably more
|
|
people want dark grey than white on white.. */
|
|
#else
|
|
for (num = 1; num < COLOR_PAIRS; num++)
|
|
init_pair(num, ansi_tab[num & 7], ansi_tab[num >> 3]);
|
|
init_pair(63, 0, 0);
|
|
#endif
|
|
|
|
clear();
|
|
return TRUE;
|
|
}
|
|
|
|
static int init_screen_int(void)
|
|
{
|
|
use_colors = settings_get_bool("colors");
|
|
read_signals();
|
|
|
|
scrx = scry = 0;
|
|
freeze_refresh = 0;
|
|
|
|
return init_curses();
|
|
}
|
|
|
|
static void deinit_screen_int(void)
|
|
{
|
|
endwin();
|
|
}
|
|
|
|
/* Initialize screen, detect screen length */
|
|
int init_screen(void)
|
|
{
|
|
settings_add_bool("lookandfeel", "colors", TRUE);
|
|
settings_add_str("misc", "ignore_signals", "");
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
|
|
|
return init_screen_int();
|
|
}
|
|
|
|
/* Deinitialize screen */
|
|
void deinit_screen(void)
|
|
{
|
|
deinit_screen_int();
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
|
}
|
|
|
|
void set_color(WINDOW *window, int col)
|
|
{
|
|
int attr;
|
|
|
|
if (!use_colors)
|
|
attr = (col & 0x70) ? A_REVERSE : 0;
|
|
else if (col & ATTR_COLOR8)
|
|
attr = (A_DIM | COLOR_PAIR(63));
|
|
else if ((col & 0x77) == 0)
|
|
attr = A_NORMAL;
|
|
else
|
|
attr = (COLOR_PAIR((col&7) + (col&0x70)/2));
|
|
|
|
if (col & 0x08) attr |= A_BOLD;
|
|
if (col & 0x80) attr |= A_BLINK;
|
|
|
|
if (col & ATTR_UNDERLINE) attr |= A_UNDERLINE;
|
|
if (col & ATTR_REVERSE) attr |= A_REVERSE;
|
|
|
|
wattrset(window, attr);
|
|
}
|
|
|
|
void set_bg(WINDOW *window, int col)
|
|
{
|
|
int attr;
|
|
|
|
if (!use_colors)
|
|
attr = (col & 0x70) ? A_REVERSE : 0;
|
|
else {
|
|
attr = (col == 8) ?
|
|
(A_DIM | COLOR_PAIR(63)) :
|
|
(COLOR_PAIR((col&7) + (col&0x70)/2));
|
|
}
|
|
|
|
if (col & 0x08) attr |= A_BOLD;
|
|
if (col & 0x80) attr |= A_BLINK;
|
|
|
|
wbkgdset(window, ' ' | attr);
|
|
}
|
|
|
|
void move_cursor(int y, int x)
|
|
{
|
|
scry = y;
|
|
scrx = x;
|
|
}
|
|
|
|
void screen_refresh_freeze(void)
|
|
{
|
|
freeze_refresh++;
|
|
}
|
|
|
|
void screen_refresh_thaw(void)
|
|
{
|
|
if (freeze_refresh > 0) {
|
|
freeze_refresh--;
|
|
if (freeze_refresh == 0) screen_refresh(NULL);
|
|
}
|
|
}
|
|
|
|
void screen_refresh(WINDOW *window)
|
|
{
|
|
if (window != NULL)
|
|
wnoutrefresh(window);
|
|
if (freeze_refresh == 0) {
|
|
move(scry, scrx);
|
|
wnoutrefresh(stdscr);
|
|
doupdate();
|
|
}
|
|
}
|