1*0c3ae37fSLionel Sambuc /* $NetBSD: curs_set.c,v 1.10 2011/03/30 09:47:02 blymn Exp $ */
2b7061124SArun Thomas
351ffecc1SBen Gras /*-
451ffecc1SBen Gras * Copyright (c) 1998-2000 Brett Lymn
551ffecc1SBen Gras * (blymn@baea.com.au, brett_lymn@yahoo.com.au)
651ffecc1SBen Gras * All rights reserved.
751ffecc1SBen Gras *
851ffecc1SBen Gras * This code has been donated to The NetBSD Foundation by the Author.
951ffecc1SBen Gras *
1051ffecc1SBen Gras * Redistribution and use in source and binary forms, with or without
1151ffecc1SBen Gras * modification, are permitted provided that the following conditions
1251ffecc1SBen Gras * are met:
1351ffecc1SBen Gras * 1. Redistributions of source code must retain the above copyright
1451ffecc1SBen Gras * notice, this list of conditions and the following disclaimer.
1551ffecc1SBen Gras * 2. The name of the author may not be used to endorse or promote products
1651ffecc1SBen Gras * derived from this software without specific prior written permission
1751ffecc1SBen Gras *
1851ffecc1SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1951ffecc1SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2051ffecc1SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2151ffecc1SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2251ffecc1SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2351ffecc1SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2451ffecc1SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2551ffecc1SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2651ffecc1SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2751ffecc1SBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2851ffecc1SBen Gras *
2951ffecc1SBen Gras *
30b7061124SArun Thomas */
3151ffecc1SBen Gras
3251ffecc1SBen Gras #include <sys/cdefs.h>
3351ffecc1SBen Gras #ifndef lint
34*0c3ae37fSLionel Sambuc __RCSID("$NetBSD: curs_set.c,v 1.10 2011/03/30 09:47:02 blymn Exp $");
3551ffecc1SBen Gras #endif /* not lint */
3651ffecc1SBen Gras
3751ffecc1SBen Gras #include "curses.h"
3851ffecc1SBen Gras #include "curses_private.h"
3951ffecc1SBen Gras
4051ffecc1SBen Gras /*
4151ffecc1SBen Gras * curs_set --
4251ffecc1SBen Gras * Set the visibility of the cursor, 0 means invisible, 1 means normal
4351ffecc1SBen Gras * visibility and 2 means high visibility. Return the previous
4451ffecc1SBen Gras * visibility iff the terminal supports the new visibility otherwise
4551ffecc1SBen Gras * return ERR.
4651ffecc1SBen Gras */
4751ffecc1SBen Gras int
curs_set(int visibility)4851ffecc1SBen Gras curs_set(int visibility)
49b7061124SArun Thomas {
5051ffecc1SBen Gras int old_one;
5151ffecc1SBen Gras
5251ffecc1SBen Gras old_one = _cursesi_screen->old_mode;
53b7061124SArun Thomas switch (visibility) {
5451ffecc1SBen Gras case 0: /* invisible */
5551ffecc1SBen Gras if (cursor_invisible != NULL) {
5651ffecc1SBen Gras #ifdef DEBUG
5751ffecc1SBen Gras __CTRACE(__CTRACE_MISC,
5851ffecc1SBen Gras "curs_set: invisible\n");
5951ffecc1SBen Gras #endif
6051ffecc1SBen Gras _cursesi_screen->old_mode = 0;
6151ffecc1SBen Gras tputs(cursor_invisible, 0, __cputchar);
62*0c3ae37fSLionel Sambuc fflush(_cursesi_screen->outfd);
6351ffecc1SBen Gras return old_one;
64b7061124SArun Thomas }
6551ffecc1SBen Gras break;
6651ffecc1SBen Gras
6751ffecc1SBen Gras case 1: /* normal */
6851ffecc1SBen Gras if (cursor_normal != NULL) {
6951ffecc1SBen Gras #ifdef DEBUG
7051ffecc1SBen Gras __CTRACE(__CTRACE_MISC, "curs_set: normal\n");
7151ffecc1SBen Gras #endif
7251ffecc1SBen Gras _cursesi_screen->old_mode = 1;
7351ffecc1SBen Gras tputs(cursor_normal, 0, __cputchar);
74*0c3ae37fSLionel Sambuc fflush(_cursesi_screen->outfd);
7551ffecc1SBen Gras return old_one;
76b7061124SArun Thomas }
7751ffecc1SBen Gras break;
7851ffecc1SBen Gras
7951ffecc1SBen Gras case 2: /* high visibility */
8051ffecc1SBen Gras if (cursor_visible != NULL) {
8151ffecc1SBen Gras #ifdef DEBUG
8251ffecc1SBen Gras __CTRACE(__CTRACE_MISC,
8351ffecc1SBen Gras "curs_set: high vis\n");
8451ffecc1SBen Gras #endif
8551ffecc1SBen Gras _cursesi_screen->old_mode = 2;
8651ffecc1SBen Gras tputs(cursor_visible, 0, __cputchar);
87*0c3ae37fSLionel Sambuc fflush(_cursesi_screen->outfd);
8851ffecc1SBen Gras return old_one;
8951ffecc1SBen Gras }
9051ffecc1SBen Gras break;
9151ffecc1SBen Gras
9251ffecc1SBen Gras default:
9351ffecc1SBen Gras break;
9451ffecc1SBen Gras }
9551ffecc1SBen Gras
9651ffecc1SBen Gras return ERR;
9751ffecc1SBen Gras }
9851ffecc1SBen Gras
9951ffecc1SBen Gras /*
10051ffecc1SBen Gras * __restore_cursor_vis --
10151ffecc1SBen Gras * Restore the old cursor visibility.
10251ffecc1SBen Gras */
10351ffecc1SBen Gras void
__restore_cursor_vis(void)10451ffecc1SBen Gras __restore_cursor_vis(void)
10551ffecc1SBen Gras {
10651ffecc1SBen Gras curs_set(_cursesi_screen->old_mode);
10751ffecc1SBen Gras }
10851ffecc1SBen Gras
109