Home | History | Annotate | Line # | Download | only in libcurses
      1  1.12    rin /*	$NetBSD: curs_set.c,v 1.12 2021/09/06 07:45:48 rin Exp $	*/
      2   1.1  blymn 
      3   1.1  blymn /*-
      4   1.1  blymn  * Copyright (c) 1998-2000 Brett Lymn
      5   1.1  blymn  *                         (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
      6   1.1  blymn  * All rights reserved.
      7   1.1  blymn  *
      8   1.1  blymn  * This code has been donated to The NetBSD Foundation by the Author.
      9   1.1  blymn  *
     10   1.1  blymn  * Redistribution and use in source and binary forms, with or without
     11   1.1  blymn  * modification, are permitted provided that the following conditions
     12   1.1  blymn  * are met:
     13   1.1  blymn  * 1. Redistributions of source code must retain the above copyright
     14   1.1  blymn  *    notice, this list of conditions and the following disclaimer.
     15   1.1  blymn  * 2. The name of the author may not be used to endorse or promote products
     16   1.5    wiz  *    derived from this software without specific prior written permission
     17   1.1  blymn  *
     18   1.1  blymn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19   1.1  blymn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20   1.1  blymn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21   1.1  blymn  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22   1.1  blymn  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23   1.1  blymn  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24   1.1  blymn  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25   1.1  blymn  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26   1.1  blymn  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27   1.1  blymn  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28   1.1  blymn  *
     29   1.1  blymn  *
     30   1.1  blymn  */
     31   1.1  blymn 
     32   1.3  blymn #include <sys/cdefs.h>
     33   1.3  blymn #ifndef lint
     34  1.12    rin __RCSID("$NetBSD: curs_set.c,v 1.12 2021/09/06 07:45:48 rin Exp $");
     35   1.3  blymn #endif				/* not lint */
     36   1.3  blymn 
     37   1.1  blymn #include "curses.h"
     38   1.1  blymn #include "curses_private.h"
     39   1.1  blymn 
     40   1.1  blymn /*
     41   1.1  blymn  * curs_set --
     42   1.1  blymn  *    Set the visibility of the cursor, 0 means invisible, 1 means normal
     43   1.1  blymn  *    visibility and 2 means high visibility.  Return the previous
     44   1.1  blymn  *    visibility iff the terminal supports the new visibility otherwise
     45   1.1  blymn  *    return ERR.
     46   1.1  blymn  */
     47   1.1  blymn int
     48   1.1  blymn curs_set(int visibility)
     49   1.1  blymn {
     50   1.1  blymn 	int old_one;
     51   1.1  blymn 
     52   1.6  blymn 	old_one = _cursesi_screen->old_mode;
     53   1.1  blymn 	switch (visibility) {
     54   1.1  blymn 		case 0: /* invisible */
     55   1.9    roy 			if (cursor_invisible != NULL) {
     56   1.8    jdc 				__CTRACE(__CTRACE_MISC,
     57   1.8    jdc 				    "curs_set: invisible\n");
     58   1.6  blymn 				_cursesi_screen->old_mode = 0;
     59   1.9    roy 				tputs(cursor_invisible, 0, __cputchar);
     60  1.10  blymn 				fflush(_cursesi_screen->outfd);
     61   1.1  blymn 				return old_one;
     62   1.1  blymn 			}
     63   1.1  blymn 			break;
     64   1.1  blymn 
     65   1.1  blymn 		case 1: /* normal */
     66   1.9    roy 			if (cursor_normal != NULL) {
     67   1.8    jdc 				__CTRACE(__CTRACE_MISC, "curs_set: normal\n");
     68   1.6  blymn 				_cursesi_screen->old_mode = 1;
     69   1.9    roy 				tputs(cursor_normal, 0, __cputchar);
     70  1.10  blymn 				fflush(_cursesi_screen->outfd);
     71   1.1  blymn 				return old_one;
     72   1.1  blymn 			}
     73   1.1  blymn 			break;
     74   1.1  blymn 
     75   1.1  blymn 		case 2: /* high visibility */
     76   1.9    roy 			if (cursor_visible != NULL) {
     77  1.12    rin 				__CTRACE(__CTRACE_MISC, "curs_set: high vis\n");
     78   1.6  blymn 				_cursesi_screen->old_mode = 2;
     79   1.9    roy 				tputs(cursor_visible, 0, __cputchar);
     80  1.10  blymn 				fflush(_cursesi_screen->outfd);
     81   1.1  blymn 				return old_one;
     82   1.1  blymn 			}
     83   1.1  blymn 			break;
     84   1.1  blymn 
     85   1.1  blymn 		default:
     86   1.1  blymn 			break;
     87   1.1  blymn 	}
     88   1.1  blymn 
     89   1.1  blymn 	return ERR;
     90   1.1  blymn }
     91   1.1  blymn 
     92   1.3  blymn /*
     93   1.3  blymn  * __restore_cursor_vis --
     94   1.3  blymn  *     Restore the old cursor visibility.
     95   1.3  blymn  */
     96   1.3  blymn void
     97   1.3  blymn __restore_cursor_vis(void)
     98   1.3  blymn {
     99   1.6  blymn 	curs_set(_cursesi_screen->old_mode);
    100   1.3  blymn }
    101   1.3  blymn 
    102