~ubuntu-branches/ubuntu/oneiric/irssi/oneiric

« back to all changes in this revision

Viewing changes to src/fe-text/textbuffer-view.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-05 15:50:50 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090505155050-aoqlnpes7che9rtd
Tags: 0.8.13-1ubuntu1
* Merge from debian unstable (LP: #372411), remaining changes:
  - debian/patches: 03firsttimer_text
    + Adapt it so it tells you about connecting to irc.ubuntu.com and
      joining #ubuntu instead of irc.debian.org and #debian.
  - debian/patches: 90irc-ubuntu-com
* Fixed debian/patches/90irc-ubuntu-com for new irssi.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
                textbuffer_cache_destroy(cache);
105
105
}
106
106
 
107
 
#define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | ATTR_BOLD | 0x0f)
108
 
#define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | ATTR_BLINK | 0xf0)
 
107
#define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | 0x0f)
 
108
#define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | 0xf0)
109
109
 
110
110
static void update_cmd_color(unsigned char cmd, int *color)
111
111
{
117
117
                                *color |= (cmd & 0x0f) << 4;
118
118
                        else {
119
119
                                *color = (*color & FGATTR) | ATTR_RESETBG;
120
 
                                if (cmd & LINE_COLOR_BLINK)
121
 
                                        *color |= ATTR_BLINK;
122
120
                        }
123
121
                } else {
124
122
                        /* set foreground color */
127
125
                                *color |= cmd & 0x0f;
128
126
                        else {
129
127
                                *color = (*color & BGATTR) | ATTR_RESETFG;
130
 
                                if (cmd & LINE_COLOR_BOLD)
131
 
                                        *color |= ATTR_BOLD;
132
128
                        }
133
129
                }
134
130
        } else switch (cmd) {
138
134
        case LINE_CMD_REVERSE:
139
135
                *color ^= ATTR_REVERSE;
140
136
                break;
 
137
        case LINE_CMD_BLINK:
 
138
                *color ^= ATTR_BLINK;
 
139
                break;
 
140
        case LINE_CMD_BOLD:
 
141
                *color ^= ATTR_BOLD;
 
142
                break;
141
143
        case LINE_CMD_COLOR0:
142
144
                *color &= BGATTR;
143
145
                break;
144
146
        }
145
147
}
146
148
 
 
149
static inline unichar read_unichar(const unsigned char *data, const unsigned char **next, int *width)
 
150
{
 
151
        unichar chr = g_utf8_get_char_validated(data, -1);
 
152
 
 
153
        if (chr & 0x80000000) {
 
154
                chr = 0xfffd;
 
155
                *next = data + 1;
 
156
                *width = 1;
 
157
        } else {
 
158
                *next = g_utf8_next_char(data);
 
159
                *width = unichar_isprint(chr) ? mk_wcwidth(chr) : 1;
 
160
        }
 
161
        return chr;
 
162
}
 
163
 
147
164
static LINE_CACHE_REC *
148
165
view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
149
166
{
154
171
        unsigned char cmd;
155
172
        const unsigned char *ptr, *next_ptr, *last_space_ptr;
156
173
        int xpos, pos, indent_pos, last_space, last_color, color, linecount;
157
 
        int char_len;
158
 
        unichar chr;
 
174
        int char_width;
159
175
 
160
176
        g_return_val_if_fail(line->text != NULL, NULL);
161
177
 
173
189
                        cmd = *ptr;
174
190
                        ptr++;
175
191
 
176
 
                        if (cmd == LINE_CMD_EOL || cmd == LINE_CMD_FORMAT)
 
192
                        if (cmd == LINE_CMD_EOL)
177
193
                                break;
178
194
 
179
195
                        if (cmd == LINE_CMD_CONTINUE) {
188
204
                                /* set indentation position here - don't do
189
205
                                   it if we're too close to right border */
190
206
                                if (xpos < view->width-5) indent_pos = xpos;
191
 
                        } else if (cmd == LINE_CMD_INDENT_FUNC) {
192
 
                                memcpy(&indent_func, ptr, sizeof(INDENT_FUNC));
193
 
                                ptr += sizeof(INDENT_FUNC);
194
 
                                if (indent_func == NULL)
195
 
                                        indent_func = view->default_indent_func;
196
207
                        } else
197
208
                                update_cmd_color(cmd, &color);
198
209
                        continue;
202
213
                        /* MH */
203
214
                        if (term_type != TERM_TYPE_BIG5 ||
204
215
                            ptr[1] == '\0' || !is_big5(ptr[0], ptr[1]))
205
 
                                char_len = 1;
 
216
                                char_width = 1;
206
217
                        else
207
 
                                char_len = 2;
208
 
                        next_ptr = ptr+char_len;
 
218
                                char_width = 2;
 
219
                        next_ptr = ptr+char_width;
209
220
                } else {
210
 
                        char_len = 1;
211
 
                        while (ptr[char_len] != '\0' && char_len < 6)
212
 
                                char_len++;
213
 
 
214
 
                        next_ptr = ptr;
215
 
                        if (get_utf8_char(&next_ptr, char_len, &chr) < 0)
216
 
                                char_len = 1;
217
 
                        else
218
 
                                char_len = unichar_isprint(chr) ? mk_wcwidth(chr) : 1;
219
 
                        next_ptr++;
 
221
                        read_unichar(ptr, &next_ptr, &char_width);
220
222
                }
