int term_init(void)
{
- struct sigaction act;
+ struct sigaction act;
+ int width, height;
last_fg = last_bg = -1;
last_attrs = 0;
if (current_term == NULL)
return FALSE;
+ if (term_get_size(&width, &height)) {
+ current_term->width = width;
+ current_term->height = height;
+ }
+
/* grab CONT signal */
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
void term_deinit(void)
{
if (current_term != NULL) {
+ signal(SIGCONT, SIG_DFL);
g_source_remove(redraw_tag);
term_common_deinit();
/* bold */
if (col & 0x08)
col |= ATTR_BOLD;
- else if (col & ATTR_BOLD)
+ if (col & ATTR_BOLD)
terminfo_set_bold();
/* underline */
void term_move(TERM_WINDOW *window, int x, int y)
{
+ if (x >= 0 && y >= 0) {
vcmove = TRUE;
vcx = x+window->x;
vcy = y+window->y;
vcx = term_width-1;
if (vcy >= term_height)
vcy = term_height-1;
+ }
}
static void term_printed_text(int count)
However, next term_move() really shouldn't try to cache
the move, otherwise terminals would try to combine the
last word in upper line with first word in lower line. */
- cforcemove = TRUE;
vcx += count;
while (vcx >= term_width) {
vcx -= term_width;
- if (vcy < term_height) vcy++;
+ if (vcy < term_height-1) vcy++;
if (vcx > 0) term_lines_empty[vcy] = FALSE;
}
+
+ crealx += count;
+ if (crealx >= term_width)
+ cforcemove = TRUE;
}
void term_addch(TERM_WINDOW *window, int chr)
if (vcmove) term_move_real();
- /* With UTF-8, move cursor only if this char is either single-byte
- (8. bit on) or beginning of multibyte (7+8 bits on) */
- if (term_type != TERM_TYPE_UTF8 ||
- (chr & 0x80) == 0 || (chr & 0x40) == 0) {
- term_printed_text(1);
- }
+ if (vcy < term_height-1 || vcx < term_width-1) {
+ /* With UTF-8, move cursor only if this char is either
+ single-byte (8. bit off) or beginning of multibyte
+ (7. bit off) */
+ if (term_type != TERM_TYPE_UTF8 ||
+ (chr & 0x80) == 0 || (chr & 0x40) == 0) {
+ term_printed_text(1);
+ }
- if (vcy != term_height || vcx != 0)
putc(chr, window->term->out);
+ }
}
static void term_addch_utf8(TERM_WINDOW *window, unichar chr)
if (term_detached) return;
if (vcmove) term_move_real();
- term_printed_text(1);
- if (vcy == term_height && vcx == 0)
+ if (vcy == term_height-1 && vcx == term_width-1)
return; /* last char in screen */
switch (term_type) {
case TERM_TYPE_UTF8:
+ term_printed_text(utf8_width(chr));
term_addch_utf8(window, chr);
break;
case TERM_TYPE_BIG5:
- putc((chr >> 8) & 0xff, window->term->out);
+ if (chr > 0xff) {
+ term_printed_text(2);
+ putc((chr >> 8) & 0xff, window->term->out);
+ } else {
+ term_printed_text(1);
+ }
putc((chr & 0xff), window->term->out);
break;
default:
+ term_printed_text(1);
putc(chr, window->term->out);
break;
}
if (term_detached) return;
if (vcmove) term_move_real();
- len = strlen(str);
+ len = strlen(str); /* FIXME utf8 or big5 */
term_printed_text(len);
if (vcy != term_height || vcx != 0)
terminfo_set_cursor_visible(TRUE);
curs_visible = TRUE;
}
+
term_set_color(window, ATTR_RESET);
fflush(window != NULL ? window->term->out : current_term->out);
}
void term_refresh_freeze(void)
{
freeze_counter++;
-
- if (!term_detached && curs_visible) {
- terminfo_set_cursor_visible(FALSE);
- curs_visible = FALSE;
- }
}
void term_refresh_thaw(void)
void term_stop(void)
{
if (term_detached) {
- kill(getpid(), SIGSTOP);
+ kill(getpid(), SIGTSTP);
} else {
terminfo_stop(current_term);
- kill(getpid(), SIGSTOP);
+ kill(getpid(), SIGTSTP);
terminfo_cont(current_term);
irssi_redraw();
}
{
const unsigned char *end = buffer;
- *result = get_utf8_char(&end, size);
- switch (*result) {
- case (unichar) -2:
+ switch (get_utf8_char(&end, size, result)) {
+ case -2:
/* not UTF8 - fallback to 8bit ascii */
*result = *buffer;
return 1;
- case (unichar) -1:
+ case -1:
/* need more data */
return -1;
default:
}
}
-/* XXX I didn't check the encoding range of big5+. This is standard big5. */
-#define is_big5_los(lo) (0x40 <= (lo) && (lo) <= 0x7E) /* standard */
-#define is_big5_lox(lo) (0x80 <= (lo) && (lo) <= 0xFE) /* extended */
-#define is_big5_hi(hi) (0x81 <= (hi) && (hi) <= 0xFE)
-#define is_big5(hi,lo) (is_big5_hi(hi) && (is_big5_los(lo) || is_big5_lox(lo)))
-
static int input_big5(const unsigned char *buffer, int size, unichar *result)
{
if (is_big5_hi(*buffer)) {
if (i >= term_inbuf_pos)
term_inbuf_pos = 0;
else if (i > 0) {
- memmove(term_inbuf+i, term_inbuf, term_inbuf_pos-i);
+ memmove(term_inbuf, term_inbuf+i, term_inbuf_pos-i);
term_inbuf_pos -= i;
}
}