• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Public Domain Curses */
2 
3 #include "pdcwin.h"
4 
5 RCSID("$Id: pdcdisp.c,v 1.47 2008/07/14 04:24:52 wmcbrine Exp $")
6 
7 #include <stdlib.h>
8 #include <string.h>
9 
10 #ifdef CHTYPE_LONG
11 
12 # define A(x) ((chtype)x | A_ALTCHARSET)
13 
14 chtype acs_map[128] =
15 {
16     A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10),
17     A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19),
18     A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27), A(28),
19     A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&', '\'', '(',
20     ')', '*',
21 
22 # ifdef PDC_WIDE
23     0x2192, 0x2190, 0x2191, 0x2193,
24 # else
25     A(0x1a), A(0x1b), A(0x18), A(0x19),
26 # endif
27 
28     '/',
29 
30 # ifdef PDC_WIDE
31     0x2588,
32 # else
33     0xdb,
34 # endif
35 
36     '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
37     '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
38     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
39     'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
40 
41 # ifdef PDC_WIDE
42     0x2666, 0x2592,
43 # else
44     A(0x04), 0xb1,
45 # endif
46 
47     'b', 'c', 'd', 'e',
48 
49 # ifdef PDC_WIDE
50     0x00b0, 0x00b1, 0x2591, 0x00a4, 0x2518, 0x2510, 0x250c, 0x2514,
51     0x253c, 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524,
52     0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3,
53     0x00b7,
54 # else
55     0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d, 0x2d,
56     0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2, 0xe3,
57     0xd8, 0x9c, 0xf9,
58 # endif
59 
60     A(127)
61 };
62 
63 # undef A
64 
65 #endif
66 
67 /* position hardware cursor at (y, x) */
68 
PDC_gotoyx(int row,int col)69 void PDC_gotoyx(int row, int col)
70 {
71     COORD coord;
72 
73     PDC_LOG(("PDC_gotoyx() - called: row %d col %d from row %d col %d\n",
74              row, col, SP->cursrow, SP->curscol));
75 
76     coord.X = col;
77     coord.Y = row;
78 
79     SetConsoleCursorPosition(pdc_con_out, coord);
80 }
81 
82 /* update the given physical line to look like the corresponding line in
83    curscr */
84 
PDC_transform_line(int lineno,int x,int len,const chtype * srcp)85 void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
86 {
87     CHAR_INFO ci[512];
88     int j;
89     COORD bufSize, bufPos;
90     SMALL_RECT sr;
91 
92     PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno));
93 
94     bufPos.X = bufPos.Y = 0;
95 
96     bufSize.X = len;
97     bufSize.Y = 1;
98 
99     sr.Top = lineno;
100     sr.Bottom = lineno;
101     sr.Left = x;
102     sr.Right = x + len - 1;
103 
104     for (j = 0; j < len; j++)
105     {
106         chtype ch = srcp[j];
107 
108         ci[j].Attributes = pdc_atrtab[ch >> PDC_ATTR_SHIFT];
109 #ifdef CHTYPE_LONG
110         if (ch & A_ALTCHARSET && !(ch & 0xff80))
111             ch = acs_map[ch & 0x7f];
112 #endif
113         ci[j].Char.UnicodeChar = ch & A_CHARTEXT;
114     }
115 
116     WriteConsoleOutput(pdc_con_out, ci, bufSize, bufPos, &sr);
117 }
118