1 /*======================================================================*\
2 |	Library to determine and enquire terminal properties
3 |	(developed as part of mined editor)
4 \*======================================================================*/
5 
6 #include "_proto.h"
7 
8 
9 #ifndef _FLAG_H
10 typedef enum {False, True} FLAG;
11 #define _FLAG_H
12 #endif
13 
14 
15 /*======================================================================*\
16 |	Terminal properties to be determined
17 \*======================================================================*/
18 
19 /* basic terminal encoding modes */
20 extern FLAG ascii_screen;	/* screen driven in ASCII mode ? */
21 extern FLAG utf8_screen;	/* screen driven in UTF-8 mode ? */
22 extern FLAG utf8_input;		/* keyboard input in UTF-8 mode ? */
23 extern FLAG combining_screen;	/* UTF-8 combining character terminal ? */
24 extern FLAG bidi_screen;	/* UTF-8 bidi terminal ? */
25 extern FLAG joining_screen;	/* UTF-8 terminal with Arabic LAM/ALEF joining ? */
26 extern FLAG halfjoining_screen;	/* Putty/mintty joining + spare space ? */
27 
28 extern FLAG mapped_term;	/* terminal in mapped 8-bit mode ? */
29 
30 extern FLAG cjk_term;		/* terminal in CJK mode ? */
31 extern FLAG cjk_uni_term;	/* terminal in CJK mode with Unicode widths ? */
32 extern FLAG cjk_wide_latin1;	/* wide CJK chars in Latin-1 range ? */
33 extern FLAG gb18030_term;	/* does CJK terminal support GB18030 ? */
34 extern FLAG euc3_term;		/* does CJK terminal support EUC 3 byte ? */
35 extern FLAG euc4_term;		/* does CJK terminal support EUC 4 byte ? */
36 extern FLAG cjklow_term;	/* does CJK terminal support 81-9F range ? */
37 extern int cjk_tab_width;	/* width of CJK TAB indicator */
38 extern int cjk_lineend_width;	/* width of CJK line end indicator */
39 extern int cjk_currency_width;	/* width of CJK cent/pound/yen characters */
40 
41 
42 /* basic data versions of Unicode (or in earlier cases, terminal-specific) */
43 /* in addition to width_data_version, cjk_width_data_version is set
44    only in CJK legacy width mode (xterm -cjk_width);
45    combining_data_version is provided separate from these two to
46    accomodate actual terminal behaviour which may not always be
47    consistent with a specific Unicode version
48  */
49 typedef enum {
50 	U0,
51 	U300beta, U300, U320beta, U320,
52 	U400, U410,
53 	U500, U510, U520,
54 	U600, U620, U630,
55 	U700,
56 	WIDTH_DATA_MAX
57 } width_data_type;
58 
59 
60 /* return name of Unicode version applied by terminal */
61 extern char * term_Unicode_version_name _((int v));
62 
63 /* basic data versions of Unicode */
64 extern int width_data_version;
65 extern int combining_data_version;
66 
67 /* special modes */
68 extern int cjk_width_data_version;	/* xterm CJK legacy width mode -cjk_width */
69 extern FLAG hangul_jamo_extended;	/* U+D7B0... combining Jamo ? */
70 
71 /* specific behaviour of specific terminals */
72 extern FLAG unassigned_single_width;	/* rxvt */
73 extern FLAG spacing_combining;		/* mlterm */
74 extern FLAG wide_Yijing_hexagrams;	/* wcwidth glitch */
75 extern FLAG printable_bidi_controls;	/* since xterm 230 */
76 
77 /* version indications of specific terminals */
78 /* a value of -1 means the specific terminal has not been detected */
79 extern int decterm_version;
80 extern int xterm_version;
81 extern int gnome_terminal_version;
82 extern int rxvt_version;
83 extern int konsole_version;
84 extern int mintty_version;
85 extern int mlterm_version;
86 extern int poderosa_version;
87 extern int screen_version;
88 extern int tmux_version;
89 
90 /* terminal features with respect to non-BMP characters (>= 0x10000) */
91 extern int nonbmp_width_data;
92 extern FLAG suppress_non_BMP;	/* suppressing display of non-BMP range */
93 #define plane_2_double_width	((nonbmp_width_data & 0x4) != 0)
94 #define plane_1_combining	((nonbmp_width_data & 0x2) == 0)
95 #define plane_14_combining	((nonbmp_width_data & 0x1) == 0)
96 
97 
98 /*======================================================================*\
99 |	Enquire character properties on terminal
100 |	with respect to the configured (detected)
101 |	Unicode version of the terminal
102 \*======================================================================*/
103 
104 /* Check whether a Unicode character is a combining character, based on its
105    Unicode general category being Mn (Mark Nonspacing), Me (Mark Enclosing),
106    Cf (Other Format),
107    or (depending on terminal features) Mc (Mark Spacing Combining).
108  */
109 extern int term_iscombining _((unsigned long ucs));
110 
111 /* Check whether a Unicode character is a wide character, based on its
112    Unicode category being East Asian Wide (W) or East Asian FullWidth (F)
113    as defined in Unicode Technical Report #11, East Asian Ambiguous (A)
114    if the terminal is running in CJK compatibility mode (xterm -cjk_width).
115    Data taken from different versions of
116    http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
117  */
118 extern int term_iswide _((unsigned long ucs));
119 
120 /* Check whether a Unicode code is a valid (assigned) Unicode character.
121  */
122 extern int term_isassigned _((unsigned long ucs));
123 
124 
125 /*======================================================================*\
126 |	End
127 \*======================================================================*/
128