vinyl-cache/bin/vinyltest/vtest2/src/teken_subr_compat.h
0
/*-
1
 * SPDX-License-Identifier: BSD-2-Clause
2
 *
3
 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
 * SUCH DAMAGE.
26
 */
27
28
static void
29 10
teken_subr_cons25_set_border(const teken_t *t, unsigned int c)
30
{
31
32 10
        teken_funcs_param(t, TP_SETBORDER, c);
33 10
}
34
35
static void
36 20
teken_subr_cons25_set_global_cursor_shape(const teken_t *t, unsigned int ncmds,
37
    const unsigned int cmds[])
38
{
39
        unsigned int code, i;
40
41
        /*
42
         * Pack the args to work around API deficiencies.  This requires
43
         * knowing too much about the low level to be fully compatible.
44
         * Returning when ncmds > 3 is necessary and happens to be
45
         * compatible.  Discarding high bits is necessary and happens to
46
         * be incompatible only for invalid args when ncmds == 3.
47
         */
48 20
        if (ncmds > 3)
49 10
                return;
50 10
        code = 0;
51 40
        for (i = ncmds; i > 0; i--)
52 30
                code = (code << 8) | (cmds[i - 1] & 0xff);
53 10
        code = (code << 8) | ncmds;
54 10
        teken_funcs_param(t, TP_SETGLOBALCURSOR, code);
55 20
}
56
57
static void
58 10
teken_subr_cons25_set_local_cursor_type(const teken_t *t, unsigned int type)
59
{
60
61 10
        teken_funcs_param(t, TP_SETLOCALCURSOR, type);
62 10
}
63
64
static const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
65
    TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_YELLOW, TC_WHITE };
66
67
static void
68 10
teken_subr_cons25_set_default_background(teken_t *t, unsigned int c)
69
{
70
71 10
        t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
72 10
        t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
73 10
}
74
75
static void
76 10
teken_subr_cons25_set_default_foreground(teken_t *t, unsigned int c)
77
{
78
79 10
        t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
80 10
        t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
81 10
}
82
83
static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
84
85
void
86 295
teken_get_defattr_cons25(const teken_t *t, int *fg, int *bg)
87
{
88
89 295
        *fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
90 295
        if (t->t_defattr.ta_format & TF_BOLD)
91 0
                *fg += 8;
92 295
        *bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
93 295
}
94
95
static void
96 10
teken_subr_cons25_switch_virtual_terminal(const teken_t *t, unsigned int vt)
97
{
98
99 10
        teken_funcs_param(t, TP_SWITCHVT, vt);
100 10
}
101
102
static void
103 10
teken_subr_cons25_set_bell_pitch_duration(const teken_t *t, unsigned int pitch,
104
    unsigned int duration)
105
{
106
107 20
        teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
108 10
            (duration & 0xffff));
109 10
}
110
111
static void
112 10
teken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
113
    unsigned int param)
114
{
115
116 10
        (void)param;
117 10
        switch (cmd) {
118
        case 0: /* Reset. */
119 10
                t->t_curattr = t->t_defattr;
120 10
                break;
121
        default:
122
                teken_printf("unsupported attribute %u\n", cmd);
123 0
        }
124 10
}
125
126
static void
127 30
teken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
128
{
129
130 30
        switch (mode) {
131
        case 0: /* Switch terminal to xterm. */
132 10
                t->t_stateflags &= ~TS_CONS25;
133 10
                break;
134
        case 1: /* Switch terminal to cons25. */
135 10
                t->t_stateflags |= TS_CONS25;
136 10
                break;
137
        default:
138 10
                break;
139
        }
140 30
}
141
142
#if 0
143
static void
144
teken_subr_vt52_decid(teken_t *t)
145
{
146
        const char response[] = "\x1B/Z";
147
148
        teken_funcs_respond(t, response, sizeof response - 1);
149
}
150
#endif