1
0
mirror of https://github.com/irssi/irssi.git synced 2024-10-27 05:20:20 -04:00

Replaced all direct curses calls with screen_xx() wrappers. This should

enable us to optionally use termcap directly.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1535 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-06-01 21:49:07 +00:00 committed by cras
parent 6f5c1117de
commit 05777636a7
13 changed files with 238 additions and 132 deletions

View File

@ -31,16 +31,16 @@ static char *prompt;
static void entry_screenpos(void)
{
if (pos-scrstart < COLS-2-promptlen && pos-scrstart > 0) {
if (pos-scrstart < screen_width-2-promptlen && pos-scrstart > 0) {
scrpos = pos-scrstart;
return;
}
if (pos < COLS-1-promptlen) {
if (pos < screen_width-1-promptlen) {
scrstart = 0;
scrpos = pos;
} else {
scrpos = (COLS-promptlen)*2/3;
scrpos = (screen_width-promptlen)*2/3;
scrstart = pos-scrpos;
}
}
@ -50,26 +50,26 @@ static void entry_update(void)
char *p;
int n, len;
len = entry->len-scrstart > COLS-1-promptlen ?
COLS-1-promptlen : entry->len-scrstart;
len = entry->len-scrstart > screen_width-1-promptlen ?
screen_width-1-promptlen : entry->len-scrstart;
set_color(stdscr, 0);
move(LINES-1, promptlen);
screen_set_color(screen_root, 0);
screen_move(screen_root, promptlen, screen_height-1);
for (p = entry->str+scrstart, n = 0; n < len; n++, p++) {
if (prompt_hidden)
addch(' ');
screen_addch(screen_root, ' ');
else if ((unsigned char) *p >= 32)
addch((unsigned char) *p);
screen_addch(screen_root, (unsigned char) *p);
else {
set_color(stdscr, ATTR_REVERSE);
addch(*p+'A'-1);
set_color(stdscr, 0);
screen_set_color(screen_root, ATTR_REVERSE);
screen_addch(screen_root, *p+'A'-1);
screen_set_color(screen_root, 0);
}
}
clrtoeol();
screen_clrtoeol(screen_root);
move_cursor(LINES-1, scrpos+promptlen);
screen_move_cursor(scrpos+promptlen, screen_height-1);
screen_refresh(NULL);
}
@ -84,7 +84,7 @@ void gui_entry_set_prompt(const char *str)
}
if (prompt != NULL)
gui_printtext(0, LINES-1, prompt);
gui_printtext(0, screen_height-1, prompt);
entry_screenpos();
entry_update();

View File

@ -165,9 +165,9 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
if (window == NULL) {
g_return_if_fail(next_xpos != -1);
wmove(stdscr, next_ypos, next_xpos);
set_color(stdscr, fg | (bg << 4));
addstr(str);
screen_move(screen_root, next_xpos, next_ypos);
screen_set_color(screen_root, fg | (bg << 4));
screen_addstr(screen_root, str);
next_xpos += strlen(str);
return;
}
@ -258,7 +258,6 @@ void gui_printtext_init(void)
signal_add("print text finished", (SIGNAL_FUNC) sig_printtext_finished);
signal_add("print format", (SIGNAL_FUNC) sig_print_format);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
signal_add("beep", (SIGNAL_FUNC) beep);
read_settings();
}
@ -271,5 +270,4 @@ void gui_printtext_deinit(void)
signal_remove("print text finished", (SIGNAL_FUNC) sig_printtext_finished);
signal_remove("print format", (SIGNAL_FUNC) sig_print_format);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
signal_remove("beep", (SIGNAL_FUNC) beep);
}

View File

@ -313,12 +313,9 @@ void readline(void)
int key;
for (;;) {
key = getch();
if (key == ERR
#ifdef KEY_RESIZE
|| key == KEY_RESIZE
#endif
) break;
key = screen_getch();
if (key == -1)
break;
handle_key(key);
}

View File

@ -254,7 +254,7 @@ static void signal_window_changed(WINDOW_REC *window)
active_mainwin->active = window;
textbuffer_view_set_window(WINDOW_GUI(window)->view,
parent->curses_win);
parent->screen_win);
window_update_prompt();
}

View File

