]> code.delx.au - gnu-emacs/blob - src/w32console.c
merge trunk
[gnu-emacs] / src / w32console.c
1 /* Terminal hooks for GNU Emacs on the Microsoft W32 API.
2 Copyright (C) 1992, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20 /*
21 Tim Fleehart (apollo@online.com) 1-17-92
22 Geoff Voelker (voelker@cs.washington.edu) 9-12-93
23 */
24
25
26 #include <config.h>
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <windows.h>
31 #include <string.h>
32 #include <setjmp.h>
33
34 #include "lisp.h"
35 #include "character.h"
36 #include "coding.h"
37 #include "disptab.h"
38 #include "frame.h"
39 #include "termhooks.h"
40 #include "termchar.h"
41 #include "dispextern.h"
42 #include "w32inevt.h"
43
44 /* from window.c */
45 extern Lisp_Object Frecenter (Lisp_Object);
46
47 /* from keyboard.c */
48 extern int detect_input_pending (void);
49
50 /* from sysdep.c */
51 extern int read_input_pending (void);
52
53 static void w32con_move_cursor (struct frame *f, int row, int col);
54 static void w32con_clear_to_end (struct frame *f);
55 static void w32con_clear_frame (struct frame *f);
56 static void w32con_clear_end_of_line (struct frame *f, int);
57 static void w32con_ins_del_lines (struct frame *f, int vpos, int n);
58 static void w32con_insert_glyphs (struct frame *f, struct glyph *start, int len);
59 static void w32con_write_glyphs (struct frame *f, struct glyph *string, int len);
60 static void w32con_delete_glyphs (struct frame *f, int n);
61 static void w32con_reset_terminal_modes (struct terminal *t);
62 static void w32con_set_terminal_modes (struct terminal *t);
63 static void w32con_set_terminal_window (struct frame *f, int size);
64 static void w32con_update_begin (struct frame * f);
65 static void w32con_update_end (struct frame * f);
66 static WORD w32_face_attributes (struct frame *f, int face_id);
67
68 static COORD cursor_coords;
69 static HANDLE prev_screen, cur_screen;
70 static WORD char_attr_normal;
71 static DWORD prev_console_mode;
72
73 #ifndef USE_SEPARATE_SCREEN
74 static CONSOLE_CURSOR_INFO prev_console_cursor;
75 #endif
76
77 extern Lisp_Object Vtty_defined_color_alist;
78
79 /* Determine whether to make frame dimensions match the screen buffer,
80 or the current window size. The former is desirable when running
81 over telnet, while the latter is more useful when working directly at
82 the console with a large scroll-back buffer. */
83 int w32_use_full_screen_buffer;
84 HANDLE keyboard_handle;
85
86
87 /* Setting this as the ctrl handler prevents emacs from being killed when
88 someone hits ^C in a 'suspended' session (child shell).
89 Also ignore Ctrl-Break signals. */
90
91 BOOL
92 ctrl_c_handler (unsigned long type)
93 {
94 /* Only ignore "interrupt" events when running interactively. */
95 return (!noninteractive
96 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT));
97 }
98
99
100 /* Move the cursor to (ROW, COL) on FRAME. */
101 static void
102 w32con_move_cursor (struct frame *f, int row, int col)
103 {
104 cursor_coords.X = col;
105 cursor_coords.Y = row;
106
107 /* TODO: for multi-tty support, cur_screen should be replaced with a
108 reference to the terminal for this frame. */
109 SetConsoleCursorPosition (cur_screen, cursor_coords);
110 }
111
112 /* Clear from cursor to end of screen. */
113 static void
114 w32con_clear_to_end (struct frame *f)
115 {
116 w32con_clear_end_of_line (f, FRAME_COLS (f) - 1);
117 w32con_ins_del_lines (f, cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
118 }
119
120 /* Clear the frame. */
121 static void
122 w32con_clear_frame (struct frame *f)
123 {
124 COORD dest;
125 int n;
126 DWORD r;
127 CONSOLE_SCREEN_BUFFER_INFO info;
128
129 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info);
130
131 /* Remember that the screen buffer might be wider than the window. */
132 n = FRAME_LINES (f) * info.dwSize.X;
133 dest.X = dest.Y = 0;
134
135 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
136 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
137
138 w32con_move_cursor (f, 0, 0);
139 }
140
141
142 static struct glyph glyph_base[256];
143 static BOOL ceol_initialized = FALSE;
144
145 /* Clear from Cursor to end (what's "standout marker"?). */
146 static void
147 w32con_clear_end_of_line (struct frame *f, int end)
148 {
149 if (!ceol_initialized)
150 {
151 int i;
152 for (i = 0; i < 256; i++)
153 {
154 memcpy (&glyph_base[i], &space_glyph, sizeof (struct glyph));
155 }
156 ceol_initialized = TRUE;
157 }
158 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */
159 }
160
161 /* Insert n lines at vpos. if n is negative delete -n lines. */
162 static void
163 w32con_ins_del_lines (struct frame *f, int vpos, int n)
164 {
165 int i, nb;
166 SMALL_RECT scroll;
167 SMALL_RECT clip;
168 COORD dest;
169 CHAR_INFO fill;
170
171 if (n < 0)
172 {
173 scroll.Top = vpos - n;
174 scroll.Bottom = FRAME_LINES (f);
175 dest.Y = vpos;
176 }
177 else
178 {
179 scroll.Top = vpos;
180 scroll.Bottom = FRAME_LINES (f) - n;
181 dest.Y = vpos + n;
182 }
183 clip.Top = clip.Left = scroll.Left = 0;
184 clip.Right = scroll.Right = FRAME_COLS (f);
185 clip.Bottom = FRAME_LINES (f);
186
187 dest.X = 0;
188
189 fill.Char.AsciiChar = 0x20;
190 fill.Attributes = char_attr_normal;
191
192 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
193
194 /* Here we have to deal with a w32 console flake: If the scroll
195 region looks like abc and we scroll c to a and fill with d we get
196 cbd... if we scroll block c one line at a time to a, we get cdd...
197 Emacs expects cdd consistently... So we have to deal with that
198 here... (this also occurs scrolling the same way in the other
199 direction. */
200
201 if (n > 0)
202 {
203 if (scroll.Bottom < dest.Y)
204 {
205 for (i = scroll.Bottom; i < dest.Y; i++)
206 {
207 w32con_move_cursor (f, i, 0);
208 w32con_clear_end_of_line (f, FRAME_COLS (f));
209 }
210 }
211 }
212 else
213 {
214 nb = dest.Y + (scroll.Bottom - scroll.Top) + 1;
215
216 if (nb < scroll.Top)
217 {
218 for (i = nb; i < scroll.Top; i++)
219 {
220 w32con_move_cursor (f, i, 0);
221 w32con_clear_end_of_line (f, FRAME_COLS (f));
222 }
223 }
224 }
225
226 cursor_coords.X = 0;
227 cursor_coords.Y = vpos;
228 }
229
230 #undef LEFT
231 #undef RIGHT
232 #define LEFT 1
233 #define RIGHT 0
234
235 static void
236 scroll_line (struct frame *f, int dist, int direction)
237 {
238 /* The idea here is to implement a horizontal scroll in one line to
239 implement delete and half of insert. */
240 SMALL_RECT scroll, clip;
241 COORD dest;
242 CHAR_INFO fill;
243
244 clip.Top = scroll.Top = clip.Bottom = scroll.Bottom = cursor_coords.Y;
245 clip.Left = 0;
246 clip.Right = FRAME_COLS (f);
247
248 if (direction == LEFT)
249 {
250 scroll.Left = cursor_coords.X + dist;
251 scroll.Right = FRAME_COLS (f) - 1;
252 }
253 else
254 {
255 scroll.Left = cursor_coords.X;
256 scroll.Right = FRAME_COLS (f) - dist - 1;
257 }
258
259 dest.X = cursor_coords.X;
260 dest.Y = cursor_coords.Y;
261
262 fill.Char.AsciiChar = 0x20;
263 fill.Attributes = char_attr_normal;
264
265 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
266 }
267
268
269 /* If start is zero insert blanks instead of a string at start ?. */
270 static void
271 w32con_insert_glyphs (struct frame *f, register struct glyph *start,
272 register int len)
273 {
274 scroll_line (f, len, RIGHT);
275
276 /* Move len chars to the right starting at cursor_coords, fill with blanks */
277 if (start)
278 {
279 /* Print the first len characters of start, cursor_coords.X adjusted
280 by write_glyphs. */
281
282 w32con_write_glyphs (f, start, len);
283 }
284 else
285 {
286 w32con_clear_end_of_line (f, cursor_coords.X + len);
287 }
288 }
289
290 extern unsigned char *encode_terminal_code (struct glyph *, int,
291 struct coding_system *);
292
293 static void
294 w32con_write_glyphs (struct frame *f, register struct glyph *string,
295 register int len)
296 {
297 DWORD r;
298 WORD char_attr;
299 unsigned char *conversion_buffer;
300 struct coding_system *coding;
301
302 if (len <= 0)
303 return;
304
305 /* If terminal_coding does any conversion, use it, otherwise use
306 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
307 because it always return 1 if the member src_multibyte is 1. */
308 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
309 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
310 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
311 the tail. */
312 coding->mode &= ~CODING_MODE_LAST_BLOCK;
313
314 while (len > 0)
315 {
316 /* Identify a run of glyphs with the same face. */
317 int face_id = string->face_id;
318 int n;
319
320 for (n = 1; n < len; ++n)
321 if (string[n].face_id != face_id)
322 break;
323
324 /* Turn appearance modes of the face of the run on. */
325 char_attr = w32_face_attributes (f, face_id);
326
327 if (n == len)
328 /* This is the last run. */
329 coding->mode |= CODING_MODE_LAST_BLOCK;
330 conversion_buffer = encode_terminal_code (string, n, coding);
331 if (coding->produced > 0)
332 {
333 /* Set the attribute for these characters. */
334 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
335 coding->produced, cursor_coords,
336 &r))
337 {
338 printf ("Failed writing console attributes: %d\n",
339 GetLastError ());
340 fflush (stdout);
341 }
342
343 /* Write the characters. */
344 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
345 coding->produced, cursor_coords,
346 &r))
347 {
348 printf ("Failed writing console characters: %d\n",
349 GetLastError ());
350 fflush (stdout);
351 }
352
353 cursor_coords.X += coding->produced;
354 w32con_move_cursor (f, cursor_coords.Y, cursor_coords.X);
355 }
356 len -= n;
357 string += n;
358 }
359 }
360
361
362 static void
363 w32con_delete_glyphs (struct frame *f, int n)
364 {
365 /* delete chars means scroll chars from cursor_coords.X + n to
366 cursor_coords.X, anything beyond the edge of the screen should
367 come out empty... */
368
369 scroll_line (f, n, LEFT);
370 }
371
372 static unsigned int sound_type = 0xFFFFFFFF;
373 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
374
375 void
376 w32_sys_ring_bell (struct frame *f)
377 {
378 if (sound_type == 0xFFFFFFFF)
379 {
380 Beep (666, 100);
381 }
382 else if (sound_type == MB_EMACS_SILENT)
383 {
384 /* Do nothing. */
385 }
386 else
387 MessageBeep (sound_type);
388 }
389
390 DEFUN ("set-message-beep", Fset_message_beep, Sset_message_beep, 1, 1, 0,
391 doc: /* Set the sound generated when the bell is rung.
392 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
393 to use the corresponding system sound for the bell. The 'silent sound
394 prevents Emacs from making any sound at all.
395 SOUND is nil to use the normal beep. */)
396 (sound)
397 Lisp_Object sound;
398 {
399 CHECK_SYMBOL (sound);
400
401 if (NILP (sound))
402 sound_type = 0xFFFFFFFF;
403 else if (EQ (sound, intern ("asterisk")))
404 sound_type = MB_ICONASTERISK;
405 else if (EQ (sound, intern ("exclamation")))
406 sound_type = MB_ICONEXCLAMATION;
407 else if (EQ (sound, intern ("hand")))
408 sound_type = MB_ICONHAND;
409 else if (EQ (sound, intern ("question")))
410 sound_type = MB_ICONQUESTION;
411 else if (EQ (sound, intern ("ok")))
412 sound_type = MB_OK;
413 else if (EQ (sound, intern ("silent")))
414 sound_type = MB_EMACS_SILENT;
415 else
416 sound_type = 0xFFFFFFFF;
417
418 return sound;
419 }
420
421 static void
422 w32con_reset_terminal_modes (struct terminal *t)
423 {
424 COORD dest;
425 CONSOLE_SCREEN_BUFFER_INFO info;
426 int n;
427 DWORD r;
428
429 /* Clear the complete screen buffer. This is required because Emacs
430 sets the cursor position to the top of the buffer, but there might
431 be other output below the bottom of the Emacs frame if the screen buffer
432 is larger than the window size. */
433 GetConsoleScreenBufferInfo (cur_screen, &info);
434 dest.X = 0;
435 dest.Y = 0;
436 n = info.dwSize.X * info.dwSize.Y;
437
438 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
439 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
440 /* Now that the screen is clear, put the cursor at the top. */
441 SetConsoleCursorPosition (cur_screen, dest);
442
443 #ifdef USE_SEPARATE_SCREEN
444 SetConsoleActiveScreenBuffer (prev_screen);
445 #else
446 SetConsoleCursorInfo (prev_screen, &prev_console_cursor);
447 #endif
448
449 SetConsoleMode (keyboard_handle, prev_console_mode);
450 }
451
452 static void
453 w32con_set_terminal_modes (struct terminal *t)
454 {
455 CONSOLE_CURSOR_INFO cci;
456
457 /* make cursor big and visible (100 on Win95 makes it disappear) */
458 cci.dwSize = 99;
459 cci.bVisible = TRUE;
460 (void) SetConsoleCursorInfo (cur_screen, &cci);
461
462 SetConsoleActiveScreenBuffer (cur_screen);
463
464 SetConsoleMode (keyboard_handle, ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
465
466 /* Initialize input mode: interrupt_input off, no flow control, allow
467 8 bit character input, standard quit char. */
468 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
469 }
470
471 /* hmmm... perhaps these let us bracket screen changes so that we can flush
472 clumps rather than one-character-at-a-time...
473
474 we'll start with not moving the cursor while an update is in progress. */
475 static void
476 w32con_update_begin (struct frame * f)
477 {
478 }
479
480 static void
481 w32con_update_end (struct frame * f)
482 {
483 SetConsoleCursorPosition (cur_screen, cursor_coords);
484 }
485
486 static void
487 w32con_set_terminal_window (struct frame *f, int size)
488 {
489 }
490
491 /***********************************************************************
492 stubs from termcap.c
493 ***********************************************************************/
494
495 void
496 sys_tputs (char *str, int nlines, int (*outfun) (int))
497 {
498 }
499
500 char *
501 sys_tgetstr (char *cap, char **area)
502 {
503 return NULL;
504 }
505
506
507 /***********************************************************************
508 stubs from cm.c
509 ***********************************************************************/
510
511 struct tty_display_info *current_tty = NULL;
512 int cost = 0;
513
514 int
515 evalcost (int c)
516 {
517 return c;
518 }
519
520 int
521 cmputc (int c)
522 {
523 return c;
524 }
525
526 void
527 cmcheckmagic (struct tty_display_info *tty)
528 {
529 }
530
531 void
532 cmcostinit (struct tty_display_info *tty)
533 {
534 }
535
536 void
537 cmgoto (struct tty_display_info *tty, int row, int col)
538 {
539 }
540
541 void
542 Wcm_clear (struct tty_display_info *tty)
543 {
544 }
545
546
547 /***********************************************************************
548 Faces
549 ***********************************************************************/
550
551
552 /* Turn appearances of face FACE_ID on tty frame F on. */
553
554 static WORD
555 w32_face_attributes (struct frame *f, int face_id)
556 {
557 WORD char_attr;
558 struct face *face = FACE_FROM_ID (f, face_id);
559
560 xassert (face != NULL);
561
562 char_attr = char_attr_normal;
563
564 /* Reverse the default color if requested. If background and
565 foreground are specified, then they have been reversed already. */
566 if (face->tty_reverse_p)
567 char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4)
568 + ((char_attr & 0x00f0) >> 4);
569
570 /* Before the terminal is properly initialized, all colors map to 0.
571 Don't try to resolve them. */
572 if (NILP (Vtty_defined_color_alist))
573 return char_attr;
574
575 /* Colors should be in the range 0...15 unless they are one of
576 FACE_TTY_DEFAULT_COLOR, FACE_TTY_DEFAULT_FG_COLOR or
577 FACE_TTY_DEFAULT_BG_COLOR. Other out of range colors are
578 invalid, so it is better to use the default color if they ever
579 get through to here. */
580 if (face->foreground >= 0 && face->foreground < 16)
581 char_attr = (char_attr & 0xfff0) + face->foreground;
582
583 if (face->background >= 0 && face->background < 16)
584 char_attr = (char_attr & 0xff0f) + (face->background << 4);
585
586 return char_attr;
587 }
588
589
590
591 /* Given a color index, return its standard name. */
592 Lisp_Object
593 vga_stdcolor_name (int idx)
594 {
595 /* Standard VGA colors, in the order of their standard numbering
596 in the default VGA palette. */
597 static char *vga_colors[16] = {
598 "black", "blue", "green", "cyan", "red", "magenta", "brown",
599 "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan",
600 "lightred", "lightmagenta", "yellow", "white"
601 };
602
603 extern Lisp_Object Qunspecified;
604
605 if (idx >= 0 && idx < sizeof (vga_colors) / sizeof (vga_colors[0]))
606 return build_string (vga_colors[idx]);
607 else
608 return Qunspecified; /* meaning the default */
609 }
610
611 void
612 initialize_w32_display (struct terminal *term)
613 {
614 CONSOLE_SCREEN_BUFFER_INFO info;
615
616 term->rif = 0; /* No window based redisplay on the console. */
617 term->cursor_to_hook = w32con_move_cursor;
618 term->raw_cursor_to_hook = w32con_move_cursor;
619 term->clear_to_end_hook = w32con_clear_to_end;
620 term->clear_frame_hook = w32con_clear_frame;
621 term->clear_end_of_line_hook = w32con_clear_end_of_line;
622 term->ins_del_lines_hook = w32con_ins_del_lines;
623 term->insert_glyphs_hook = w32con_insert_glyphs;
624 term->write_glyphs_hook = w32con_write_glyphs;
625 term->delete_glyphs_hook = w32con_delete_glyphs;
626 term->ring_bell_hook = w32_sys_ring_bell;
627 term->reset_terminal_modes_hook = w32con_reset_terminal_modes;
628 term->set_terminal_modes_hook = w32con_set_terminal_modes;
629 term->set_terminal_window_hook = w32con_set_terminal_window;
630 term->update_begin_hook = w32con_update_begin;
631 term->update_end_hook = w32con_update_end;
632
633 term->read_socket_hook = w32_console_read_socket;
634 term->mouse_position_hook = w32_console_mouse_position;
635
636 /* The following are not used on the console. */
637 term->frame_rehighlight_hook = 0;
638 term->frame_raise_lower_hook = 0;
639 term->set_vertical_scroll_bar_hook = 0;
640 term->condemn_scroll_bars_hook = 0;
641 term->redeem_scroll_bar_hook = 0;
642 term->judge_scroll_bars_hook = 0;
643 term->frame_up_to_date_hook = 0;
644
645 /* Initialize interrupt_handle. */
646 init_crit ();
647
648 /* Remember original console settings. */
649 keyboard_handle = GetStdHandle (STD_INPUT_HANDLE);
650 GetConsoleMode (keyboard_handle, &prev_console_mode);
651
652 prev_screen = GetStdHandle (STD_OUTPUT_HANDLE);
653
654 #ifdef USE_SEPARATE_SCREEN
655 cur_screen = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE,
656 0, NULL,
657 CONSOLE_TEXTMODE_BUFFER,
658 NULL);
659
660 if (cur_screen == INVALID_HANDLE_VALUE)
661 {
662 printf ("CreateConsoleScreenBuffer failed in ResetTerm\n");
663 printf ("LastError = 0x%lx\n", GetLastError ());
664 fflush (stdout);
665 exit (0);
666 }
667 #else
668 cur_screen = prev_screen;
669 GetConsoleCursorInfo (prev_screen, &prev_console_cursor);
670 #endif
671
672 /* Respect setting of LINES and COLUMNS environment variables. */
673 {
674 char * lines = getenv ("LINES");
675 char * columns = getenv ("COLUMNS");
676
677 if (lines != NULL && columns != NULL)
678 {
679 SMALL_RECT new_win_dims;
680 COORD new_size;
681
682 new_size.X = atoi (columns);
683 new_size.Y = atoi (lines);
684
685 GetConsoleScreenBufferInfo (cur_screen, &info);
686
687 /* Shrink the window first, so the buffer dimensions can be
688 reduced if necessary. */
689 new_win_dims.Top = 0;
690 new_win_dims.Left = 0;
691 new_win_dims.Bottom = min (new_size.Y, info.dwSize.Y) - 1;
692 new_win_dims.Right = min (new_size.X, info.dwSize.X) - 1;
693 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
694
695 SetConsoleScreenBufferSize (cur_screen, new_size);
696
697 /* Set the window size to match the buffer dimension. */
698 new_win_dims.Top = 0;
699 new_win_dims.Left = 0;
700 new_win_dims.Bottom = new_size.Y - 1;
701 new_win_dims.Right = new_size.X - 1;
702 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
703 }
704 }
705
706 GetConsoleScreenBufferInfo (cur_screen, &info);
707
708 char_attr_normal = info.wAttributes;
709
710 /* Determine if the info returned by GetConsoleScreenBufferInfo
711 is realistic. Old MS Telnet servers used to only fill out
712 the dwSize portion, even modern one fill the whole struct with
713 garbage when using non-MS telnet clients. */
714 if ((w32_use_full_screen_buffer
715 && (info.dwSize.Y < 20 || info.dwSize.Y > 100
716 || info.dwSize.X < 40 || info.dwSize.X > 200))
717 || (!w32_use_full_screen_buffer
718 && (info.srWindow.Bottom - info.srWindow.Top < 20
719 || info.srWindow.Bottom - info.srWindow.Top > 100
720 || info.srWindow.Right - info.srWindow.Left < 40
721 || info.srWindow.Right - info.srWindow.Left > 100)))
722 {
723 FRAME_LINES (SELECTED_FRAME ()) = 25;
724 SET_FRAME_COLS (SELECTED_FRAME (), 80);
725 }
726
727 else if (w32_use_full_screen_buffer)
728 {
729 FRAME_LINES (SELECTED_FRAME ()) = info.dwSize.Y; /* lines per page */
730 SET_FRAME_COLS (SELECTED_FRAME (), info.dwSize.X); /* characters per line */
731 }
732 else
733 {
734 /* Lines per page. Use buffer coords instead of buffer size. */
735 FRAME_LINES (SELECTED_FRAME ()) = 1 + info.srWindow.Bottom -
736 info.srWindow.Top;
737 /* Characters per line. Use buffer coords instead of buffer size. */
738 SET_FRAME_COLS (SELECTED_FRAME (), 1 + info.srWindow.Right -
739 info.srWindow.Left);
740 }
741
742 /* Setup w32_display_info structure for this frame. */
743
744 w32_initialize_display_info (build_string ("Console"));
745
746 }
747
748
749 DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0,
750 doc: /* Set screen colors. */)
751 (foreground, background)
752 Lisp_Object foreground;
753 Lisp_Object background;
754 {
755 char_attr_normal = XFASTINT (foreground) + (XFASTINT (background) << 4);
756
757 Frecenter (Qnil);
758 return Qt;
759 }
760
761 DEFUN ("set-cursor-size", Fset_cursor_size, Sset_cursor_size, 1, 1, 0,
762 doc: /* Set cursor size. */)
763 (size)
764 Lisp_Object size;
765 {
766 CONSOLE_CURSOR_INFO cci;
767 cci.dwSize = XFASTINT (size);
768 cci.bVisible = TRUE;
769 (void) SetConsoleCursorInfo (cur_screen, &cci);
770
771 return Qt;
772 }
773
774 void
775 syms_of_ntterm (void)
776 {
777 DEFVAR_BOOL ("w32-use-full-screen-buffer",
778 &w32_use_full_screen_buffer,
779 doc: /* Non-nil means make terminal frames use the full screen buffer dimensions.
780 This is desirable when running Emacs over telnet.
781 A value of nil means use the current console window dimensions; this
782 may be preferrable when working directly at the console with a large
783 scroll-back buffer. */);
784 w32_use_full_screen_buffer = 0;
785
786 defsubr (&Sset_screen_color);
787 defsubr (&Sset_cursor_size);
788 defsubr (&Sset_message_beep);
789 }
790
791 /* arch-tag: a390a07f-f661-42bc-aeb4-e6d8bf860337
792 (do not change this comment) */