* lisp/emacs-lisp/backquote.el: Fix bug with unoptimized exp.
[emacs.git] / src / w32console.c
bloba38a558c22696356abde96371450859f6347552d
1 /* Terminal hooks for GNU Emacs on the Microsoft Windows API.
2 Copyright (C) 1992, 1999, 2001-2015 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 Tim Fleehart (apollo@online.com) 1-17-92
21 Geoff Voelker (voelker@cs.washington.edu) 9-12-93
25 #include <config.h>
27 #include <stdio.h>
28 #include <windows.h>
30 #include "lisp.h"
31 #include "character.h"
32 #include "coding.h"
33 #include "disptab.h"
34 #include "frame.h"
35 #include "window.h"
36 #include "termhooks.h"
37 #include "termchar.h"
38 #include "dispextern.h"
39 #include "menu.h" /* for tty_menu_show */
40 #include "w32term.h"
41 #include "w32common.h" /* for os_subtype */
42 #include "w32inevt.h"
44 /* from window.c */
45 extern Lisp_Object Frecenter (Lisp_Object);
47 static void w32con_move_cursor (struct frame *f, int row, int col);
48 static void w32con_clear_to_end (struct frame *f);
49 static void w32con_clear_frame (struct frame *f);
50 static void w32con_clear_end_of_line (struct frame *f, int);
51 static void w32con_ins_del_lines (struct frame *f, int vpos, int n);
52 static void w32con_insert_glyphs (struct frame *f, struct glyph *start, int len);
53 static void w32con_write_glyphs (struct frame *f, struct glyph *string, int len);
54 static void w32con_delete_glyphs (struct frame *f, int n);
55 static void w32con_reset_terminal_modes (struct terminal *t);
56 static void w32con_set_terminal_modes (struct terminal *t);
57 static void w32con_update_begin (struct frame * f);
58 static void w32con_update_end (struct frame * f);
59 static WORD w32_face_attributes (struct frame *f, int face_id);
61 static COORD cursor_coords;
62 static HANDLE prev_screen, cur_screen;
63 static WORD char_attr_normal;
64 static DWORD prev_console_mode;
66 static CONSOLE_CURSOR_INFO console_cursor_info;
67 #ifndef USE_SEPARATE_SCREEN
68 static CONSOLE_CURSOR_INFO prev_console_cursor;
69 #endif
71 HANDLE keyboard_handle;
72 int w32_console_unicode_input;
75 /* Setting this as the ctrl handler prevents emacs from being killed when
76 someone hits ^C in a 'suspended' session (child shell).
77 Also ignore Ctrl-Break signals. */
79 BOOL
80 ctrl_c_handler (unsigned long type)
82 /* Only ignore "interrupt" events when running interactively. */
83 return (!noninteractive
84 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT));
88 /* Move the cursor to (ROW, COL) on FRAME. */
89 static void
90 w32con_move_cursor (struct frame *f, int row, int col)
92 cursor_coords.X = col;
93 cursor_coords.Y = row;
95 /* TODO: for multi-tty support, cur_screen should be replaced with a
96 reference to the terminal for this frame. */
97 SetConsoleCursorPosition (cur_screen, cursor_coords);
100 void
101 w32con_hide_cursor (void)
103 GetConsoleCursorInfo (cur_screen, &console_cursor_info);
104 console_cursor_info.bVisible = FALSE;
105 SetConsoleCursorInfo (cur_screen, &console_cursor_info);
108 void
109 w32con_show_cursor (void)
111 GetConsoleCursorInfo (cur_screen, &console_cursor_info);
112 console_cursor_info.bVisible = TRUE;
113 SetConsoleCursorInfo (cur_screen, &console_cursor_info);
116 /* Clear from cursor to end of screen. */
117 static void
118 w32con_clear_to_end (struct frame *f)
120 w32con_clear_end_of_line (f, FRAME_COLS (f) - 1);
121 w32con_ins_del_lines (f, cursor_coords.Y, FRAME_TOTAL_LINES (f) - cursor_coords.Y - 1);
124 /* Clear the frame. */
125 static void
126 w32con_clear_frame (struct frame *f)
128 COORD dest;
129 int n;
130 DWORD r;
131 CONSOLE_SCREEN_BUFFER_INFO info;
133 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info);
135 /* Remember that the screen buffer might be wider than the window. */
136 n = FRAME_TOTAL_LINES (f) * info.dwSize.X;
137 dest.X = dest.Y = 0;
139 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
140 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
142 w32con_move_cursor (f, 0, 0);
146 static struct glyph glyph_base[256];
147 static BOOL ceol_initialized = FALSE;
149 /* Clear from Cursor to end (what's "standout marker"?). */
150 static void
151 w32con_clear_end_of_line (struct frame *f, int end)
153 if (!ceol_initialized)
155 int i;
156 for (i = 0; i < 256; i++)
158 memcpy (&glyph_base[i], &space_glyph, sizeof (struct glyph));
160 ceol_initialized = TRUE;
162 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */
165 /* Insert n lines at vpos. if n is negative delete -n lines. */
166 static void
167 w32con_ins_del_lines (struct frame *f, int vpos, int n)
169 int i, nb;
170 SMALL_RECT scroll;
171 SMALL_RECT clip;
172 COORD dest;
173 CHAR_INFO fill;
175 if (n < 0)
177 scroll.Top = vpos - n;
178 scroll.Bottom = FRAME_TOTAL_LINES (f);
179 dest.Y = vpos;
181 else
183 scroll.Top = vpos;
184 scroll.Bottom = FRAME_TOTAL_LINES (f) - n;
185 dest.Y = vpos + n;
187 clip.Top = clip.Left = scroll.Left = 0;
188 clip.Right = scroll.Right = FRAME_COLS (f);
189 clip.Bottom = FRAME_TOTAL_LINES (f);
191 dest.X = 0;
193 fill.Char.AsciiChar = 0x20;
194 fill.Attributes = char_attr_normal;
196 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
198 /* Here we have to deal with a w32 console flake: If the scroll
199 region looks like abc and we scroll c to a and fill with d we get
200 cbd... if we scroll block c one line at a time to a, we get cdd...
201 Emacs expects cdd consistently... So we have to deal with that
202 here... (this also occurs scrolling the same way in the other
203 direction. */
205 if (n > 0)
207 if (scroll.Bottom < dest.Y)
209 for (i = scroll.Bottom; i < dest.Y; i++)
211 w32con_move_cursor (f, i, 0);
212 w32con_clear_end_of_line (f, FRAME_COLS (f));
216 else
218 nb = dest.Y + (scroll.Bottom - scroll.Top) + 1;
220 if (nb < scroll.Top)
222 for (i = nb; i < scroll.Top; i++)
224 w32con_move_cursor (f, i, 0);
225 w32con_clear_end_of_line (f, FRAME_COLS (f));
230 cursor_coords.X = 0;
231 cursor_coords.Y = vpos;
234 #undef LEFT
235 #undef RIGHT
236 #define LEFT 1
237 #define RIGHT 0
239 static void
240 scroll_line (struct frame *f, int dist, int direction)
242 /* The idea here is to implement a horizontal scroll in one line to
243 implement delete and half of insert. */
244 SMALL_RECT scroll, clip;
245 COORD dest;
246 CHAR_INFO fill;
248 clip.Top = scroll.Top = clip.Bottom = scroll.Bottom = cursor_coords.Y;
249 clip.Left = 0;
250 clip.Right = FRAME_COLS (f);
252 if (direction == LEFT)
254 scroll.Left = cursor_coords.X + dist;
255 scroll.Right = FRAME_COLS (f) - 1;
257 else
259 scroll.Left = cursor_coords.X;
260 scroll.Right = FRAME_COLS (f) - dist - 1;
263 dest.X = cursor_coords.X;
264 dest.Y = cursor_coords.Y;
266 fill.Char.AsciiChar = 0x20;
267 fill.Attributes = char_attr_normal;
269 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
273 /* If start is zero insert blanks instead of a string at start ?. */
274 static void
275 w32con_insert_glyphs (struct frame *f, register struct glyph *start,
276 register int len)
278 scroll_line (f, len, RIGHT);
280 /* Move len chars to the right starting at cursor_coords, fill with blanks */
281 if (start)
283 /* Print the first len characters of start, cursor_coords.X adjusted
284 by write_glyphs. */
286 w32con_write_glyphs (f, start, len);
288 else
290 w32con_clear_end_of_line (f, cursor_coords.X + len);
294 static void
295 w32con_write_glyphs (struct frame *f, register struct glyph *string,
296 register int len)
298 DWORD r;
299 WORD char_attr;
300 unsigned char *conversion_buffer;
301 struct coding_system *coding;
303 if (len <= 0)
304 return;
306 /* If terminal_coding does any conversion, use it, otherwise use
307 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
308 because it always return 1 if the member src_multibyte is 1. */
309 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
310 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
311 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
312 the tail. */
313 coding->mode &= ~CODING_MODE_LAST_BLOCK;
315 while (len > 0)
317 /* Identify a run of glyphs with the same face. */
318 int face_id = string->face_id;
319 int n;
321 for (n = 1; n < len; ++n)
322 if (string[n].face_id != face_id)
323 break;
325 /* Turn appearance modes of the face of the run on. */
326 char_attr = w32_face_attributes (f, face_id);
328 if (n == len)
329 /* This is the last run. */
330 coding->mode |= CODING_MODE_LAST_BLOCK;
331 conversion_buffer = encode_terminal_code (string, n, coding);
332 if (coding->produced > 0)
334 /* Set the attribute for these characters. */
335 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
336 coding->produced, cursor_coords,
337 &r))
339 printf ("Failed writing console attributes: %d\n",
340 GetLastError ());
341 fflush (stdout);
344 /* Write the characters. */
345 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
346 coding->produced, cursor_coords,
347 &r))
349 printf ("Failed writing console characters: %d\n",
350 GetLastError ());
351 fflush (stdout);
354 cursor_coords.X += coding->produced;
355 w32con_move_cursor (f, cursor_coords.Y, cursor_coords.X);
357 len -= n;
358 string += n;
362 /* Used for mouse highlight. */
363 static void
364 w32con_write_glyphs_with_face (struct frame *f, register int x, register int y,
365 register struct glyph *string, register int len,
366 register int face_id)
368 unsigned char *conversion_buffer;
369 struct coding_system *coding;
371 if (len <= 0)
372 return;
374 /* If terminal_coding does any conversion, use it, otherwise use
375 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
376 because it always return 1 if the member src_multibyte is 1. */
377 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
378 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
379 /* We are going to write the entire block of glyphs in one go, as
380 they all have the same face. So this _is_ the last block. */
381 coding->mode |= CODING_MODE_LAST_BLOCK;
383 conversion_buffer = encode_terminal_code (string, len, coding);
384 if (coding->produced > 0)
386 DWORD filled, written;
387 /* Compute the character attributes corresponding to the face. */
388 DWORD char_attr = w32_face_attributes (f, face_id);
389 COORD start_coords;
391 start_coords.X = x;
392 start_coords.Y = y;
393 /* Set the attribute for these characters. */
394 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
395 coding->produced, start_coords,
396 &filled))
397 DebPrint (("Failed writing console attributes: %d\n", GetLastError ()));
398 else
400 /* Write the characters. */
401 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
402 filled, start_coords, &written))
403 DebPrint (("Failed writing console characters: %d\n",
404 GetLastError ()));
409 /* Implementation of draw_row_with_mouse_face for W32 console. */
410 void
411 tty_draw_row_with_mouse_face (struct window *w, struct glyph_row *row,
412 int start_hpos, int end_hpos,
413 enum draw_glyphs_face draw)
415 int nglyphs = end_hpos - start_hpos;
416 struct frame *f = XFRAME (WINDOW_FRAME (w));
417 struct tty_display_info *tty = FRAME_TTY (f);
418 int face_id = tty->mouse_highlight.mouse_face_face_id;
419 int pos_x, pos_y;
421 if (end_hpos >= row->used[TEXT_AREA])
422 nglyphs = row->used[TEXT_AREA] - start_hpos;
424 pos_y = row->y + WINDOW_TOP_EDGE_Y (w);
425 pos_x = row->used[LEFT_MARGIN_AREA] + start_hpos + WINDOW_LEFT_EDGE_X (w);
427 if (draw == DRAW_MOUSE_FACE)
428 w32con_write_glyphs_with_face (f, pos_x, pos_y,
429 row->glyphs[TEXT_AREA] + start_hpos,
430 nglyphs, face_id);
431 else if (draw == DRAW_NORMAL_TEXT)
433 COORD save_coords = cursor_coords;
435 w32con_move_cursor (f, pos_y, pos_x);
436 write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs);
437 w32con_move_cursor (f, save_coords.Y, save_coords.X);
441 static void
442 w32con_delete_glyphs (struct frame *f, int n)
444 /* delete chars means scroll chars from cursor_coords.X + n to
445 cursor_coords.X, anything beyond the edge of the screen should
446 come out empty... */
448 scroll_line (f, n, LEFT);
452 static void
453 w32con_reset_terminal_modes (struct terminal *t)
455 COORD dest;
456 CONSOLE_SCREEN_BUFFER_INFO info;
457 int n;
458 DWORD r;
460 /* Clear the complete screen buffer. This is required because Emacs
461 sets the cursor position to the top of the buffer, but there might
462 be other output below the bottom of the Emacs frame if the screen buffer
463 is larger than the window size. */
464 GetConsoleScreenBufferInfo (cur_screen, &info);
465 dest.X = 0;
466 dest.Y = 0;
467 n = info.dwSize.X * info.dwSize.Y;
469 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
470 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
471 /* Now that the screen is clear, put the cursor at the top. */
472 SetConsoleCursorPosition (cur_screen, dest);
474 #ifdef USE_SEPARATE_SCREEN
475 SetConsoleActiveScreenBuffer (prev_screen);
476 #else
477 SetConsoleCursorInfo (prev_screen, &prev_console_cursor);
478 #endif
480 SetConsoleMode (keyboard_handle, prev_console_mode);
483 static void
484 w32con_set_terminal_modes (struct terminal *t)
486 CONSOLE_CURSOR_INFO cci;
488 /* make cursor big and visible (100 on Windows 95 makes it disappear) */
489 cci.dwSize = 99;
490 cci.bVisible = TRUE;
491 (void) SetConsoleCursorInfo (cur_screen, &cci);
493 SetConsoleActiveScreenBuffer (cur_screen);
495 SetConsoleMode (keyboard_handle, ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
497 /* Initialize input mode: interrupt_input off, no flow control, allow
498 8 bit character input, standard quit char. */
499 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
502 /* hmmm... perhaps these let us bracket screen changes so that we can flush
503 clumps rather than one-character-at-a-time...
505 we'll start with not moving the cursor while an update is in progress. */
506 static void
507 w32con_update_begin (struct frame * f)
511 static void
512 w32con_update_end (struct frame * f)
514 SetConsoleCursorPosition (cur_screen, cursor_coords);
517 /***********************************************************************
518 stubs from termcap.c
519 ***********************************************************************/
521 void
522 sys_tputs (char *str, int nlines, int (*outfun) (int))
526 char *
527 sys_tgetstr (char *cap, char **area)
529 return NULL;
533 /***********************************************************************
534 stubs from cm.c
535 ***********************************************************************/
537 struct tty_display_info *current_tty = NULL;
538 int cost = 0;
541 evalcost (int c)
543 return c;
547 cmputc (int c)
549 return c;
552 void
553 cmcheckmagic (struct tty_display_info *tty)
557 void
558 cmcostinit (struct tty_display_info *tty)
562 void
563 cmgoto (struct tty_display_info *tty, int row, int col)
567 void
568 Wcm_clear (struct tty_display_info *tty)
573 /* Report the current cursor position. The following two functions
574 are used in term.c's tty menu code, so they are not really
575 "stubs". */
577 cursorX (struct tty_display_info *tty)
579 return cursor_coords.X;
583 cursorY (struct tty_display_info *tty)
585 return cursor_coords.Y;
588 /***********************************************************************
589 Faces
590 ***********************************************************************/
593 /* Turn appearances of face FACE_ID on tty frame F on. */
595 static WORD
596 w32_face_attributes (struct frame *f, int face_id)
598 WORD char_attr;
599 struct face *face = FACE_FROM_ID (f, face_id);
601 eassert (face != NULL);
603 char_attr = char_attr_normal;
605 /* Reverse the default color if requested. If background and
606 foreground are specified, then they have been reversed already. */
607 if (face->tty_reverse_p)
608 char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4)
609 + ((char_attr & 0x00f0) >> 4);
611 /* Before the terminal is properly initialized, all colors map to 0.
612 Don't try to resolve them. */
613 if (NILP (Vtty_defined_color_alist))
614 return char_attr;
616 /* Colors should be in the range 0...15 unless they are one of
617 FACE_TTY_DEFAULT_COLOR, FACE_TTY_DEFAULT_FG_COLOR or
618 FACE_TTY_DEFAULT_BG_COLOR. Other out of range colors are
619 invalid, so it is better to use the default color if they ever
620 get through to here. */
621 if (face->foreground >= 0 && face->foreground < 16)
622 char_attr = (char_attr & 0xfff0) + face->foreground;
624 if (face->background >= 0 && face->background < 16)
625 char_attr = (char_attr & 0xff0f) + (face->background << 4);
627 return char_attr;
630 void
631 initialize_w32_display (struct terminal *term, int *width, int *height)
633 CONSOLE_SCREEN_BUFFER_INFO info;
635 term->rif = 0; /* No window based redisplay on the console. */
636 term->cursor_to_hook = w32con_move_cursor;
637 term->raw_cursor_to_hook = w32con_move_cursor;
638 term->clear_to_end_hook = w32con_clear_to_end;
639 term->clear_frame_hook = w32con_clear_frame;
640 term->clear_end_of_line_hook = w32con_clear_end_of_line;
641 term->ins_del_lines_hook = w32con_ins_del_lines;
642 term->insert_glyphs_hook = w32con_insert_glyphs;
643 term->write_glyphs_hook = w32con_write_glyphs;
644 term->delete_glyphs_hook = w32con_delete_glyphs;
645 term->ring_bell_hook = w32_sys_ring_bell;
646 term->reset_terminal_modes_hook = w32con_reset_terminal_modes;
647 term->set_terminal_modes_hook = w32con_set_terminal_modes;
648 term->set_terminal_window_hook = NULL;
649 term->update_begin_hook = w32con_update_begin;
650 term->update_end_hook = w32con_update_end;
652 term->read_socket_hook = w32_console_read_socket;
653 term->mouse_position_hook = w32_console_mouse_position;
654 term->menu_show_hook = tty_menu_show;
656 /* The following are not used on the console. */
657 term->frame_rehighlight_hook = 0;
658 term->frame_raise_lower_hook = 0;
659 term->set_vertical_scroll_bar_hook = 0;
660 term->set_horizontal_scroll_bar_hook = 0;
661 term->condemn_scroll_bars_hook = 0;
662 term->redeem_scroll_bar_hook = 0;
663 term->judge_scroll_bars_hook = 0;
664 term->frame_up_to_date_hook = 0;
666 /* Initialize the mouse-highlight data. */
667 reset_mouse_highlight (&term->display_info.tty->mouse_highlight);
669 /* Initialize interrupt_handle. */
670 init_crit ();
672 /* Remember original console settings. */
673 keyboard_handle = GetStdHandle (STD_INPUT_HANDLE);
674 GetConsoleMode (keyboard_handle, &prev_console_mode);
676 prev_screen = GetStdHandle (STD_OUTPUT_HANDLE);
678 #ifdef USE_SEPARATE_SCREEN
679 cur_screen = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE,
680 0, NULL,
681 CONSOLE_TEXTMODE_BUFFER,
682 NULL);
684 if (cur_screen == INVALID_HANDLE_VALUE)
686 printf ("CreateConsoleScreenBuffer failed in ResetTerm\n");
687 printf ("LastError = 0x%lx\n", GetLastError ());
688 fflush (stdout);
689 exit (0);
691 #else
692 cur_screen = prev_screen;
693 GetConsoleCursorInfo (prev_screen, &prev_console_cursor);
694 #endif
696 /* Respect setting of LINES and COLUMNS environment variables. */
698 char * lines = getenv ("LINES");
699 char * columns = getenv ("COLUMNS");
701 if (lines != NULL && columns != NULL)
703 SMALL_RECT new_win_dims;
704 COORD new_size;
706 new_size.X = atoi (columns);
707 new_size.Y = atoi (lines);
709 GetConsoleScreenBufferInfo (cur_screen, &info);
711 /* Shrink the window first, so the buffer dimensions can be
712 reduced if necessary. */
713 new_win_dims.Top = 0;
714 new_win_dims.Left = 0;
715 new_win_dims.Bottom = min (new_size.Y, info.dwSize.Y) - 1;
716 new_win_dims.Right = min (new_size.X, info.dwSize.X) - 1;
717 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
719 SetConsoleScreenBufferSize (cur_screen, new_size);
721 /* Set the window size to match the buffer dimension. */
722 new_win_dims.Top = 0;
723 new_win_dims.Left = 0;
724 new_win_dims.Bottom = new_size.Y - 1;
725 new_win_dims.Right = new_size.X - 1;
726 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
730 GetConsoleScreenBufferInfo (cur_screen, &info);
732 char_attr_normal = info.wAttributes;
734 /* Determine if the info returned by GetConsoleScreenBufferInfo
735 is realistic. Old MS Telnet servers used to only fill out
736 the dwSize portion, even modern one fill the whole struct with
737 garbage when using non-MS telnet clients. */
738 if ((w32_use_full_screen_buffer
739 && (info.dwSize.Y < 20 || info.dwSize.Y > 100
740 || info.dwSize.X < 40 || info.dwSize.X > 200))
741 || (!w32_use_full_screen_buffer
742 && (info.srWindow.Bottom - info.srWindow.Top < 20
743 || info.srWindow.Bottom - info.srWindow.Top > 100
744 || info.srWindow.Right - info.srWindow.Left < 40
745 || info.srWindow.Right - info.srWindow.Left > 100)))
747 *height = 25;
748 *width = 80;
751 else if (w32_use_full_screen_buffer)
753 *height = info.dwSize.Y; /* lines per page */
754 *width = info.dwSize.X; /* characters per line */
756 else
758 /* Lines per page. Use buffer coords instead of buffer size. */
759 *height = 1 + info.srWindow.Bottom - info.srWindow.Top;
760 /* Characters per line. Use buffer coords instead of buffer size. */
761 *width = 1 + info.srWindow.Right - info.srWindow.Left;
764 if (os_subtype == OS_NT)
765 w32_console_unicode_input = 1;
766 else
767 w32_console_unicode_input = 0;
769 /* This is needed by w32notify.c:send_notifications. */
770 dwMainThreadId = GetCurrentThreadId ();
772 /* Setup w32_display_info structure for this frame. */
774 w32_initialize_display_info (build_string ("Console"));
779 DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0,
780 doc: /* Set screen foreground and background colors.
782 Arguments should be indices between 0 and 15, see w32console.el. */)
783 (Lisp_Object foreground, Lisp_Object background)
785 char_attr_normal = XFASTINT (foreground) + (XFASTINT (background) << 4);
787 Frecenter (Qnil);
788 return Qt;
791 DEFUN ("get-screen-color", Fget_screen_color, Sget_screen_color, 0, 0, 0,
792 doc: /* Get color indices of the current screen foreground and background.
794 The colors are returned as a list of 2 indices (FOREGROUND BACKGROUND).
795 See w32console.el and `tty-defined-color-alist' for mapping of indices
796 to colors. */)
797 (void)
799 return Fcons (make_number (char_attr_normal & 0x000f),
800 Fcons (make_number ((char_attr_normal >> 4) & 0x000f), Qnil));
803 DEFUN ("set-cursor-size", Fset_cursor_size, Sset_cursor_size, 1, 1, 0,
804 doc: /* Set cursor size. */)
805 (Lisp_Object size)
807 CONSOLE_CURSOR_INFO cci;
808 cci.dwSize = XFASTINT (size);
809 cci.bVisible = TRUE;
810 (void) SetConsoleCursorInfo (cur_screen, &cci);
812 return Qt;
815 void
816 syms_of_ntterm (void)
818 DEFVAR_BOOL ("w32-use-full-screen-buffer",
819 w32_use_full_screen_buffer,
820 doc: /* Non-nil means make terminal frames use the full screen buffer dimensions.
821 This is desirable when running Emacs over telnet.
822 A value of nil means use the current console window dimensions; this
823 may be preferable when working directly at the console with a large
824 scroll-back buffer. */);
825 w32_use_full_screen_buffer = 0;
827 defsubr (&Sset_screen_color);
828 defsubr (&Sget_screen_color);
829 defsubr (&Sset_cursor_size);