Ticket #1475: warningis fix
[midnight-commander.git] / src / tty.c
blob17edb8808a2e950bf6fc08dd17345bc415b32476
1 /*
2 Interface to the terminal controlling library.
4 Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
6 Written by:
7 Roland Illig <roland.illig@gmx.de>, 2005.
9 This file is part of the Midnight Commander.
11 The Midnight Commander is free software; you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 The Midnight Commander is distributed in the hope that it will be
17 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 MA 02110-1301, USA.
27 /** \file tty.c
28 * \brief Source: %interface to the terminal controlling library
31 #include <config.h>
33 #include <signal.h>
34 #include <stdarg.h>
36 #include "global.h"
37 #include "color.h"
38 #include "main.h" /* for slow_terminal */
39 #include "strutil.h"
41 #if defined(USE_NCURSES) || defined(USE_NCURSESW)
42 #define WANT_TERM_H
43 #endif
44 #include "tty.h"
46 /*** file scope macro definitions **************************************/
48 #ifndef HAVE_SLANG
49 # define acs()
50 # define noacs()
51 #endif
53 /*** global variables **************************************************/
55 /*** file scope type declarations **************************************/
57 /*** file scope variables **********************************************/
59 static volatile sig_atomic_t got_interrupt = 0;
61 /*** file scope functions **********************************************/
63 static void
64 sigintr_handler(int signo)
66 (void) &signo;
67 got_interrupt = 1;
70 /*** public functions **************************************************/
72 extern void
73 tty_start_interrupt_key(void)
75 struct sigaction act;
77 act.sa_handler = sigintr_handler;
78 sigemptyset (&act.sa_mask);
79 act.sa_flags = SA_RESTART;
80 sigaction (SIGINT, &act, NULL);
83 extern void
84 tty_enable_interrupt_key(void)
86 struct sigaction act;
88 act.sa_handler = sigintr_handler;
89 sigemptyset (&act.sa_mask);
90 act.sa_flags = 0;
91 sigaction (SIGINT, &act, NULL);
92 got_interrupt = 0;
95 extern void
96 tty_disable_interrupt_key(void)
98 struct sigaction act;
100 act.sa_handler = SIG_IGN;
101 sigemptyset (&act.sa_mask);
102 act.sa_flags = 0;
103 sigaction (SIGINT, &act, NULL);
106 extern gboolean
107 tty_got_interrupt(void)
109 gboolean rv;
111 rv = (got_interrupt != 0);
112 got_interrupt = 0;
113 return rv;
116 extern void
117 tty_gotoyx(int y, int x)
119 #ifdef HAVE_SLANG
120 SLsmg_gotorc(y, x);
121 #else
122 move(y, x);
123 #endif
126 extern void
127 tty_getyx(int *py, int *px)
129 #ifdef HAVE_SLANG
130 *px = SLsmg_get_column();
131 *py = SLsmg_get_row();
132 #else
133 getyx(stdscr, *py, *px);
134 #endif
137 extern void
138 tty_setcolor(int c)
140 attrset(c);
143 extern void
144 tty_print_char(int c)
146 #ifdef HAVE_SLANG
147 /* We cannot use SLsmg_write_char here because the Debian and Redhat
148 * people thought changing the API of an external project was fun,
149 * especially when it depends on the preprocessor symbol UTF8 being
150 * defined or not. Congratulations! At least, they left the API call
151 * for SLsmg_write_nchars as it has always been.
153 char ch;
155 ch = c;
156 SLsmg_write_nchars(&ch, 1);
157 #else
158 addch(c);
159 #endif
162 extern void
163 tty_print_alt_char(int c)
165 #ifdef HAVE_SLANG
166 SLsmg_draw_object(SLsmg_get_row(), SLsmg_get_column(), c);
167 #else
168 acs();
169 addch(c);
170 noacs();
171 #endif
174 extern void
175 tty_print_string(const char *s)
177 #ifdef HAVE_SLANG
178 SLsmg_write_string (str_unconst (str_term_form (s)));
179 #else
180 addstr (str_term_form (s));
181 #endif
184 extern void
185 tty_print_one_hline(void)
187 if (slow_terminal)
188 tty_print_char(' ');
189 else
190 tty_print_alt_char(ACS_HLINE);
193 extern void
194 tty_print_one_vline(void)
196 if (slow_terminal)
197 tty_print_char(' ');
198 else
199 tty_print_alt_char(ACS_VLINE);
202 extern void
203 tty_print_hline(int top, int left, int length)
205 int i;
207 tty_gotoyx(top, left);
208 for (i = 0; i < length; i++)
209 tty_print_one_hline();
212 extern void
213 tty_print_vline(int top, int left, int length)
215 int i;
217 tty_gotoyx(top, left);
218 for (i = 0; i < length; i++) {
219 tty_gotoyx(top + i, left);
220 tty_print_one_vline();
224 extern void
225 tty_printf(const char *fmt, ...)
227 va_list args;
229 va_start(args, fmt);
230 #ifdef HAVE_SLANG
231 SLsmg_vprintf(str_unconst(fmt), args);
232 #else
233 vw_printw(stdscr, fmt, args);
234 #endif
235 va_end(args);
238 extern char *
239 tty_tgetstr (const char *cap)
241 #ifdef HAVE_SLANG
242 return SLtt_tgetstr (str_unconst (cap));
243 #else
245 char *unused = NULL;
246 return tgetstr (str_unconst (cap), &unused);
248 #endif