Implement cygw32
[emacs.git] / src / w32console.c
blob76b7bb0b4513bce075880451cd0a1be9a5532a7b
1 /* Terminal hooks for GNU Emacs on the Microsoft Windows API.
2 Copyright (C) 1992, 1999, 2001-2012 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>
29 #include <setjmp.h>
31 #include "lisp.h"
32 #include "character.h"
33 #include "coding.h"
34 #include "disptab.h"
35 #include "frame.h"
36 #include "window.h"
37 #include "termhooks.h"
38 #include "termchar.h"
39 #include "dispextern.h"
40 #include "w32term.h"
41 #include "w32heap.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_set_terminal_window (struct frame *f, int size);
58 static void w32con_update_begin (struct frame * f);
59 static void w32con_update_end (struct frame * f);
60 static WORD w32_face_attributes (struct frame *f, int face_id);
62 static COORD cursor_coords;
63 static HANDLE prev_screen, cur_screen;
64 static WORD char_attr_normal;
65 static DWORD prev_console_mode;
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 /* Clear from cursor to end of screen. */
101 static void
102 w32con_clear_to_end (struct frame *f)
104 w32con_clear_end_of_line (f, FRAME_COLS (f) - 1);
105 w32con_ins_del_lines (f, cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
108 /* Clear the frame. */
109 static void
110 w32con_clear_frame (struct frame *f)
112 COORD dest;
113 int n;
114 DWORD r;
115 CONSOLE_SCREEN_BUFFER_INFO info;
117 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info);
119 /* Remember that the screen buffer might be wider than the window. */
120 n = FRAME_LINES (f) * info.dwSize.X;
121 dest.X = dest.Y = 0;
123 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
124 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
126 w32con_move_cursor (f, 0, 0);
130 static struct glyph glyph_base[256];
131 static BOOL ceol_initialized = FALSE;
133 /* Clear from Cursor to end (what's "standout marker"?). */
134 static void
135 w32con_clear_end_of_line (struct frame *f, int end)
137 if (!ceol_initialized)
139 int i;
140 for (i = 0; i < 256; i++)
142 memcpy (&glyph_base[i], &space_glyph, sizeof (struct glyph));
144 ceol_initialized = TRUE;
146 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */
149 /* Insert n lines at vpos. if n is negative delete -n lines. */
150 static void
151 w32con_ins_del_lines (struct frame *f, int vpos, int n)
153 int i, nb;
154 SMALL_RECT scroll;
155 SMALL_RECT clip;
156 COORD dest;
157 CHAR_INFO fill;
159 if (n < 0)
161 scroll.Top = vpos - n;
162 scroll.Bottom = FRAME_LINES (f);
163 dest.Y = vpos;
165 else
167 scroll.Top = vpos;
168 scroll.Bottom = FRAME_LINES (f) - n;
169 dest.Y = vpos + n;
171 clip.Top = clip.Left = scroll.Left = 0;
172 clip.Right = scroll.Right = FRAME_COLS (f);
173 clip.Bottom = FRAME_LINES (f);
175 dest.X = 0;
177 fill.Char.AsciiChar = 0x20;
178 fill.Attributes = char_attr_normal;
180 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
182 /* Here we have to deal with a w32 console flake: If the scroll
183 region looks like abc and we scroll c to a and fill with d we get
184 cbd... if we scroll block c one line at a time to a, we get cdd...
185 Emacs expects cdd consistently... So we have to deal with that
186 here... (this also occurs scrolling the same way in the other
187 direction. */
189 if (n > 0)
191 if (scroll.Bottom < dest.Y)
193 for (i = scroll.Bottom; i < dest.Y; i++)
195 w32con_move_cursor (f, i, 0);
196 w32con_clear_end_of_line (f, FRAME_COLS (f));
200 else
202 nb = dest.Y + (scroll.Bottom - scroll.Top) + 1;
204 if (nb < scroll.Top)
206 for (i = nb; i < scroll.Top; i++)
208 w32con_move_cursor (f, i, 0);
209 w32con_clear_end_of_line (f, FRAME_COLS (f));
214 cursor_coords.X = 0;
215 cursor_coords.Y = vpos;
218 #undef LEFT
219 #undef RIGHT
220 #define LEFT 1
221 #define RIGHT 0
223 static void
224 scroll_line (struct frame *f, int dist, int direction)
226 /* The idea here is to implement a horizontal scroll in one line to
227 implement delete and half of insert. */
228 SMALL_RECT scroll, clip;
229 COORD dest;
230 CHAR_INFO fill;
232 clip.Top = scroll.Top = clip.Bottom = scroll.Bottom = cursor_coords.Y;
233 clip.Left = 0;
234 clip.Right = FRAME_COLS (f);
236 if (direction == LEFT)
238 scroll.Left = cursor_coords.X + dist;
239 scroll.Right = FRAME_COLS (f) - 1;
241 else
243 scroll.Left = cursor_coords.X;
244 scroll.Right = FRAME_COLS (f) - dist - 1;
247 dest.X = cursor_coords.X;
248 dest.Y = cursor_coords.Y;
250 fill.Char.AsciiChar = 0x20;
251 fill.Attributes = char_attr_normal;
253 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
257 /* If start is zero insert blanks instead of a string at start ?. */
258 static void
259 w32con_insert_glyphs (struct frame *f, register struct glyph *start,
260 register int len)
262 scroll_line (f, len, RIGHT);
264 /* Move len chars to the right starting at cursor_coords, fill with blanks */
265 if (start)
267 /* Print the first len characters of start, cursor_coords.X adjusted
268 by write_glyphs. */
270 w32con_write_glyphs (f, start, len);
272 else
274 w32con_clear_end_of_line (f, cursor_coords.X + len);
278 static void
279 w32con_write_glyphs (struct frame *f, register struct glyph *string,
280 register int len)
282 DWORD r;
283 WORD char_attr;
284 unsigned char *conversion_buffer;
285 struct coding_system *coding;
287 if (len <= 0)
288 return;
290 /* If terminal_coding does any conversion, use it, otherwise use
291 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
292 because it always return 1 if the member src_multibyte is 1. */
293 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
294 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
295 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
296 the tail. */
297 coding->mode &= ~CODING_MODE_LAST_BLOCK;
299 while (len > 0)
301 /* Identify a run of glyphs with the same face. */
302 int face_id = string->face_id;
303 int n;
305 for (n = 1; n < len; ++n)
306 if (string[n].face_id != face_id)
307 break;
309 /* Turn appearance modes of the face of the run on. */
310 char_attr = w32_face_attributes (f, face_id);
312 if (n == len)
313 /* This is the last run. */
314 coding->mode |= CODING_MODE_LAST_BLOCK;
315 conversion_buffer = encode_terminal_code (string, n, coding);
316 if (coding->produced > 0)
318 /* Set the attribute for these characters. */
319 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
320 coding->produced, cursor_coords,
321 &r))
323 printf ("Failed writing console attributes: %d\n",
324 GetLastError ());
325 fflush (stdout);
328 /* Write the characters. */
329 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
330 coding->produced, cursor_coords,
331 &r))
333 printf ("Failed writing console characters: %d\n",
334 GetLastError ());
335 fflush (stdout);
338 cursor_coords.X += coding->produced;
339 w32con_move_cursor (f, cursor_coords.Y, cursor_coords.X);
341 len -= n;
342 string += n;
346 /* Used for mouse highlight. */
347 static void
348 w32con_write_glyphs_with_face (struct frame *f, register int x, register int y,
349 register struct glyph *string, register int len,
350 register int face_id)
352 unsigned char *conversion_buffer;
353 struct coding_system *coding;
355 if (len <= 0)
356 return;
358 /* If terminal_coding does any conversion, use it, otherwise use
359 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
360 because it always return 1 if the member src_multibyte is 1. */
361 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
362 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
363 /* We are going to write the entire block of glyphs in one go, as
364 they all have the same face. So this _is_ the last block. */
365 coding->mode |= CODING_MODE_LAST_BLOCK;
367 conversion_buffer = encode_terminal_code (string, len, coding);
368 if (coding->produced > 0)
370 DWORD filled, written;
371 /* Compute the character attributes corresponding to the face. */
372 DWORD char_attr = w32_face_attributes (f, face_id);
373 COORD start_coords;
375 start_coords.X = x;
376 start_coords.Y = y;
377 /* Set the attribute for these characters. */
378 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
379 coding->produced, start_coords,
380 &filled))
381 DebPrint (("Failed writing console attributes: %d\n", GetLastError ()));
382 else
384 /* Write the characters. */
385 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
386 filled, start_coords, &written))
387 DebPrint (("Failed writing console characters: %d\n",
388 GetLastError ()));
393 /* Implementation of draw_row_with_mouse_face for W32 console. */
394 void
395 tty_draw_row_with_mouse_face (struct window *w, struct glyph_row *row,
396 int start_hpos, int end_hpos,
397 enum draw_glyphs_face draw)
399 int nglyphs = end_hpos - start_hpos;
400 struct frame *f = XFRAME (WINDOW_FRAME (w));
401 struct tty_display_info *tty = FRAME_TTY (f);
402 int face_id = tty->mouse_highlight.mouse_face_face_id;
403 int pos_x, pos_y;
405 if (end_hpos >= row->used[TEXT_AREA])
406 nglyphs = row->used[TEXT_AREA] - start_hpos;
408 pos_y = row->y + WINDOW_TOP_EDGE_Y (w);
409 pos_x = row->used[LEFT_MARGIN_AREA] + start_hpos + WINDOW_LEFT_EDGE_X (w);
411 if (draw == DRAW_MOUSE_FACE)
412 w32con_write_glyphs_with_face (f, pos_x, pos_y,
413 row->glyphs[TEXT_AREA] + start_hpos,
414 nglyphs, face_id);
415 else if (draw == DRAW_NORMAL_TEXT)
417 COORD save_coords = cursor_coords;
419 w32con_move_cursor (f, pos_y, pos_x);
420 write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs);
421 w32con_move_cursor (f, save_coords.Y, save_coords.X);
425 static void
426 w32con_delete_glyphs (struct frame *f, int n)
428 /* delete chars means scroll chars from cursor_coords.X + n to
429 cursor_coords.X, anything beyond the edge of the screen should
430 come out empty... */
432 scroll_line (f, n, LEFT);
436 static void
437 w32con_reset_terminal_modes (struct terminal *t)
439 COORD dest;
440 CONSOLE_SCREEN_BUFFER_INFO info;
441 int n;
442 DWORD r;
444 /* Clear the complete screen buffer. This is required because Emacs
445 sets the cursor position to the top of the buffer, but there might
446 be other output below the bottom of the Emacs frame if the screen buffer
447 is larger than the window size. */
448 GetConsoleScreenBufferInfo (cur_screen, &info);
449 dest.X = 0;
450 dest.Y = 0;
451 n = info.dwSize.X * info.dwSize.Y;
453 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
454 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
455 /* Now that the screen is clear, put the cursor at the top. */
456 SetConsoleCursorPosition (cur_screen, dest);
458 #ifdef USE_SEPARATE_SCREEN
459 SetConsoleActiveScreenBuffer (prev_screen);
460 #else
461 SetConsoleCursorInfo (prev_screen, &prev_console_cursor);
462 #endif
464 SetConsoleMode (keyboard_handle, prev_console_mode);
467 static void
468 w32con_set_terminal_modes (struct terminal *t)
470 CONSOLE_CURSOR_INFO cci;
472 /* make cursor big and visible (100 on Windows 95 makes it disappear) */
473 cci.dwSize = 99;
474 cci.bVisible = TRUE;
475 (void) SetConsoleCursorInfo (cur_screen, &cci);
477 SetConsoleActiveScreenBuffer (cur_screen);
479 SetConsoleMode (keyboard_handle, ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
481 /* Initialize input mode: interrupt_input off, no flow control, allow
482 8 bit character input, standard quit char. */
483 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
486 /* hmmm... perhaps these let us bracket screen changes so that we can flush
487 clumps rather than one-character-at-a-time...
489 we'll start with not moving the cursor while an update is in progress. */
490 static void
491 w32con_update_begin (struct frame * f)
495 static void
496 w32con_update_end (struct frame * f)
498 SetConsoleCursorPosition (cur_screen, cursor_coords);
501 static void
502 w32con_set_terminal_window (struct frame *f, int size)
506 /***********************************************************************
507 stubs from termcap.c
508 ***********************************************************************/
510 void
511 sys_tputs (char *str, int nlines, int (*outfun) (int))
515 char *
516 sys_tgetstr (char *cap, char **area)
518 return NULL;
522 /***********************************************************************
523 stubs from cm.c
524 ***********************************************************************/
526 struct tty_display_info *current_tty = NULL;
527 int cost = 0;
530 evalcost (int c)
532 return c;
536 cmputc (int c)
538 return c;
541 void
542 cmcheckmagic (struct tty_display_info *tty)
546 void
547 cmcostinit (struct tty_display_info *tty)
551 void
552 cmgoto (struct tty_display_info *tty, int row, int col)
556 void
557 Wcm_clear (struct tty_display_info *tty)
562 /***********************************************************************
563 Faces
564 ***********************************************************************/
567 /* Turn appearances of face FACE_ID on tty frame F on. */
569 static WORD
570 w32_face_attributes (struct frame *f, int face_id)
572 WORD char_attr;
573 struct face *face = FACE_FROM_ID (f, face_id);
575 eassert (face != NULL);
577 char_attr = char_attr_normal;
579 /* Reverse the default color if requested. If background and
580 foreground are specified, then they have been reversed already. */
581 if (face->tty_reverse_p)
582 char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4)
583 + ((char_attr & 0x00f0) >> 4);
585 /* Before the terminal is properly initialized, all colors map to 0.
586 Don't try to resolve them. */
587 if (NILP (Vtty_defined_color_alist))
588 return char_attr;
590 /* Colors should be in the range 0...15 unless they are one of
591 FACE_TTY_DEFAULT_COLOR, FACE_TTY_DEFAULT_FG_COLOR or
592 FACE_TTY_DEFAULT_BG_COLOR. Other out of range colors are
593 invalid, so it is better to use the default color if they ever
594 get through to here. */
595 if (face->foreground >= 0 && face->foreground < 16)
596 char_attr = (char_attr & 0xfff0) + face->foreground;
598 if (face->background >= 0 && face->background < 16)
599 char_attr = (char_attr & 0xff0f) + (face->background << 4);
601 return char_attr;
604 void
605 initialize_w32_display (struct terminal *term)
607 CONSOLE_SCREEN_BUFFER_INFO info;
608 Mouse_HLInfo *hlinfo;
610 term->rif = 0; /* No window based redisplay on the console. */
611 term->cursor_to_hook = w32con_move_cursor;
612 term->raw_cursor_to_hook = w32con_move_cursor;
613 term->clear_to_end_hook = w32con_clear_to_end;
614 term->clear_frame_hook = w32con_clear_frame;
615 term->clear_end_of_line_hook = w32con_clear_end_of_line;
616 term->ins_del_lines_hook = w32con_ins_del_lines;
617 term->insert_glyphs_hook = w32con_insert_glyphs;
618 term->write_glyphs_hook = w32con_write_glyphs;
619 term->delete_glyphs_hook = w32con_delete_glyphs;
620 term->ring_bell_hook = w32_sys_ring_bell;
621 term->reset_terminal_modes_hook = w32con_reset_terminal_modes;
622 term->set_terminal_modes_hook = w32con_set_terminal_modes;
623 term->set_terminal_window_hook = w32con_set_terminal_window;
624 term->update_begin_hook = w32con_update_begin;
625 term->update_end_hook = w32con_update_end;
627 term->read_socket_hook = w32_console_read_socket;
628 term->mouse_position_hook = w32_console_mouse_position;
630 /* The following are not used on the console. */
631 term->frame_rehighlight_hook = 0;
632 term->frame_raise_lower_hook = 0;
633 term->set_vertical_scroll_bar_hook = 0;
634 term->condemn_scroll_bars_hook = 0;
635 term->redeem_scroll_bar_hook = 0;
636 term->judge_scroll_bars_hook = 0;
637 term->frame_up_to_date_hook = 0;
639 /* Initialize the mouse-highlight data. */
640 hlinfo = &term->display_info.tty->mouse_highlight;
641 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
642 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
643 hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
644 hlinfo->mouse_face_mouse_frame = NULL;
645 hlinfo->mouse_face_window = Qnil;
646 hlinfo->mouse_face_hidden = 0;
648 /* Initialize interrupt_handle. */
649 init_crit ();
651 /* Remember original console settings. */
652 keyboard_handle = GetStdHandle (STD_INPUT_HANDLE);
653 GetConsoleMode (keyboard_handle, &prev_console_mode);
655 prev_screen = GetStdHandle (STD_OUTPUT_HANDLE);
657 #ifdef USE_SEPARATE_SCREEN
658 cur_screen = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE,
659 0, NULL,
660 CONSOLE_TEXTMODE_BUFFER,
661 NULL);
663 if (cur_screen == INVALID_HANDLE_VALUE)
665 printf ("CreateConsoleScreenBuffer failed in ResetTerm\n");
666 printf ("LastError = 0x%lx\n", GetLastError ());
667 fflush (stdout);
668 exit (0);
670 #else
671 cur_screen = prev_screen;
672 GetConsoleCursorInfo (prev_screen, &prev_console_cursor);
673 #endif
675 /* Respect setting of LINES and COLUMNS environment variables. */
677 char * lines = getenv ("LINES");
678 char * columns = getenv ("COLUMNS");
680 if (lines != NULL && columns != NULL)
682 SMALL_RECT new_win_dims;
683 COORD new_size;
685 new_size.X = atoi (columns);
686 new_size.Y = atoi (lines);
688 GetConsoleScreenBufferInfo (cur_screen, &info);
690 /* Shrink the window first, so the buffer dimensions can be
691 reduced if necessary. */
692 new_win_dims.Top = 0;
693 new_win_dims.Left = 0;
694 new_win_dims.Bottom = min (new_size.Y, info.dwSize.Y) - 1;
695 new_win_dims.Right = min (new_size.X, info.dwSize.X) - 1;
696 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
698 SetConsoleScreenBufferSize (cur_screen, new_size);
700 /* Set the window size to match the buffer dimension. */
701 new_win_dims.Top = 0;
702 new_win_dims.Left = 0;
703 new_win_dims.Bottom = new_size.Y - 1;
704 new_win_dims.Right = new_size.X - 1;
705 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
709 GetConsoleScreenBufferInfo (cur_screen, &info);
711 char_attr_normal = info.wAttributes;
713 /* Determine if the info returned by GetConsoleScreenBufferInfo
714 is realistic. Old MS Telnet servers used to only fill out
715 the dwSize portion, even modern one fill the whole struct with
716 garbage when using non-MS telnet clients. */
717 if ((w32_use_full_screen_buffer
718 && (info.dwSize.Y < 20 || info.dwSize.Y > 100
719 || info.dwSize.X < 40 || info.dwSize.X > 200))
720 || (!w32_use_full_screen_buffer
721 && (info.srWindow.Bottom - info.srWindow.Top < 20
722 || info.srWindow.Bottom - info.srWindow.Top > 100
723 || info.srWindow.Right - info.srWindow.Left < 40
724 || info.srWindow.Right - info.srWindow.Left > 100)))
726 FRAME_LINES (SELECTED_FRAME ()) = 25;
727 SET_FRAME_COLS (SELECTED_FRAME (), 80);
730 else if (w32_use_full_screen_buffer)
732 FRAME_LINES (SELECTED_FRAME ()) = info.dwSize.Y; /* lines per page */
733 SET_FRAME_COLS (SELECTED_FRAME (), info.dwSize.X); /* characters per line */
735 else
737 /* Lines per page. Use buffer coords instead of buffer size. */
738 FRAME_LINES (SELECTED_FRAME ()) = 1 + info.srWindow.Bottom -
739 info.srWindow.Top;
740 /* Characters per line. Use buffer coords instead of buffer size. */
741 SET_FRAME_COLS (SELECTED_FRAME (), 1 + info.srWindow.Right -
742 info.srWindow.Left);
745 if (os_subtype == OS_NT)
746 w32_console_unicode_input = 1;
747 else
748 w32_console_unicode_input = 0;
750 /* Setup w32_display_info structure for this frame. */
752 w32_initialize_display_info (build_string ("Console"));
757 DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0,
758 doc: /* Set screen foreground and background colors.
760 Arguments should be indices between 0 and 15, see w32console.el. */)
761 (Lisp_Object foreground, Lisp_Object background)
763 char_attr_normal = XFASTINT (foreground) + (XFASTINT (background) << 4);
765 Frecenter (Qnil);
766 return Qt;
769 DEFUN ("get-screen-color", Fget_screen_color, Sget_screen_color, 0, 0, 0,
770 doc: /* Get color indices of the current screen foreground and background.
772 The colors are returned as a list of 2 indices (FOREGROUND BACKGROUND).
773 See w32console.el and `tty-defined-color-alist' for mapping of indices
774 to colors. */)
775 (void)
777 return Fcons (make_number (char_attr_normal & 0x000f),
778 Fcons (make_number ((char_attr_normal >> 4) & 0x000f), Qnil));
781 DEFUN ("set-cursor-size", Fset_cursor_size, Sset_cursor_size, 1, 1, 0,
782 doc: /* Set cursor size. */)
783 (Lisp_Object size)
785 CONSOLE_CURSOR_INFO cci;
786 cci.dwSize = XFASTINT (size);
787 cci.bVisible = TRUE;
788 (void) SetConsoleCursorInfo (cur_screen, &cci);
790 return Qt;
793 void
794 syms_of_ntterm (void)
796 DEFVAR_BOOL ("w32-use-full-screen-buffer",
797 w32_use_full_screen_buffer,
798 doc: /* Non-nil means make terminal frames use the full screen buffer dimensions.
799 This is desirable when running Emacs over telnet.
800 A value of nil means use the current console window dimensions; this
801 may be preferable when working directly at the console with a large
802 scroll-back buffer. */);
803 w32_use_full_screen_buffer = 0;
805 defsubr (&Sset_screen_color);
806 defsubr (&Sget_screen_color);
807 defsubr (&Sset_cursor_size);