Exemplo n.º 1
0
    def set_render_coords(self, x, y, width, height):
        ui.Window.set_render_coords(self, x, y, width, height)

        cr = self.app.ui.cr
        context = pango.cairo_create_context(cr)
        font_map = pango.cairo_font_map_get_default()
        desc = pango.FontDescription.from_string('Bitstream Vera Sans Mono 8')
        font = pango.font_map_load_font(font_map, context._internal, desc._internal)
        metrics = pango.font_get_metrics(font, None)[0]
        self.char_width = pango.pango_units_to_double(pango.font_metrics_get_approximate_char_width(metrics))
        self.char_height = (
            pango.pango_units_to_double(pango.font_metrics_get_ascent(metrics)) + 
            pango.pango_units_to_double(pango.font_metrics_get_descent(metrics))
        )

        self.chars_width = int(self.rwidth / self.char_width)
        self.chars_height = int(self.rheight / self.char_height)

        self.app.term.screen.resize(self.chars_height, self.chars_width)
        fcntl.ioctl(self.app.process_io, termios.TIOCSWINSZ,
                struct.pack("hhhh", self.chars_height, self.chars_width, 0, 0))
Exemplo n.º 2
0
    def _render(self, cr):
        desc = pango.FontDescription.from_string('Bitstream Vera Sans Mono 8')
        y = self.ry + self.char_height
        for row in self.term.screen[self.term.screen.visible_start:self.term.screen.visible_start+self.term.screen.rows]:
            if row.dirty:
                curr = row.rendition[0]
                #print "curr %08x" % curr, curr >> 24, (curr & 0x00ff0000) >> 16
                markup = ('<span foreground="%s" background="%s">' % (
                        color_map[curr >> 24], 
                        color_map[(curr & 0x00ff0000) >> 16],
                        )) + row.chars[0]
                for c in xrange(1, self.chars_width):
                    ch = row.chars[c]
                    r = row.rendition[c]
                    if curr != r:
                        curr = r
                        markup += ('</span><span foreground="%s" background="%s">' % (
                                color_map[curr >> 24], 
                                color_map[(curr & 0x00ff0000) >> 16],
                                ))
                    if ch == '>':
                        markup += '&gt;'
                    elif ch == '<':
                        markup += '&lt;'
                    else:
                        markup += ch
                markup += '</span>'
                row.layout = pango.cairo_create_layout(cr)
                row.layout.font_description = desc
                row.layout.set_markup(markup, -1)
                row.dirty = False
            if row.layout:
                cr.move_to(self.rx, y-pango.pango_units_to_double(row.layout.get_baseline()))
                pango.cairo_update_layout(cr, row.layout)
                pango.cairo_show_layout(cr, row.layout)

            y += self.char_height
        desc.free()

        cr.rectangle(
            self.rx+(self.term.screen.cursor_col*self.char_width),
            2+self.ry+(self.term.screen.cursor_row*self.char_height),
            self.char_width,
            self.char_height)
        cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
        cr.fill()