cmenu: use VT-100 alternate character set for drawing boxes
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Sat, 29 Aug 2009 05:06:12 +0000 (22:06 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Tue, 1 Sep 2009 18:43:38 +0000 (11:43 -0700)
Use the Special Characters and Line Drawing Character Set as
described in http://www.vt100.net/docs/vt102-ug/table5-13.html
to draw boxes around the menus.

Note that to work in xterm, G1 needs to be initialized (to point
to the alternate character set). This is done in the cls function
("\033)0").

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/cmenu/libmenu/tui.c
com32/cmenu/libmenu/tui.h

index 81e4079..330b46f 100644 (file)
@@ -343,29 +343,26 @@ void drawbox(char top, char left, char bot, char right,
 {
     unsigned char *box_chars;  // pointer to array of box chars
     unsigned char x;
-
+       fputs(SO, stdout);
     box_chars = getboxchars(bt);
     // Top border
     gotoxy(top, left, page);
-    cprint(box_chars[BOX_TOPLEFT], attr, 1, page);
-    gotoxy(top, left + 1, page);
-    cprint(box_chars[BOX_TOP], attr, right - left, page);
-    gotoxy(top, right, page);
-    cprint(box_chars[BOX_TOPRIGHT], attr, 1, page);
+    cprint(TOP_LEFT_CORNER_BORDER, attr, 1, page);
+    cprint(TOP_BORDER, attr, right - left - 1, page);
+    cprint(TOP_RIGHT_CORNER_BORDER, attr, 1, page);
     // Bottom border
     gotoxy(bot, left, page);
-    cprint(box_chars[BOX_BOTLEFT], attr, 1, page);
-    gotoxy(bot, left + 1, page);
-    cprint(box_chars[BOX_BOT], attr, right - left, page);
-    gotoxy(bot, right, page);
-    cprint(box_chars[BOX_BOTRIGHT], attr, 1, page);
+    cprint(BOTTOM_LEFT_CORNER_BORDER, attr, 1, page);
+    cprint(BOTTOM_BORDER, attr, right - left - 1, page);
+    cprint(BOTTOM_RIGHT_CORNER_BORDER, attr, 1, page);
     // Left & right borders
     for (x = top + 1; x < bot; x++) {
        gotoxy(x, left, page);
-       cprint(box_chars[BOX_LEFT], attr, 1, page);
+       cprint(LEFT_BORDER, attr, 1, page);
        gotoxy(x, right, page);
-       cprint(box_chars[BOX_RIGHT], attr, 1, page);
+       cprint(RIGHT_BORDER, attr, 1, page);
     }
+       fputs(SI, stdout);
 }
 
 void drawhorizline(char top, char left, char right, char page, char attr,
index 4df1532..28c680e 100644 (file)
 #define NULL ((void *)0)
 #endif
 
+/* "", not ''! */
+#define SO "\016"
+#define SI "\017"
+
+#define TOP_LEFT_CORNER_BORDER '\154'
+#define TOP_BORDER '\161'
+#define TOP_RIGHT_CORNER_BORDER '\153'
+#define BOTTOM_LEFT_CORNER_BORDER '\155'
+#define BOTTOM_BORDER '\161'
+#define BOTTOM_RIGHT_CORNER_BORDER '\152'
+#define LEFT_BORDER '\170'
+#define RIGHT_BORDER '\170'
+
 #define BELL 0x07
 // CHRELATTR = ^N, CHABSATTR = ^O
 #define CHABSATTR 15
 void clearwindow(char top, char left, char bot, char right,
                 char page, char fillchar, char fillattr);
 
-void cls(void);                        /* Clears the entire current screen page */
+/*
+ * Clears the entire screen
+ *
+ * Note: when initializing xterm, one has to specify that
+ * G1 points to the alternate character set (this is not true
+ * by default). Without the initial printf "\033)0", line drawing
+ * characters won't be displayed.
+ */
+static inline void cls(void)
+{
+       return fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+}
+
 
 // Generic user input,
 // password = 0 iff chars echoed on screen