@ -89,8 +89,8 @@ static void sig_exit(void)
/* redraw irssi's screen.. */
void irssi_redraw(void)
{
clear();
refresh();
screen_clear();
screen_refresh(NULL);
/* windows */
mainwindows_redraw();

View File

@ -37,7 +37,11 @@ GSList *mainwindows;
MAIN_WINDOW_REC *active_mainwin;
static int reserved_up, reserved_down;
static int screen_width, screen_height;
static int old_screen_width, old_screen_height;
#define mainwindow_create_screen(window) \
screen_window_create(0, (window)->first_line, \
(window)->width, (window)->height)
static MAIN_WINDOW_REC *find_window_with_room(void)
{
@ -59,15 +63,6 @@ static MAIN_WINDOW_REC *find_window_with_room(void)
return biggest_rec;
}
#ifdef USE_CURSES_WINDOWS
static void create_curses_window(MAIN_WINDOW_REC *window)
{
window->curses_win = newwin(window->height, window->width,
window->first_line, 0);
idlok(window->curses_win, 1);
}
#endif
static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff)
{
GSList *tmp;
@ -77,18 +72,8 @@ static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff)
window->width += xdiff;
window->height = window->last_line-window->first_line+1;
#ifdef USE_CURSES_WINDOWS
#ifdef HAVE_CURSES_WRESIZE
wresize(window->curses_win, window->height, window->width);
mvwin(window->curses_win, window->first_line, 0);
#else
delwin(window->curses_win);
create_curses_window(window);
textbuffer_view_set_window(WINDOW_GUI(window->active)->view,
window->curses_win);
#endif
#endif
screen_window_move(window->screen_win, 0, window->first_line,
window->width, window->height);
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
WINDOW_REC *rec = tmp->data;
@ -99,7 +84,7 @@ static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff)
}
textbuffer_view_set_window(WINDOW_GUI(window->active)->view,
window->curses_win);
window->screen_win);
signal_emit("mainwindow resized", 1, window);
}
@ -110,11 +95,9 @@ void mainwindows_recreate(void)
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data;
#ifdef USE_CURSES_WINDOWS
create_curses_window(rec);
#endif
rec->screen_win = mainwindow_create_screen(rec);
textbuffer_view_set_window(WINDOW_GUI(rec->active)->view,
rec->curses_win);
rec->screen_win);
}
}
@ -151,10 +134,8 @@ MAIN_WINDOW_REC *mainwindow_create(void)
mainwindow_resize(parent, 0, -space-1);
}
#ifdef USE_CURSES_WINDOWS
rec->curses_win = newwin(rec->height, rec->width, rec->first_line, 0);
refresh();
#endif
rec->screen_win = mainwindow_create_screen(rec);
screen_refresh(NULL);
mainwindows = g_slist_append(mainwindows, rec);
signal_emit("mainwindow created", 1, rec);
@ -240,9 +221,7 @@ void mainwindow_destroy(MAIN_WINDOW_REC *window)
mainwindows = g_slist_remove(mainwindows, window);
signal_emit("mainwindow destroyed", 1, window);
#ifdef USE_CURSES_WINDOWS
delwin(window->curses_win);
#endif
screen_window_destroy(window->screen_win);
if (!quitting && mainwindows != NULL) {
gui_windows_remove_parent(window);
@ -419,10 +398,10 @@ void mainwindows_resize(int width, int height)
{
int xdiff, ydiff;
xdiff = width-screen_width;
ydiff = height-screen_height;
screen_width = width;
screen_height = height;
xdiff = width-old_screen_width;
ydiff = height-old_screen_height;
old_screen_width = width;
old_screen_height = height;
screen_refresh_freeze();
if (ydiff < 0)
@ -431,9 +410,9 @@ void mainwindows_resize(int width, int height)
mainwindows_resize_bigger(xdiff, ydiff);
else if (xdiff != 0)
mainwindows_resize_horiz(xdiff);
screen_refresh_thaw();
irssi_redraw();
screen_refresh_thaw();
}
int mainwindows_reserve_lines(int count, int up)
@ -871,8 +850,8 @@ static void cmd_window_stick(const char *data)
void mainwindows_init(void)
{
screen_width = COLS;
screen_height = LINES;
old_screen_width = screen_width;
old_screen_height = screen_height;
mainwindows = NULL;
active_mainwin = NULL;

View File

@ -10,11 +10,8 @@ typedef struct {
WINDOW_REC *active;
GSList *sticky_windows; /* list of windows allowed to show only in this mainwindow */
#ifdef USE_CURSES_WINDOWS
WINDOW *curses_win;
#else
#error disable-curses-windows is currently broken /* FIXME */
#endif
SCREEN_WINDOW *screen_win;
int first_line, last_line, width, height;
int statusbar_lines;
void *statusbar;

View File

@ -32,12 +32,25 @@
#endif
#include <signal.h>
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
# include <ncurses.h>
#else
# include <curses.h>
#endif
#ifndef COLOR_PAIRS
#define COLOR_PAIRS 64
#endif
#define MIN_SCREEN_WIDTH 20
struct _SCREEN_WINDOW {
WINDOW *win;
};
SCREEN_WINDOW *screen_root;
int screen_width, screen_height;
static int scrx, scry;
static int use_colors;
static int freeze_refresh;
@ -66,6 +79,9 @@ static void sig_winch(int p)
/* Resize curses terminal */
resizeterm(ws.ws_row, ws.ws_col);
screen_width = COLS;
screen_height = LINES;
#else
deinit_screen_int();
init_screen_int();
@ -141,36 +157,103 @@ static int init_curses(void)
static int init_screen_int(void)
{
int ret;
ret = init_curses();
if (!ret) return 0;
use_colors = settings_get_bool("colors");
scrx = scry = 0;
freeze_refresh = 0;
return init_curses();
screen_root = g_new0(SCREEN_WINDOW, 1);
screen_root->win = stdscr;
screen_width = COLS;
screen_height = LINES;
return ret;
}
static void deinit_screen_int(void)
{
endwin();
g_free_and_null(screen_root);
}
/* Initialize screen, detect screen length */
int init_screen(void)
{
settings_add_bool("lookandfeel", "colors", TRUE);
signal_add("beep", (SIGNAL_FUNC) beep);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
return init_screen_int();
return init_screen_int();
}
/* Deinitialize screen */
void deinit_screen(void)
{
deinit_screen_int();
deinit_screen_int();
signal_remove("beep", (SIGNAL_FUNC) beep);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
}
void set_color(WINDOW *window, int col)
int screen_has_colors(void)
{
return has_colors();
}
void screen_clear(void)
{
clear();
}
SCREEN_WINDOW *screen_window_create(int x, int y, int width, int height)
{
SCREEN_WINDOW *scrwin;
scrwin = g_new0(SCREEN_WINDOW, 1);
scrwin->win = newwin(height, width, y, x);
idlok(scrwin->win, 1);
return scrwin;
}
void screen_window_destroy(SCREEN_WINDOW *window)
{
delwin(window->win);
g_free(window);
}
void screen_window_clear(SCREEN_WINDOW *window)
{
werase(window->win);
}
void screen_window_move(SCREEN_WINDOW *window, int x, int y,
int width, int height)
{
#ifdef HAVE_CURSES_WRESIZE
wresize(window->win, height, width);
mvwin(window->win, y, x);
#else
delwin(window->win);
window->win = newwin(height, width, y, x);
idlok(window->win, 1);
#endif
}
void screen_window_scroll(SCREEN_WINDOW *window, int count)
{
scrollok(window->win, TRUE);
wscrl(window->win, count);
scrollok(window->win, FALSE);
}
void screen_set_color(SCREEN_WINDOW *window, int col)
{
int attr;
@ -189,10 +272,10 @@ void set_color(WINDOW *window, int col)
if (col & ATTR_UNDERLINE) attr |= A_UNDERLINE;
if (col & ATTR_REVERSE) attr |= A_REVERSE;
wattrset(window, attr);
wattrset(window->win, attr);
}
void set_bg(WINDOW *window, int col)
void screen_set_bg(SCREEN_WINDOW *window, int col)
{
int attr;
@ -207,10 +290,30 @@ void set_bg(WINDOW *window, int col)
if (col & 0x08) attr |= A_BOLD;
if (col & 0x80) attr |= A_BLINK;
wbkgdset(window, ' ' | attr);
wbkgdset(window->win, ' ' | attr);
}
void move_cursor(int y, int x)
void screen_move(SCREEN_WINDOW *window, int x, int y)
{
wmove(window->win, y, x);
}
void screen_addch(SCREEN_WINDOW *window, int chr)
{
waddch(window->win, chr);
}
void screen_addstr(SCREEN_WINDOW *window, char *str)
{
waddstr(window->win, str);
}
void screen_clrtoeol(SCREEN_WINDOW *window)
{
wclrtoeol(window->win);
}
void screen_move_cursor(int x, int y)
{
scry = y;
scrx = x;
@ -229,13 +332,30 @@ void screen_refresh_thaw(void)
}
}
void screen_refresh(WINDOW *window)
void screen_refresh(SCREEN_WINDOW *window)
{
if (window != NULL)
wnoutrefresh(window);
wnoutrefresh(window->win);
if (freeze_refresh == 0) {
move(scry, scrx);
wnoutrefresh(stdscr);
doupdate();
}
}
int screen_getch(void)
{
int key;
key = getch();
if (key == ERR)
return -1;
#ifdef KEY_RESIZE
if (key == KEY_RESIZE)
return -1;
#endif
return key;
}

View File

@ -1,16 +1,7 @@
#ifndef __SCREEN_H
#define __SCREEN_H
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
# include <ncurses.h>
#else
# include <curses.h>
#endif
/* Some curseses include term.h, which #defines some things breaking irssi */
#undef lines
#undef key_backspace
#undef tab
typedef struct _SCREEN_WINDOW SCREEN_WINDOW;
#define ATTR_UNDERLINE 0x100
#define ATTR_COLOR8 0x200
@ -25,22 +16,43 @@
*/
#ifdef WANT_BIG5
/* XXX I didn't check the encoding range of big5+. This is standard big5. */
#define is_big5_los(lo) (((char)0x40<=lo)&&(lo<=(char)0x7E)) /* standard */
#define is_big5_lox(lo) (((char)0x80<=lo)&&(lo<=(char)0xFE)) /* extended */
#define is_big5_hi(hi) (((char)0x81<=hi)&&(hi<=(char)0xFE))
#define is_big5(hi,lo) is_big5_hi(hi) && (is_big5_los(lo) || is_big5_lox(lo))
# define is_big5_los(lo) (((char)0x40<=lo)&&(lo<=(char)0x7E)) /* standard */
# define is_big5_lox(lo) (((char)0x80<=lo)&&(lo<=(char)0xFE)) /* extended */
# define is_big5_hi(hi) (((char)0x81<=hi)&&(hi<=(char)0xFE))
# define is_big5(hi,lo) is_big5_hi(hi) && (is_big5_los(lo) || is_big5_lox(lo))
#endif
extern SCREEN_WINDOW *screen_root;
extern int screen_width, screen_height;
int init_screen(void); /* Initialize screen, detect screen length */
void deinit_screen(void); /* Deinitialize screen */
void set_color(WINDOW *window, int col);
void set_bg(WINDOW *window, int col);
int screen_has_colors(void);
void screen_clear(void);
void move_cursor(int y, int x);
SCREEN_WINDOW *screen_window_create(int x, int y, int width, int height);
void screen_window_destroy(SCREEN_WINDOW *window);
void screen_window_clear(SCREEN_WINDOW *window);
void screen_window_move(SCREEN_WINDOW *window, int x, int y,
int width, int height);
void screen_window_scroll(SCREEN_WINDOW *window, int count);
void screen_set_color(SCREEN_WINDOW *window, int col);
void screen_set_bg(SCREEN_WINDOW *window, int col);
void screen_move(SCREEN_WINDOW *window, int x, int y);
void screen_addch(SCREEN_WINDOW *window, int chr);
void screen_addstr(SCREEN_WINDOW *window, char *str);
void screen_clrtoeol(SCREEN_WINDOW *window);
void screen_move_cursor(int x, int y);
void screen_refresh_freeze(void);
void screen_refresh_thaw(void);
void screen_refresh(WINDOW *window);
void screen_refresh(SCREEN_WINDOW *window);
int screen_getch(void);
#endif

View File

@ -632,7 +632,7 @@ static void sig_main_statusbar_changed(WINDOW_REC *window)
static void read_settings(void)
{
use_colors = settings_get_bool("colors") && has_colors();
use_colors = settings_get_bool("colors") && screen_has_colors();
if (settings_get_bool("topicbar"))
topicbar_create();
else

View File

@ -141,7 +141,7 @@ static void statusbar_redraw_line(STATUSBAR_REC *bar)
if (bar->window != NULL)
active_win = bar->window->active;
statusbar_get_sizes(bar, COLS-2);
statusbar_get_sizes(bar, screen_width-2);
xpos = 1;
for (tmp = bar->items; tmp != NULL; tmp = tmp->next) {
@ -154,7 +154,7 @@ static void statusbar_redraw_line(STATUSBAR_REC *bar)
}
}
rxpos = COLS-1;
rxpos = screen_width-1;
for (tmp = bar->items; tmp != NULL; tmp = tmp->next) {
SBAR_ITEM_REC *rec = tmp->data;
@ -196,9 +196,10 @@ void statusbar_redraw(STATUSBAR_REC *bar)
return;
}
set_bg(stdscr, backs[bar->color] << 4);
move(bar->ypos, 0); clrtoeol();
set_bg(stdscr, 0);
screen_set_bg(screen_root, backs[bar->color] << 4);
screen_move(screen_root, 0, bar->ypos);
screen_clrtoeol(screen_root);
screen_set_bg(screen_root, 0);
statusbar_redraw_line(bar);
@ -247,7 +248,8 @@ STATUSBAR_REC *statusbar_create(int pos, int ypos)
rec->line = pos == STATUSBAR_POS_MIDDLE ? ypos :
mainwindows_reserve_lines(1, pos == STATUSBAR_POS_UP);
rec->ypos = pos == STATUSBAR_POS_MIDDLE ? ypos :
pos == STATUSBAR_POS_UP ? rec->line : LINES-1-rec->line;
pos == STATUSBAR_POS_UP ? rec->line :
screen_height-1-rec->line;
/* get background color from sb_background abstract */
str = theme_format_expand(current_theme, "{sb_background}");
@ -268,9 +270,10 @@ STATUSBAR_REC *statusbar_create(int pos, int ypos)
rec->line -= sbar_lowest;
}
set_bg(stdscr, backs[rec->color] << 4);
move(rec->ypos, 0); clrtoeol();
set_bg(stdscr, 0);
screen_set_bg(screen_root, backs[rec->color] << 4);
screen_move(screen_root, 0, rec->ypos);
screen_clrtoeol(screen_root);
screen_set_bg(screen_root, 0);
return rec;
}

