chiark / gitweb /
terminal/screen: add cursor rendering
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 3 Oct 2014 12:42:42 +0000 (14:42 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 3 Oct 2014 13:57:00 +0000 (15:57 +0200)
This is the most simple way to render cursors: flip attr->inverse of the
cursor cell. This causes the background and foreground colors of the
cursor-cell to be inversed.

Now that we render cursors ourselves, make subterm not call into the
parent terminal to render cursors.

src/libsystemd-terminal/subterm.c
src/libsystemd-terminal/term-screen.c

index 563cbf0823a9928689f2c2740785ad29faab63c4..321cd35f528b5fe1a496fbb9c6d15610831ef759 100644 (file)
@@ -286,6 +286,8 @@ static Output *output_free(Output *o) {
         if (!o)
                 return NULL;
 
         if (!o)
                 return NULL;
 
+        /* re-enable cursor */
+        output_printf(o, "\e[?25h");
         /* disable alternate screen buffer */
         output_printf(o, "\e[?1049l");
         output_flush(o);
         /* disable alternate screen buffer */
         output_printf(o, "\e[?1049l");
         output_flush(o);
@@ -317,6 +319,11 @@ static int output_new(Output **out, int fd) {
         if (r < 0)
                 goto error;
 
         if (r < 0)
                 goto error;
 
+        /* always hide cursor */
+        r = output_printf(o, "\e[?25l");
+        if (r < 0)
+                goto error;
+
         r = output_flush(o);
         if (r < 0)
                 goto error;
         r = output_flush(o);
         if (r < 0)
                 goto error;
@@ -539,10 +546,6 @@ static void output_draw(Output *o, bool menu, term_screen *screen) {
         else
                 output_draw_screen(o, screen);
 
         else
                 output_draw_screen(o, screen);
 
-        /* show cursor */
-        if (!(screen->flags & TERM_FLAG_HIDE_CURSOR))
-                output_printf(o, "\e[?25h");
-
         /*
          * Hack: sd-term was not written to support TTY as output-objects, thus
          * expects callers to use term_screen_feed_keyboard(). However, we
         /*
          * Hack: sd-term was not written to support TTY as output-objects, thus
          * expects callers to use term_screen_feed_keyboard(). However, we
index 2c881ca8b1c6e832b294f135f8bbb0ec08139993..ccfb9a450c65e7581e198a6749092159f214ace5 100644 (file)
@@ -4246,6 +4246,8 @@ int term_screen_draw(term_screen *screen,
                 line_age = MAX(line->age, page->age);
 
                 for (i = 0; i < page->width; ++i) {
                 line_age = MAX(line->age, page->age);
 
                 for (i = 0; i < page->width; ++i) {
+                        term_attr attr;
+
                         cell = &line->cells[i];
                         cell_age = MAX(cell->age, line_age);
 
                         cell = &line->cells[i];
                         cell_age = MAX(cell->age, line_age);
 
@@ -4259,11 +4261,16 @@ int term_screen_draw(term_screen *screen,
                          * renderers can assume ch_width is set properpy. */
                         cw = MAX(cell->cwidth, 1U);
 
                          * renderers can assume ch_width is set properpy. */
                         cw = MAX(cell->cwidth, 1U);
 
+                        attr = cell->attr;
+                        if (i == screen->cursor_x && j == screen->cursor_y &&
+                            !(screen->flags & TERM_FLAG_HIDE_CURSOR))
+                                attr.inverse ^= 1;
+
                         r = draw_fn(screen,
                                     userdata,
                                     i,
                                     j,
                         r = draw_fn(screen,
                                     userdata,
                                     i,
                                     j,
-                                    &cell->attr,
+                                    &attr,
                                     ch_str,
                                     ch_n,
                                     cw);
                                     ch_str,
                                     ch_n,
                                     cw);