221
223
 
222
 
                if (xpos + char_len > view->width && sub != NULL &&
 
224
                if (xpos + char_width > view->width && sub != NULL &&
223
225
                    (last_space <= indent_pos || last_space <= 10) &&
224
226
                    view->longword_noindent) {
225
227
                        /* long word, remove the indentation from this line */
227
229
                        sub->indent = 0;
228
230
                }
229
231
 
230
 
                if (xpos + char_len > view->width) {
 
232
                if (xpos + char_width > view->width) {
231
233
                        xpos = indent_func == NULL ? indent_pos :
232
234
                                indent_func(view, line, -1);
233
235
 
255
257
                        continue;
256
258
                }
257
259
 
258
 
                if (!view->utf8 && char_len > 1) {
 
260
                if (!view->utf8 && char_width > 1) {
259
261
                        last_space = xpos;
260
262
                        last_space_ptr = next_ptr;
261
263
                        last_color = color;
265
267
                        last_color = color;
266
268
                }
267
269
 
268
 
                xpos += char_len;
 
270
                xpos += char_width;
269
271
                ptr = next_ptr;
270
272
        }
271
273
 
412
414
                if (*text == '\0') {
413
415
                        /* command */
414
416
                        text++;
415
 
                        if (*text == LINE_CMD_EOL || *text == LINE_CMD_FORMAT)
 
417
                        if (*text == LINE_CMD_EOL)
416
418
                                break;
417
419
 
418
420
                        if (*text == LINE_CMD_CONTINUE) {
420
422
                                memcpy(&tmp, text+1, sizeof(unsigned char *));
421
423
                                text = tmp;
422
424
                                continue;
423
 
                        } else if (*text == LINE_CMD_INDENT_FUNC) {
424
 
                                text += sizeof(INDENT_FUNC);
425
425
                        } else {
426
426
                                update_cmd_color(*text, &color);
427
427
                                term_set_color(view->window, color);
430
430
                        continue;
431
431
                }
432
432
 
433
 
                chr = *text;
434
 
                end = text;
435
433
                if (view->utf8) {
436
 
                        if (get_utf8_char(&end, 6, &chr)<0)
437
 
                                char_width = 1;
438
 
                        else
439
 
                                char_width = unichar_isprint(chr) ? mk_wcwidth(chr) : 1;
 
434
                        chr = read_unichar(text, &end, &char_width);
440
435
                } else {
 
436
                        chr = *text;
 
437
                        end = text;
441
438
                        if (term_type == TERM_TYPE_BIG5 &&
442
439
                            is_big5(end[0], end[1]))
443
440
                                char_width = 2;
444
441
                        else
445
442
                                char_width = 1;
446
 
                        end += char_width-1;
 
443
                        end += char_width;
447
444
                }
448
445
 
449
446
                xpos += char_width;
450
447
                if (xpos <= term_width) {
451
448
                        if (unichar_isprint(chr)) {
 
449
                                if (view->utf8)
 
450
                                term_add_unichar(view->window, chr);
 
451
                                else
452
452
                                for (; text < end; text++)
453
453
                                        term_addch(view->window, *text);
454
 
                                term_addch(view->window, *text);
455
454
                        } else {
456
455
                                /* low-ascii */
457
456
                                term_set_color(view->window, ATTR_RESET|ATTR_REVERSE);
459
458
                                term_set_color(view->window, color);
460
459
                        }
461
460
                }
462
 
                text++;
 
461
                text = end;
463
462
        }
464
463
 
465
464
        if (need_clrtoeol && xpos < term_width) {
603
602
static void view_unregister_indent_func(TEXT_BUFFER_VIEW_REC *view,
604
603
                                        INDENT_FUNC indent_func)
605
604
{
606
 
        INDENT_FUNC func;
607
 
        LINE_REC *line;
608
 
        const unsigned char *text, *tmp;
609
 
 
610
605
        if (view->default_indent_func == indent_func)
611
606
                view->default_indent_func = NULL;
612
607
 
614
609
           to the indent function */
615
610
        view_reset_cache(view);
616
611
        view->cache = textbuffer_cache_get(view->siblings, view->width);
617
 
 
618
 
        /* remove all references to the indent function from buffer */
619
 
        line = view->buffer->first_line;
620
 
        while (line != NULL) {
621
 
                text = line->text;
622
 
 
623
 
                for (text = line->text;; text++) {
624
 
                        if (*text != '\0')
625
 
                                continue;
626
 
 
627
 
                        text++;
628
 
                        if (*text == LINE_CMD_EOL)
629
 
                                break;
630
 
 
631
 
                        if (*text == LINE_CMD_INDENT_FUNC) {
632
 
                                text++;
633
 
                                memcpy(&func, text, sizeof(INDENT_FUNC));
634
 
                                if (func == indent_func)
635
 
                                        memset(&func, 0, sizeof(INDENT_FUNC));
636
 
                                text += sizeof(INDENT_FUNC);
637
 
                        } else if (*text == LINE_CMD_CONTINUE) {
638
 
                                memcpy(&tmp, text+1, sizeof(char *));
639
 
                                text = tmp-1;
640
 
                        }
641
 
                }
642
 
 
643
 
                line = line->next;
644
 
        }
645
612
}
646
613
 
647
614
void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func)