blob: f4e7a12f74a91f6142fe23f799446c601b604217 [file] [log] [blame]
balrog4d3b6f62008-02-10 16:33:14 +00001/*
2 * QEMU curses/ncurses display driver
3 *
4 * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
Peter Maydelle16f4c82016-01-29 17:49:51 +000024#include "qemu/osdep.h"
balrog4d3b6f62008-02-10 16:33:14 +000025
26#ifndef _WIN32
balrog4d3b6f62008-02-10 16:33:14 +000027#include <sys/ioctl.h>
28#include <termios.h>
29#endif
30
Fei Liab4f9312018-10-17 10:26:50 +020031#include "qapi/error.h"
blueswir1511d2b12009-03-07 15:32:56 +000032#include "qemu-common.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010033#include "ui/console.h"
Gerd Hoffmanncd100322013-12-04 13:40:20 +010034#include "ui/input.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010035#include "sysemu/sysemu.h"
blueswir1511d2b12009-03-07 15:32:56 +000036
Gerd Hoffmanne2f82e92017-09-27 12:38:11 +020037/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
38#undef KEY_EVENT
39#include <curses.h>
40#undef KEY_EVENT
41
balrog4d3b6f62008-02-10 16:33:14 +000042#define FONT_HEIGHT 16
43#define FONT_WIDTH 8
44
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +010045static DisplayChangeListener *dcl;
Anthony Liguoric227f092009-10-01 16:12:16 -050046static console_ch_t screen[160 * 100];
balrog4d3b6f62008-02-10 16:33:14 +000047static WINDOW *screenpad = NULL;
48static int width, height, gwidth, gheight, invalidate;
49static int px, py, sminx, sminy, smaxx, smaxy;
50
Gerd Hoffmanne2f82e92017-09-27 12:38:11 +020051static chtype vga_to_curses[256];
OGAWA Hirofumie2368dc2015-10-19 21:23:46 +090052
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +010053static void curses_update(DisplayChangeListener *dcl,
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +010054 int x, int y, int w, int h)
balrog4d3b6f62008-02-10 16:33:14 +000055{
Gerd Hoffmanne2f82e92017-09-27 12:38:11 +020056 console_ch_t *line;
57 chtype curses_line[width];
balrog4d3b6f62008-02-10 16:33:14 +000058
Gerd Hoffmanne2f82e92017-09-27 12:38:11 +020059 line = screen + y * width;
60 for (h += y; y < h; y ++, line += width) {
61 for (x = 0; x < width; x++) {
62 chtype ch = line[x] & 0xff;
63 chtype at = line[x] & ~0xff;
64 if (vga_to_curses[ch]) {
65 ch = vga_to_curses[ch];
66 }
67 curses_line[x] = ch | at;
68 }
69 mvwaddchnstr(screenpad, y, 0, curses_line, width);
70 }
balrog4d3b6f62008-02-10 16:33:14 +000071
72 pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
73 refresh();
74}
75
76static void curses_calc_pad(void)
77{
Gerd Hoffmann81c0d5a2013-03-14 14:27:08 +010078 if (qemu_console_is_fixedsize(NULL)) {
balrog4d3b6f62008-02-10 16:33:14 +000079 width = gwidth;
80 height = gheight;
81 } else {
82 width = COLS;
83 height = LINES;
84 }
85
86 if (screenpad)
87 delwin(screenpad);
88
89 clear();
90 refresh();
91
92 screenpad = newpad(height, width);
93
94 if (width > COLS) {
95 px = (width - COLS) / 2;
96 sminx = 0;
97 smaxx = COLS;
98 } else {
99 px = 0;
100 sminx = (COLS - width) / 2;
101 smaxx = sminx + width;
102 }
103
104 if (height > LINES) {
105 py = (height - LINES) / 2;
106 sminy = 0;
107 smaxy = LINES;
108 } else {
109 py = 0;
110 sminy = (LINES - height) / 2;
111 smaxy = sminy + height;
112 }
113}
114
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100115static void curses_resize(DisplayChangeListener *dcl,
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100116 int width, int height)
balrog4d3b6f62008-02-10 16:33:14 +0000117{
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200118 if (width == gwidth && height == gheight) {
balrog4d3b6f62008-02-10 16:33:14 +0000119 return;
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200120 }
balrog4d3b6f62008-02-10 16:33:14 +0000121
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200122 gwidth = width;
123 gheight = height;
balrog4d3b6f62008-02-10 16:33:14 +0000124
125 curses_calc_pad();
126}
127
Gerd Hoffmann032ac6f2013-11-22 15:35:03 +0100128#if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE)
129static volatile sig_atomic_t got_sigwinch;
130static void curses_winch_check(void)
balrog4d3b6f62008-02-10 16:33:14 +0000131{
132 struct winsize {
133 unsigned short ws_row;
134 unsigned short ws_col;
135 unsigned short ws_xpixel; /* unused */
136 unsigned short ws_ypixel; /* unused */
137 } ws;
138
Gerd Hoffmann032ac6f2013-11-22 15:35:03 +0100139 if (!got_sigwinch) {
balrog4d3b6f62008-02-10 16:33:14 +0000140 return;
Gerd Hoffmann032ac6f2013-11-22 15:35:03 +0100141 }
142 got_sigwinch = false;
143
144 if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
145 return;
146 }
balrog4d3b6f62008-02-10 16:33:14 +0000147
148 resize_term(ws.ws_row, ws.ws_col);
balrog4d3b6f62008-02-10 16:33:14 +0000149 invalidate = 1;
balrog4d3b6f62008-02-10 16:33:14 +0000150}
Gerd Hoffmann032ac6f2013-11-22 15:35:03 +0100151
152static void curses_winch_handler(int signum)
153{
154 got_sigwinch = true;
155}
156
157static void curses_winch_init(void)
158{
159 struct sigaction old, winch = {
160 .sa_handler = curses_winch_handler,
161 };
162 sigaction(SIGWINCH, &winch, &old);
163}
164#else
165static void curses_winch_check(void) {}
166static void curses_winch_init(void) {}
balrog4d3b6f62008-02-10 16:33:14 +0000167#endif
168
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100169static void curses_cursor_position(DisplayChangeListener *dcl,
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100170 int x, int y)
balrog4d3b6f62008-02-10 16:33:14 +0000171{
172 if (x >= 0) {
173 x = sminx + x - px;
174 y = sminy + y - py;
175
176 if (x >= 0 && y >= 0 && x < COLS && y < LINES) {
177 move(y, x);
178 curs_set(1);
179 /* it seems that curs_set(1) must always be called before
180 * curs_set(2) for the latter to have effect */
Gerd Hoffmann81c0d5a2013-03-14 14:27:08 +0100181 if (!qemu_console_is_graphic(NULL)) {
balrog4d3b6f62008-02-10 16:33:14 +0000182 curs_set(2);
Gerd Hoffmann81c0d5a2013-03-14 14:27:08 +0100183 }
balrog4d3b6f62008-02-10 16:33:14 +0000184 return;
185 }
186 }
187
188 curs_set(0);
189}
190
191/* generic keyboard conversion */
192
193#include "curses_keys.h"
balrog4d3b6f62008-02-10 16:33:14 +0000194
Anthony Liguoric227f092009-10-01 16:12:16 -0500195static kbd_layout_t *kbd_layout = NULL;
balrog4d3b6f62008-02-10 16:33:14 +0000196
Gerd Hoffmannbc2ed972013-03-01 13:03:04 +0100197static void curses_refresh(DisplayChangeListener *dcl)
balrog4d3b6f62008-02-10 16:33:14 +0000198{
Peter Maydell99a9ef42016-08-11 15:23:27 +0100199 int chr, keysym, keycode, keycode_alt;
balrog4d3b6f62008-02-10 16:33:14 +0000200
Gerd Hoffmann032ac6f2013-11-22 15:35:03 +0100201 curses_winch_check();
202
balrog4d3b6f62008-02-10 16:33:14 +0000203 if (invalidate) {
204 clear();
205 refresh();
206 curses_calc_pad();
Gerd Hoffmann1dbfa002013-03-12 13:44:38 +0100207 graphic_hw_invalidate(NULL);
balrog4d3b6f62008-02-10 16:33:14 +0000208 invalidate = 0;
209 }
210
Gerd Hoffmann1dbfa002013-03-12 13:44:38 +0100211 graphic_hw_text_update(NULL, screen);
balrog4d3b6f62008-02-10 16:33:14 +0000212
balrog4d3b6f62008-02-10 16:33:14 +0000213 while (1) {
214 /* while there are any pending key strokes to process */
Peter Maydell99a9ef42016-08-11 15:23:27 +0100215 chr = getch();
balrog4d3b6f62008-02-10 16:33:14 +0000216
217 if (chr == ERR)
218 break;
219
balrogb1314cf2008-02-22 18:21:28 +0000220#ifdef KEY_RESIZE
balrog4d3b6f62008-02-10 16:33:14 +0000221 /* this shouldn't occur when we use a custom SIGWINCH handler */
222 if (chr == KEY_RESIZE) {
223 clear();
224 refresh();
225 curses_calc_pad();
Gerd Hoffmannbc2ed972013-03-01 13:03:04 +0100226 curses_update(dcl, 0, 0, width, height);
balrog4d3b6f62008-02-10 16:33:14 +0000227 continue;
228 }
balrogb1314cf2008-02-22 18:21:28 +0000229#endif
balrog4d3b6f62008-02-10 16:33:14 +0000230
231 keycode = curses2keycode[chr];
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100232 keycode_alt = 0;
balrog4d3b6f62008-02-10 16:33:14 +0000233
234 /* alt key */
235 if (keycode == 1) {
Peter Maydell99a9ef42016-08-11 15:23:27 +0100236 int nextchr = getch();
balrog4d3b6f62008-02-10 16:33:14 +0000237
238 if (nextchr != ERR) {
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100239 chr = nextchr;
240 keycode_alt = ALT;
Peter Maydell99a9ef42016-08-11 15:23:27 +0100241 keycode = curses2keycode[chr];
balrog4d3b6f62008-02-10 16:33:14 +0000242
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100243 if (keycode != -1) {
244 keycode |= ALT;
balrog4d3b6f62008-02-10 16:33:14 +0000245
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100246 /* process keys reserved for qemu */
247 if (keycode >= QEMU_KEY_CONSOLE0 &&
248 keycode < QEMU_KEY_CONSOLE0 + 9) {
249 erase();
250 wnoutrefresh(stdscr);
251 console_select(keycode - QEMU_KEY_CONSOLE0);
balrog4d3b6f62008-02-10 16:33:14 +0000252
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100253 invalidate = 1;
254 continue;
255 }
balrog4d3b6f62008-02-10 16:33:14 +0000256 }
257 }
258 }
259
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100260 if (kbd_layout) {
261 keysym = -1;
262 if (chr < CURSES_KEYS)
263 keysym = curses2keysym[chr];
balrog4d3b6f62008-02-10 16:33:14 +0000264
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100265 if (keysym == -1) {
Samuel Thibaultd03703c2010-10-19 19:48:20 +0200266 if (chr < ' ') {
267 keysym = chr + '@';
268 if (keysym >= 'A' && keysym <= 'Z')
269 keysym += 'a' - 'A';
270 keysym |= KEYSYM_CNTRL;
271 } else
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100272 keysym = chr;
273 }
274
Gerd Hoffmannabb4f2c2018-02-22 08:05:13 +0100275 keycode = keysym2scancode(kbd_layout, keysym & KEYSYM_MASK,
276 false, false, false);
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100277 if (keycode == 0)
278 continue;
279
280 keycode |= (keysym & ~KEYSYM_MASK) >> 16;
281 keycode |= keycode_alt;
balrog4d3b6f62008-02-10 16:33:14 +0000282 }
283
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100284 if (keycode == -1)
285 continue;
286
Gerd Hoffmann81c0d5a2013-03-14 14:27:08 +0100287 if (qemu_console_is_graphic(NULL)) {
balrog4d3b6f62008-02-10 16:33:14 +0000288 /* since terminals don't know about key press and release
289 * events, we need to emit both for each key received */
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100290 if (keycode & SHIFT) {
291 qemu_input_event_send_key_number(NULL, SHIFT_CODE, true);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200292 qemu_input_event_send_key_delay(0);
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100293 }
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100294 if (keycode & CNTRL) {
295 qemu_input_event_send_key_number(NULL, CNTRL_CODE, true);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200296 qemu_input_event_send_key_delay(0);
Samuel Thibault44bb61c2010-02-28 21:03:00 +0100297 }
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100298 if (keycode & ALT) {
299 qemu_input_event_send_key_number(NULL, ALT_CODE, true);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200300 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100301 }
302 if (keycode & ALTGR) {
303 qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200304 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100305 }
306
Andrew Oatesf5c0ab12014-05-23 20:16:09 -0400307 qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, true);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200308 qemu_input_event_send_key_delay(0);
Andrew Oatesf5c0ab12014-05-23 20:16:09 -0400309 qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, false);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200310 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100311
312 if (keycode & ALTGR) {
313 qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200314 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100315 }
316 if (keycode & ALT) {
317 qemu_input_event_send_key_number(NULL, ALT_CODE, false);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200318 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100319 }
320 if (keycode & CNTRL) {
321 qemu_input_event_send_key_number(NULL, CNTRL_CODE, false);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200322 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100323 }
324 if (keycode & SHIFT) {
325 qemu_input_event_send_key_number(NULL, SHIFT_CODE, false);
Gerd Hoffmann5a165662014-05-28 13:05:04 +0200326 qemu_input_event_send_key_delay(0);
Gerd Hoffmanncd100322013-12-04 13:40:20 +0100327 }
balrog4d3b6f62008-02-10 16:33:14 +0000328 } else {
Peter Maydellbba4e1b2016-08-11 15:23:26 +0100329 keysym = -1;
330 if (chr < CURSES_KEYS) {
331 keysym = curses2qemu[chr];
332 }
balrog4d3b6f62008-02-10 16:33:14 +0000333 if (keysym == -1)
334 keysym = chr;
335
336 kbd_put_keysym(keysym);
337 }
338 }
339}
340
Blue Swirlaaf12c22010-03-21 19:44:06 +0000341static void curses_atexit(void)
balrog4d3b6f62008-02-10 16:33:14 +0000342{
343 endwin();
344}
345
balrog4d3b6f62008-02-10 16:33:14 +0000346static void curses_setup(void)
347{
348 int i, colour_default[8] = {
OGAWA Hirofumi40837332015-11-29 22:28:24 +0900349 [QEMU_COLOR_BLACK] = COLOR_BLACK,
350 [QEMU_COLOR_BLUE] = COLOR_BLUE,
351 [QEMU_COLOR_GREEN] = COLOR_GREEN,
352 [QEMU_COLOR_CYAN] = COLOR_CYAN,
353 [QEMU_COLOR_RED] = COLOR_RED,
354 [QEMU_COLOR_MAGENTA] = COLOR_MAGENTA,
355 [QEMU_COLOR_YELLOW] = COLOR_YELLOW,
356 [QEMU_COLOR_WHITE] = COLOR_WHITE,
balrog4d3b6f62008-02-10 16:33:14 +0000357 };
358
359 /* input as raw as possible, let everything be interpreted
360 * by the guest system */
361 initscr(); noecho(); intrflush(stdscr, FALSE);
362 nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
363 start_color(); raw(); scrollok(stdscr, FALSE);
364
OGAWA Hirofumi40837332015-11-29 22:28:24 +0900365 /* Make color pair to match color format (3bits bg:3bits fg) */
OGAWA Hirofumi615220d2015-10-19 21:23:10 +0900366 for (i = 0; i < 64; i++) {
balrog4d3b6f62008-02-10 16:33:14 +0000367 init_pair(i, colour_default[i & 7], colour_default[i >> 3]);
OGAWA Hirofumi615220d2015-10-19 21:23:10 +0900368 }
OGAWA Hirofumi40837332015-11-29 22:28:24 +0900369 /* Set default color for more than 64 for safety. */
OGAWA Hirofumi615220d2015-10-19 21:23:10 +0900370 for (i = 64; i < COLOR_PAIRS; i++) {
371 init_pair(i, COLOR_WHITE, COLOR_BLACK);
372 }
OGAWA Hirofumie2368dc2015-10-19 21:23:46 +0900373
374 /*
375 * Setup mapping for vga to curses line graphics.
376 * FIXME: for better font, have to use ncursesw and setlocale()
377 */
378#if 0
379 /* FIXME: map from where? */
380 ACS_S1;
381 ACS_S3;
382 ACS_S7;
383 ACS_S9;
384#endif
385 /* ACS_* is not constant. So, we can't initialize statically. */
386 vga_to_curses['\0'] = ' ';
387 vga_to_curses[0x04] = ACS_DIAMOND;
OGAWA Hirofumie2368dc2015-10-19 21:23:46 +0900388 vga_to_curses[0x18] = ACS_UARROW;
389 vga_to_curses[0x19] = ACS_DARROW;
Samuel Thibault697783a2016-10-15 21:53:04 +0200390 vga_to_curses[0x1a] = ACS_RARROW;
391 vga_to_curses[0x1b] = ACS_LARROW;
OGAWA Hirofumie2368dc2015-10-19 21:23:46 +0900392 vga_to_curses[0x9c] = ACS_STERLING;
393 vga_to_curses[0xb0] = ACS_BOARD;
394 vga_to_curses[0xb1] = ACS_CKBOARD;
395 vga_to_curses[0xb3] = ACS_VLINE;
396 vga_to_curses[0xb4] = ACS_RTEE;
397 vga_to_curses[0xbf] = ACS_URCORNER;
398 vga_to_curses[0xc0] = ACS_LLCORNER;
399 vga_to_curses[0xc1] = ACS_BTEE;
400 vga_to_curses[0xc2] = ACS_TTEE;
401 vga_to_curses[0xc3] = ACS_LTEE;
402 vga_to_curses[0xc4] = ACS_HLINE;
403 vga_to_curses[0xc5] = ACS_PLUS;
404 vga_to_curses[0xce] = ACS_LANTERN;
405 vga_to_curses[0xd8] = ACS_NEQUAL;
406 vga_to_curses[0xd9] = ACS_LRCORNER;
407 vga_to_curses[0xda] = ACS_ULCORNER;
408 vga_to_curses[0xdb] = ACS_BLOCK;
409 vga_to_curses[0xe3] = ACS_PI;
410 vga_to_curses[0xf1] = ACS_PLMINUS;
411 vga_to_curses[0xf2] = ACS_GEQUAL;
412 vga_to_curses[0xf3] = ACS_LEQUAL;
413 vga_to_curses[0xf8] = ACS_DEGREE;
414 vga_to_curses[0xfe] = ACS_BULLET;
balrog4d3b6f62008-02-10 16:33:14 +0000415}
416
417static void curses_keyboard_setup(void)
418{
balrog4d3b6f62008-02-10 16:33:14 +0000419#if defined(__APPLE__)
420 /* always use generic keymaps */
421 if (!keyboard_layout)
422 keyboard_layout = "en-us";
423#endif
424 if(keyboard_layout) {
Fei Liab4f9312018-10-17 10:26:50 +0200425 kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout,
426 &error_fatal);
balrog4d3b6f62008-02-10 16:33:14 +0000427 }
balrog4d3b6f62008-02-10 16:33:14 +0000428}
429
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100430static const DisplayChangeListenerOps dcl_ops = {
431 .dpy_name = "curses",
432 .dpy_text_update = curses_update,
433 .dpy_text_resize = curses_resize,
434 .dpy_refresh = curses_refresh,
435 .dpy_text_cursor = curses_cursor_position,
436};
437
Gerd Hoffmannb0766612018-03-01 11:05:38 +0100438static void curses_display_init(DisplayState *ds, DisplayOptions *opts)
balrog4d3b6f62008-02-10 16:33:14 +0000439{
440#ifndef _WIN32
441 if (!isatty(1)) {
442 fprintf(stderr, "We need a terminal output\n");
443 exit(1);
444 }
445#endif
446
447 curses_setup();
448 curses_keyboard_setup();
Anthony Liguori28695482010-03-21 14:13:02 -0500449 atexit(curses_atexit);
balrog4d3b6f62008-02-10 16:33:14 +0000450
Gerd Hoffmann032ac6f2013-11-22 15:35:03 +0100451 curses_winch_init();
balrog4d3b6f62008-02-10 16:33:14 +0000452
Markus Armbrusterfedf0d32015-11-03 17:12:03 +0100453 dcl = g_new0(DisplayChangeListener, 1);
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100454 dcl->ops = &dcl_ops;
Gerd Hoffmann52090892013-04-23 15:44:31 +0200455 register_displaychangelistener(dcl);
balrog4d3b6f62008-02-10 16:33:14 +0000456
457 invalidate = 1;
balrog4d3b6f62008-02-10 16:33:14 +0000458}
Gerd Hoffmannb0766612018-03-01 11:05:38 +0100459
460static QemuDisplay qemu_display_curses = {
461 .type = DISPLAY_TYPE_CURSES,
462 .init = curses_display_init,
463};
464
465static void register_curses(void)
466{
467 qemu_display_register(&qemu_display_curses);
468}
469
470type_init(register_curses);