[vte] terminal: Use an enum class for cursor style



commit 872d2b8eb183f2d047755a44bacde2c7e304661d
Author: Christian Persch <chpe src gnome org>
Date:   Mon Nov 18 22:42:22 2019 +0100

    terminal: Use an enum class for cursor style

 src/vte.cc         | 40 ++++++++++++++++++----------------------
 src/vteinternal.hh | 53 ++++++++++++++++++++++++++++-------------------------
 src/vteseq.cc      |  4 ++--
 3 files changed, 48 insertions(+), 49 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 2a4092fa..bd9607ef 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -3330,7 +3330,7 @@ Terminal::process_incoming_utf8()
 {
        VteVisualPosition saved_cursor;
        gboolean saved_cursor_visible;
-        VteCursorStyle saved_cursor_style;
+        CursorStyle saved_cursor_style;
         vte::grid::row_t bbox_top, bbox_bottom;
        gboolean modified, bottom;
        gboolean invalidated_text;
@@ -3610,7 +3610,7 @@ Terminal::process_incoming_pcterm()
 {
        VteVisualPosition saved_cursor;
        gboolean saved_cursor_visible;
-        VteCursorStyle saved_cursor_style;
+        CursorStyle saved_cursor_style;
         vte::grid::row_t bbox_top, bbox_bottom;
        gboolean modified, bottom;
        gboolean invalidated_text;
@@ -7895,10 +7895,6 @@ Terminal::Terminal(vte::platform::Widget* w,
        /* Cursor blinking. */
         m_cursor_blink_mode = VTE_CURSOR_BLINK_SYSTEM;
 
-        /* DECSCUSR cursor style (shape and blinking possibly overridden
-         * via escape sequence) */
-        m_cursor_style = VTE_CURSOR_STYLE_TERMINAL_DEFAULT;
-
         /* Initialize the saved cursor. */
         save_cursor(&m_normal_screen);
         save_cursor(&m_alternate_screen);
@@ -9818,7 +9814,7 @@ Terminal::set_cursor_shape(VteCursorShape shape)
 
 /* DECSCUSR set cursor style */
 bool
-Terminal::set_cursor_style(VteCursorStyle style)
+Terminal::set_cursor_style(CursorStyle style)
 {
         if (m_cursor_style == style)
                 return false;
@@ -9845,15 +9841,15 @@ Terminal::decscusr_cursor_blink()
 {
         switch (m_cursor_style) {
         default:
-        case VTE_CURSOR_STYLE_TERMINAL_DEFAULT:
+        case CursorStyle::eTERMINAL_DEFAULT:
                 return m_cursor_blink_mode;
-        case VTE_CURSOR_STYLE_BLINK_BLOCK:
-        case VTE_CURSOR_STYLE_BLINK_UNDERLINE:
-        case VTE_CURSOR_STYLE_BLINK_IBEAM:
+        case CursorStyle::eBLINK_BLOCK:
+        case CursorStyle::eBLINK_UNDERLINE:
+        case CursorStyle::eBLINK_IBEAM:
                 return VTE_CURSOR_BLINK_ON;
-        case VTE_CURSOR_STYLE_STEADY_BLOCK:
-        case VTE_CURSOR_STYLE_STEADY_UNDERLINE:
-        case VTE_CURSOR_STYLE_STEADY_IBEAM:
+        case CursorStyle::eSTEADY_BLOCK:
+        case CursorStyle::eSTEADY_UNDERLINE:
+        case CursorStyle::eSTEADY_IBEAM:
                 return VTE_CURSOR_BLINK_OFF;
         }
 }
@@ -9873,16 +9869,16 @@ Terminal::decscusr_cursor_shape()
 {
         switch (m_cursor_style) {
         default:
-        case VTE_CURSOR_STYLE_TERMINAL_DEFAULT:
+        case CursorStyle::eTERMINAL_DEFAULT:
                 return m_cursor_shape;
-        case VTE_CURSOR_STYLE_BLINK_BLOCK:
-        case VTE_CURSOR_STYLE_STEADY_BLOCK:
+        case CursorStyle::eBLINK_BLOCK:
+        case CursorStyle::eSTEADY_BLOCK:
                 return VTE_CURSOR_SHAPE_BLOCK;
-        case VTE_CURSOR_STYLE_BLINK_UNDERLINE:
-        case VTE_CURSOR_STYLE_STEADY_UNDERLINE:
+        case CursorStyle::eBLINK_UNDERLINE:
+        case CursorStyle::eSTEADY_UNDERLINE:
                 return VTE_CURSOR_SHAPE_UNDERLINE;
-        case VTE_CURSOR_STYLE_BLINK_IBEAM:
-        case VTE_CURSOR_STYLE_STEADY_IBEAM:
+        case CursorStyle::eBLINK_IBEAM:
+        case CursorStyle::eSTEADY_IBEAM:
                 return VTE_CURSOR_SHAPE_IBEAM;
         }
 }
@@ -10078,7 +10074,7 @@ Terminal::reset(bool clear_tabstops,
                adjust_adjustments_full();
        }
         /* DECSCUSR cursor style */
-        set_cursor_style(VTE_CURSOR_STYLE_TERMINAL_DEFAULT);
+        set_cursor_style(CursorStyle::eTERMINAL_DEFAULT);
        /* Reset restricted scrolling regions, leave insert mode, make
         * the cursor visible again. */
         m_scrolling_restricted = FALSE;
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index fd441ccd..290ee188 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -147,29 +147,6 @@ typedef struct _VtePaletteColor {
        } sources[2];
 } VtePaletteColor;
 
-/* These correspond to the parameters for DECSCUSR (Set cursor style). */
-typedef enum _VteCursorStyle {
-        /* We treat 0 and 1 differently, assuming that the VT510 does so too.
-         *
-         * See, according to the "VT510 Video Terminal Programmer Information",
-         * from vt100.net, paragraph "2.5.7 Cursor Display", there was a menu
-         * item in the "Terminal Set-Up" to set the cursor's style. It looks
-         * like that defaulted to blinking block. So it makes sense for 0 to
-         * mean "set cursor style to default (set by Set-Up)" and 1 to mean
-         * "set cursor style to blinking block", since that default need not be
-         * blinking block. Access to a VT510 is needed to test this theory,
-         * but it seems plausible. And, anyhow, we can even decide we know
-         * better than the VT510 designers! */
-        VTE_CURSOR_STYLE_TERMINAL_DEFAULT = 0,
-        VTE_CURSOR_STYLE_BLINK_BLOCK      = 1,
-        VTE_CURSOR_STYLE_STEADY_BLOCK     = 2,
-        VTE_CURSOR_STYLE_BLINK_UNDERLINE  = 3,
-        VTE_CURSOR_STYLE_STEADY_UNDERLINE = 4,
-        /* *_IBEAM are xterm extensions */
-        VTE_CURSOR_STYLE_BLINK_IBEAM      = 5,
-        VTE_CURSOR_STYLE_STEADY_IBEAM     = 6
-} VteCursorStyle;
-
 struct VteScreen {
 public:
         VteScreen(gulong max_rows,
@@ -327,6 +304,31 @@ class Widget;
 namespace terminal {
 
 class Terminal {
+private:
+        /* These correspond to the parameters for DECSCUSR (Set cursor style). */
+        enum class CursorStyle {
+                /* We treat 0 and 1 differently, assuming that the VT510 does so too.
+                 *
+                 * See, according to the "VT510 Video Terminal Programmer Information",
+                 * from vt100.net, paragraph "2.5.7 Cursor Display", there was a menu
+                 * item in the "Terminal Set-Up" to set the cursor's style. It looks
+                 * like that defaulted to blinking block. So it makes sense for 0 to
+                 * mean "set cursor style to default (set by Set-Up)" and 1 to mean
+                 * "set cursor style to blinking block", since that default need not be
+                 * blinking block. Access to a VT510 is needed to test this theory,
+                 * but it seems plausible. And, anyhow, we can even decide we know
+                 * better than the VT510 designers!
+                 */
+                eTERMINAL_DEFAULT = 0,
+                eBLINK_BLOCK      = 1,
+                eSTEADY_BLOCK     = 2,
+                eBLINK_UNDERLINE  = 3,
+                eSTEADY_UNDERLINE = 4,
+                /* *_IBEAM are xterm extensions */
+                eBLINK_IBEAM      = 5,
+                eSTEADY_IBEAM     = 6,
+        };
+
 public:
         Terminal(vte::platform::Widget* w,
                  VteTerminal *t);
@@ -508,7 +510,8 @@ public:
 
         /* DECSCUSR cursor style (shape and blinking possibly overridden
          * via escape sequence) */
-        VteCursorStyle m_cursor_style;
+
+        CursorStyle m_cursor_style{CursorStyle::eTERMINAL_DEFAULT};
 
        /* Input device options. */
         bool m_input_enabled{true};
@@ -1279,7 +1282,7 @@ public:
         void set_colors_default();
         bool set_cursor_blink_mode(VteCursorBlinkMode mode);
         bool set_cursor_shape(VteCursorShape shape);
-        bool set_cursor_style(VteCursorStyle style);
+        bool set_cursor_style(CursorStyle style);
         bool set_delete_binding(VteEraseBinding binding);
         bool set_enable_bidi(bool setting);
         bool set_enable_shaping(bool setting);
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 86fe2c7b..314c03d8 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -3775,7 +3775,7 @@ Terminal::DECRQSS(vte::parser::Sequence const& seq)
         switch (request.command()) {
 
         case VTE_CMD_DECSCUSR:
-                return reply(seq, VTE_REPLY_DECRPSS, {1}, {VTE_REPLY_DECSCUSR, {m_cursor_style}});
+                return reply(seq, VTE_REPLY_DECRPSS, {1}, {VTE_REPLY_DECSCUSR, {int(m_cursor_style)}});
 
         case VTE_CMD_DECSTBM:
                 if (m_scrolling_restricted)
@@ -4181,7 +4181,7 @@ Terminal::DECSCUSR(vte::parser::Sequence const& seq)
         auto param = seq.collect1(0, 0);
         switch (param) {
         case 0 ... 6:
-                set_cursor_style(VteCursorStyle(param));
+                set_cursor_style(CursorStyle(param));
                 break;
         default:
                 break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]