View File

@ -254,12 +254,12 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
color = cache->lines[subline-1].color;
}
set_color(view->window, 0);
wmove(view->window, ypos, 0);
wclrtoeol(view->window);
screen_set_color(view->window, 0);
screen_move(view->window, 0, ypos);
screen_clrtoeol(view->window);
wmove(view->window, ypos, xpos);
set_color(view->window, color);
screen_move(view->window, xpos, ypos);
screen_set_color(view->window, color);
/* get the beginning of the next subline */
text_newline = subline == cache->count-1 ? NULL :
@ -298,18 +298,18 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
color |= 0x80;
break;
}
set_color(view->window, color);
screen_set_color(view->window, color);
text++;
continue;
}
if ((*text & 127) >= 32)
waddch(view->window, *text);
screen_addch(view->window, *text);
else {
/* low-ascii */
set_color(view->window, ATTR_REVERSE);
waddch(view->window, (*text & 127)+'A'-1);
set_color(view->window, color);
screen_set_color(view->window, ATTR_REVERSE);
screen_addch(view->window, (*text & 127)+'A'-1);
screen_set_color(view->window, color);
}
text++;
}
@ -475,8 +475,8 @@ static void view_draw(TEXT_BUFFER_VIEW_REC *view, GList *line,
/* clear the rest of the view */
while (lines > 0) {
wmove(view->window, ypos, 0);
wclrtoeol(view->window);
screen_move(view->window, ypos, 0);
screen_clrtoeol(view->window);
ypos++; lines--;
}
}
@ -562,9 +562,7 @@ static int view_scroll(TEXT_BUFFER_VIEW_REC *view, GList **lines, int *subline,
whole view */
textbuffer_view_redraw(view);
} else {
scrollok(view->window, TRUE);
wscrl(view->window, realcount);
scrollok(view->window, FALSE);
screen_window_scroll(view->window, realcount);
if (draw_nonclean) {
if (realcount < 0)
@ -1054,7 +1052,8 @@ LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
/* Specify window where the changes in view should be drawn,
NULL disables it. */
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view, WINDOW *window)
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view,
SCREEN_WINDOW *window)
{
g_return_if_fail(view != NULL);
@ -1071,7 +1070,7 @@ void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view)
g_return_if_fail(view != NULL);
if (view->window != NULL) {
werase(view->window);
screen_window_clear(view->window);
view_draw_top(view, view->height);
screen_refresh(view->window);
}

View File

@ -41,7 +41,7 @@ typedef struct {
TEXT_BUFFER_REC *buffer;
GSList *siblings; /* other views that use the same buffer */
WINDOW *window;
SCREEN_WINDOW *window;
int width, height;
int default_indent;
@ -121,7 +121,8 @@ LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
/* Specify window where the changes in view should be drawn,
NULL disables it. */
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view, WINDOW *window);
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view,
SCREEN_WINDOW *window);
/* Redraw the view */
void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view);