changed includes from ../mhl/ to <mhl/...>
[midnight-commander.git] / src / tty.c
bloba71c6cc8ebcf3b17094c5885b6a2f282b07a24a3
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 #include <config.h>
29 #include <signal.h>
30 #include <stdarg.h>
32 #include "global.h"
33 #include "color.h"
34 #include "main.h" /* for slow_terminal */
36 #ifdef USE_NCURSES
37 #define WANT_TERM_H
38 #endif
39 #include "tty.h"
41 /*** file scope macro definitions **************************************/
43 #ifndef HAVE_SLANG
44 # define acs()
45 # define noacs()
46 #endif
48 /*** global variables **************************************************/
50 /*** file scope type declarations **************************************/
52 /*** file scope variables **********************************************/
54 static volatile sig_atomic_t got_interrupt = 0;
56 /*** file scope functions **********************************************/
58 static void
59 sigintr_handler(int signo)
61 (void) &signo;
62 got_interrupt = 1;
65 /*** public functions **************************************************/
67 extern void
68 tty_enable_interrupt_key(void)
70 struct sigaction act;
72 got_interrupt = 0;
73 act.sa_handler = sigintr_handler;
74 sigemptyset (&act.sa_mask);
75 act.sa_flags = 0;
76 sigaction (SIGINT, &act, NULL);
79 extern void
80 tty_disable_interrupt_key(void)
82 struct sigaction act;
84 act.sa_handler = SIG_IGN;
85 sigemptyset (&act.sa_mask);
86 act.sa_flags = 0;
87 sigaction (SIGINT, &act, NULL);
90 extern gboolean
91 tty_got_interrupt(void)
93 gboolean rv;
95 rv = (got_interrupt != 0);
96 got_interrupt = 0;
97 return rv;
100 extern void
101 tty_gotoyx(int y, int x)
103 #ifdef HAVE_SLANG
104 SLsmg_gotorc(y, x);
105 #else
106 move(y, x);
107 #endif
110 extern void
111 tty_getyx(int *py, int *px)
113 #ifdef HAVE_SLANG
114 *px = SLsmg_get_column();
115 *py = SLsmg_get_row();
116 #else
117 getyx(stdscr, *py, *px);
118 #endif
121 extern void
122 tty_setcolor(int c)
124 attrset(c);
127 extern void
128 tty_print_char(int c)
130 #ifdef HAVE_SLANG
131 /* We cannot use SLsmg_write_char here because the Debian and Redhat
132 * people thought changing the API of an external project was fun,
133 * especially when it depends on the preprocessor symbol UTF8 being
134 * defined or not. Congratulations! At least, they left the API call
135 * for SLsmg_write_nchars as it has always been.
137 char ch;
139 ch = c;
140 SLsmg_write_nchars(&ch, 1);
141 #else
142 addch(c);
143 #endif
146 extern void
147 tty_print_alt_char(int c)
149 #ifdef HAVE_SLANG
150 SLsmg_draw_object(SLsmg_get_row(), SLsmg_get_column(), c);
151 #else
152 acs();
153 addch(c);
154 noacs();
155 #endif
158 extern void
159 tty_print_string(const char *s)
161 #ifdef HAVE_SLANG
162 SLsmg_write_string(str_unconst(s));
163 #else
164 addstr(s);
165 #endif
168 extern void
169 tty_print_one_hline(void)
171 if (slow_terminal)
172 tty_print_char(' ');
173 else
174 tty_print_alt_char(ACS_HLINE);
177 extern void
178 tty_print_one_vline(void)
180 if (slow_terminal)
181 tty_print_char(' ');
182 else
183 tty_print_alt_char(ACS_VLINE);
186 extern void
187 tty_print_hline(int top, int left, int length)
189 int i;
191 tty_gotoyx(top, left);
192 for (i = 0; i < length; i++)
193 tty_print_one_hline();
196 extern void
197 tty_print_vline(int top, int left, int length)
199 int i;
201 tty_gotoyx(top, left);
202 for (i = 0; i < length; i++) {
203 tty_gotoyx(top + i, left);
204 tty_print_one_vline();
208 extern void
209 tty_printf(const char *fmt, ...)
211 va_list args;
213 va_start(args, fmt);
214 #ifdef HAVE_SLANG
215 SLsmg_vprintf(str_unconst(fmt), args);
216 #else
217 vw_printw(stdscr, fmt, args);
218 #endif
219 va_end(args);
222 extern char *
223 tty_tgetstr (const char *cap)
225 #ifdef HAVE_SLANG
226 return SLtt_tgetstr (str_unconst (cap));
227 #else
229 char *unused = NULL;
230 return tgetstr (str_unconst (cap), &unused);
232 #endif