teken_subr_compat.h revision 302408
157416Smarkm/*-
257416Smarkm * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
357416Smarkm * All rights reserved.
457416Smarkm *
557416Smarkm * Redistribution and use in source and binary forms, with or without
657416Smarkm * modification, are permitted provided that the following conditions
757416Smarkm * are met:
857416Smarkm * 1. Redistributions of source code must retain the above copyright
957416Smarkm *    notice, this list of conditions and the following disclaimer.
1057416Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1157416Smarkm *    notice, this list of conditions and the following disclaimer in the
1257416Smarkm *    documentation and/or other materials provided with the distribution.
1357416Smarkm *
1457416Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1557416Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1657416Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1757416Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1857416Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1957416Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2057416Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2157416Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2257416Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2357416Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2457416Smarkm * SUCH DAMAGE.
2557416Smarkm *
2657416Smarkm * $FreeBSD: stable/11/sys/teken/teken_subr_compat.h 214817 2010-11-05 00:56:21Z ed $
2757416Smarkm */
2857416Smarkm
2957416Smarkmstatic void
3057416Smarkmteken_subr_cons25_set_cursor_type(teken_t *t, unsigned int type)
3157416Smarkm{
3257416Smarkm
3357416Smarkm	teken_funcs_param(t, TP_SHOWCURSOR, type != 1);
3457416Smarkm}
3557416Smarkm
36233294Sstasstatic const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
3757416Smarkm    TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_BROWN, TC_WHITE };
3857416Smarkm
3957416Smarkmstatic void
4057416Smarkmteken_subr_cons25_set_adapter_background(teken_t *t, unsigned int c)
4157416Smarkm{
4257416Smarkm
4357416Smarkm	t->t_defattr.ta_bgcolor = cons25_colors[c % 8];
4457416Smarkm	t->t_curattr.ta_bgcolor = cons25_colors[c % 8];
4557416Smarkm}
4657416Smarkm
4757416Smarkmstatic void
48142403Snectarteken_subr_cons25_set_adapter_foreground(teken_t *t, unsigned int c)
4957416Smarkm{
5057416Smarkm
5157416Smarkm	t->t_defattr.ta_fgcolor = cons25_colors[c % 8];
5257416Smarkm	t->t_curattr.ta_fgcolor = cons25_colors[c % 8];
5357416Smarkm	if (c >= 8) {
5457416Smarkm		t->t_defattr.ta_format |= TF_BOLD;
5557416Smarkm		t->t_curattr.ta_format |= TF_BOLD;
5657416Smarkm	} else {
5757416Smarkm		t->t_defattr.ta_format &= ~TF_BOLD;
5857416Smarkm		t->t_curattr.ta_format &= ~TF_BOLD;
5957416Smarkm	}
6057416Smarkm}
6157416Smarkm
6257416Smarkmstatic const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
6357416Smarkm
6457416Smarkmvoid
6557416Smarkmteken_get_defattr_cons25(teken_t *t, int *fg, int *bg)
6657416Smarkm{
6757416Smarkm
6857416Smarkm	*fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
6957416Smarkm	if (t->t_defattr.ta_format & TF_BOLD)
7057416Smarkm		*fg += 8;
7157416Smarkm	*bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
7257416Smarkm}
7357416Smarkm
7457416Smarkmstatic void
7557416Smarkmteken_subr_cons25_switch_virtual_terminal(teken_t *t, unsigned int vt)
7657416Smarkm{
7757416Smarkm
7857416Smarkm	teken_funcs_param(t, TP_SWITCHVT, vt);
7957416Smarkm}
8057416Smarkm
8157416Smarkmstatic void
8257416Smarkmteken_subr_cons25_set_bell_pitch_duration(teken_t *t, unsigned int pitch,
8357416Smarkm    unsigned int duration)
8457416Smarkm{
8557416Smarkm
8657416Smarkm	teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
8757416Smarkm	    (duration & 0xffff));
8857416Smarkm}
8957416Smarkm
9057416Smarkmstatic void
9157416Smarkmteken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
9257416Smarkm    unsigned int param __unused)
9357416Smarkm{
9457416Smarkm
9557416Smarkm	switch (cmd) {
9657416Smarkm	case 0: /* Reset. */
9757416Smarkm		t->t_curattr = t->t_defattr;
9857416Smarkm		break;
9957416Smarkm	default:
10057416Smarkm		teken_printf("unsupported attribute %u\n", cmd);
10157416Smarkm	}
10257416Smarkm}
10357416Smarkm
10457416Smarkmstatic void
10557416Smarkmteken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
10657416Smarkm{
10757416Smarkm
10857416Smarkm	switch (mode) {
10957416Smarkm	case 0:	/* Switch terminal to xterm. */
11057416Smarkm		t->t_stateflags &= ~TS_CONS25;
11157416Smarkm		break;
11257416Smarkm	case 1: /* Switch terminal to cons25. */
11357416Smarkm		t->t_stateflags |= TS_CONS25;
11457416Smarkm		break;
11557416Smarkm	}
11657416Smarkm}
11757416Smarkm
11857416Smarkm#if 0
11957416Smarkmstatic void
12057416Smarkmteken_subr_vt52_decid(teken_t *t)
12157416Smarkm{
12257416Smarkm	const char response[] = "\x1B/Z";
12357416Smarkm
12457416Smarkm	teken_funcs_respond(t, response, sizeof response - 1);
12557416Smarkm}
12657416Smarkm#endif
12757416Smarkm