5 * (c) 2024 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU Library General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * mLib is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 * License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
35 /*----- Header files ------------------------------------------------------*/
43 /*----- Data structures ---------------------------------------------------*/
46 #define TTAF_LNMASK 0x0003u /* line style mask */
47 #define TTAF_LNSHIFT 0 /* line style shift */
49 TTLN_NONE, /* no line */
50 TTLN_ULINE, /* underline */
51 TTLN_UULINE, /* double underline */
52 TTLN_STRIKE, /* strikeout */
55 #define TTAF_WTMASK 0x000cu /* weight mask */
56 #define TTAG_WTSHIFT 2 /* weight shift */
58 TTWT_MED, /* medium */
59 TTWT_BOLD, /* bold/bright */
60 TTWT_DIM, /* light/dim */
63 #define TTAF_ITAL 0x0010u /* italic/oblique */
64 #define TTAF_INVV 0x0020u /* inverse video */
65 #define TTAF_FGSPCMASK 0x1c00u /* foreground space mask */
66 #define TTAF_FGSPCSHIFT 10 /* foreground space shift */
67 #define TTAF_BGSPCMASK 0xe000u /* background space mask */
68 #define TTAF_BGSPCSHIFT 13 /* background space shift */
70 TTCSPC_NONE, /* no colour */
71 TTCSPC_1BPC, /* one bit per channel */
72 TTCSPC_1BPCBR, /* one bit per channel, brighter */
73 TTCSPC_2BPC, /* two bits levels per channel */
74 TTCSPC_8LGS, /* eight levels greyscale */
75 TTCSPC_6LPC, /* six levels per channel */
76 TTCSPC_24LGS, /* 24 levels greyscale */
77 TTCSPC_8BPC /* eight bits per channel */
83 #define TT1BC_GREEN 2u
85 #define TT1BC_BRIGHT 8u
86 #define TTCOL_BLACK 0u
87 #define TTCOL_RED (TT1BC_RED)
88 #define TTCOL_GREEN (TT1BC_GREEN)
89 #define TTCOL_YELLOW (TT1BC_RED | TT1BC_GREEN)
90 #define TTCOL_BLUE (TT1BC_BLUE)
91 #define TTCOL_MAGENTA (TT1BC_RED | TT1BC_BLUE)
92 #define TTCOL_CYAN (TT1BC_GREEN | TT1BC_BLUE)
93 #define TTCOL_WHITE (TT1BC_RED | TT1BC_GREEN | TT1BC_BLUE)
94 #define TTCOL_BRBLACK (TTCOL_BLACK | TT1BC_BRIGHT)
95 #define TTCOL_BRRED (TTCOL_RED | TT1BC_BRIGHT)
96 #define TTCOL_BRGREEN (TTCOL_GREEN | TT1BC_BRIGHT)
97 #define TTCOL_BRYELLOW (TTCOL_YELLOW | TT1BC_BRIGHT)
98 #define TTCOL_BRBLUE (TTCOL_BLUE | TT1BC_BRIGHT)
99 #define TTCOL_BRMAGENTA (TTCOL_MAGENTA | TT1BC_BRIGHT)
100 #define TTCOL_BRCYAN (TTCOL_CYAN | TT1BC_BRIGHT)
101 #define TTCOL_BRWHITE (TTCOL_WHITE | TT1BC_BRIGHT)
103 #define TTCOL_MK2B(r, g, b) (((r) << 4) | ((g) << 2) | ((b) << 0))
104 #define TTCOL_2BR(col) (((col) >> 4)&0x03)
105 #define TTCOL_2BG(col) (((col) >> 2)&0x03)
106 #define TTCOL_2BB(col) (((col) >> 0)&0x03)
108 #define TTCOL_MK6L(r, g, b) (36*(r) + 6*(g) + (b))
109 #define TTCOL_6LR(col) ((col)/36)
110 #define TTCOL_6LG(col) (((col)/6)%6)
111 #define TTCOL_6LB(col) ((col)%6)
113 #define TTCOL_MK8B(r, g, b) (((r) << 16) | ((g) << 8) | ((b) << 0))
114 #define TTCOL_8BR(col) (((col) >> 16)&0xff)
115 #define TTCOL_8BG(col) (((col) >> 8)&0xff)
116 #define TTCOL_8BB(col) (((col) >> 0)&0xff)
119 uint32 f, _res0; /* attribute flags, reserved */
120 uint32 fg, bg; /* foreground/background colours */
124 #define TTMF_AUTOM 0x00000001u /* automatic margins */
125 #define TTMF_FSCRM 0x00000002u /* full-screen mode */
126 #define TTMF_INS 0x00000004u /* insert mode */
128 /* Attribute capabilities. */
129 #define TTACF_ULINE 0x00000001u /* underline */
130 #define TTACF_UULINE 0x00000002u /* double underline */
131 #define TTACF_STRIKE 0x00000004u /* strikeout */
132 #define TTACF_BOLD 0x00000008u /* bold/bright */
133 #define TTACF_DIM 0x00000010u /* light/dim */
134 #define TTACF_ITAL 0x00000020u /* italic/oblique */
135 #define TTACF_INVV 0x00000040u /* inverse video */
136 #define TTACF_FG 0x00000080u /* set foreground colour */
137 #define TTACF_BG 0x00000100u /* set background colour */
138 #define TTACF_1BPC 0x00000200u /* one-bit-per-channel space */
139 #define TTACF_1BPCBR 0x00000400u /* one-bit-per-channel bright space */
140 #define TTACF_2BPC 0x00000800u /* two-bits-per-channel space */
141 #define TTACF_8LGS 0x00001000u /* 8-levels-greyscale space */
142 #define TTACF_6LPC 0x00002000u /* six-levels-per-channel space */
143 #define TTACF_24LGS 0x00004000u /* 24-levels-greyscale space */
144 #define TTACF_8BPC 0x00008000u /* eight-bits-per-channel space */
146 /* Other capabilities. */
147 #define TTCF_RELMV 0x00000100u /* relative cursor motion */
148 #define TTCF_ABSMV 0x00000200u /* absolute cursor motion */
149 #define TTCF_MIXMV 0x00000400u /* mixed cursor motion */
150 #define TTCF_MVINS 0x00000800u /* motion preserves insert mode */
151 #define TTCF_MVATTR 0x00001000u /* motion preserves attributes */
152 #define TTCF_MMARG 0x00002000u /* proper magic margins */
153 #define TTCF_SCRGN 0x00004000u /* scroll regions */
154 #define TTCF_SCROLL 0x00008000u /* explicit scrolling */
155 #define TTCF_BGER 0x00010000u /* erasure uses background colour */
156 #define TTCF_ERCH 0x00020000u /* erase characters */
157 #define TTCF_ERBOL 0x00040000u /* erase from beginning of line */
158 #define TTCF_EREOL 0x00080000u /* erase to end of line */
159 #define TTCF_ERBOD 0x00100000u /* erase from beginning of display */
160 #define TTCF_EREOD 0x00200000u /* erase to end of display */
161 #define TTCF_ERDSP 0x00400000u /* erase display */
162 #define TTCF_INSCH 0x00800000u /* insert character */
163 #define TTCF_INSLN 0x01000000u /* insert line */
164 #define TTCF_DELCH 0x02000000u /* delete character */
165 #define TTCF_DELLN 0x04000000u /* delete line */
167 struct tty_attrlist {
168 uint32 cap_mask, cap_eq; /* capabilities to select */
169 struct tty_attr attr; /* attributes to set */
171 #define TTY_ATTRLIST_END { 0, 0, { 0, 0, 0, 0 } }
173 /* Terminal capability backend libraries. */
175 TTLIB_TERMCAP, /* traditional `termcap' */
176 TTLIB_TERMINFO, /* standard `terminfo' */
177 TTLIB_UNIBILIUM, /* `Unibiliium' */
178 TTLIB_XTERM, /* assume modern terminal conventions */
184 struct tty_attr attr;
188 const struct tty_ops *ops;
190 unsigned baud, ht, wd;
196 #define TTOF_XHOME 0u /* absolute horizontal motion */
197 #define TTOF_XCUR 1u /* relative horizontal motion */
198 #define TTOF_YHOME 0u /* absolute vertical motion */
199 #define TTOF_YCUR 2u /* relative vertical motion */
202 #define TTEF_LINE 0u /* erase within line */
203 #define TTEF_DSP 1u /* erase whole display */
204 #define TTEF_BEGIN 2u /* erase from beginning */
205 #define TTEF_END 4u /* erase to end */
207 /* Insertion and deletion. */
208 #define TTIDF_CH 0u /* insert/delete characters */
209 #define TTIDF_LN 1u /* insert/delete lines */
212 int (*setattr)(struct tty */*tty*/,
213 const struct gprintf_ops */*gops*/, void */*go*/,
214 const struct tty_attr */*old*/,
215 const struct tty_attr */*new*/);
216 int (*setmodes)(struct tty */*tty*/,
217 const struct gprintf_ops */*gops*/, void */*go*/,
218 uint32 /*modes_bic*/, uint32 /*modes_xor*/);
219 int (*move)(struct tty */*tty*/,
220 const struct gprintf_ops */*gops*/, void */*go*/,
221 unsigned /*orig*/, int /*y*/, int /*x*/);
222 int (*repeat)(struct tty */*tty*/,
223 const struct gprintf_ops */*gops*/, void */*go*/,
224 int /*ch*/, unsigned /*n*/);
225 int (*erase)(struct tty */*tty*/,
226 const struct gprintf_ops */*gops*/, void */*go*/,
228 int (*erch)(struct tty */*tty*/,
229 const struct gprintf_ops */*gops*/, void */*go*/,
231 int (*ins)(struct tty */*tty*/,
232 const struct gprintf_ops */*gops*/, void */*go*/,
233 unsigned /*f*/, unsigned /*n*/);
234 int (*del)(struct tty */*tty*/,
235 const struct gprintf_ops */*gops*/, void */*go*/,
236 unsigned /*f*/, unsigned /*n*/);
237 int (*setscrgn)(struct tty */*tty*/,
238 const struct gprintf_ops */*gops*/, void */*go*/,
239 unsigned /*y0*/, unsigned /*y1*/);
240 int (*scroll)(struct tty */*tty*/,
241 const struct gprintf_ops */*gops*/, void */*go*/,
245 /*----- Functions provided ------------------------------------------------*/
255 * me clear text highlighting
257 * op default colour pair
259 * up cursor up 1 line
261 * cd clear to end-of-display
262 * ce clear to end-of-line
271 /*----- That's all, folks -------------------------------------------------*/