Update copyright year to 2014 by running admin/update-copyright.
[bpt/emacs.git] / lisp / term / w32console.el
CommitLineData
2097e21d
JR
1;;; w32console.el -- Setup w32 console keys and colors.
2
ba318903 3;; Copyright (C) 2007-2014 Free Software Foundation, Inc.
2097e21d
JR
4
5;; Author: FSF
6;; Keywords: terminals
7
8;; This file is part of GNU Emacs.
9
1fecc8fe 10;; GNU Emacs is free software: you can redistribute it and/or modify
2097e21d 11;; it under the terms of the GNU General Public License as published by
1fecc8fe
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
2097e21d
JR
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
1fecc8fe 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
2097e21d
JR
22
23;;; Commentary:
24
25;;; Code:
26
27;; W32 uses different color indexes than standard:
28
29(defvar w32-tty-standard-colors
30 '(("black" 0 0 0 0)
31 ("blue" 1 0 0 52480) ; MediumBlue
32 ("green" 2 8704 35584 8704) ; ForestGreen
33 ("cyan" 3 0 52736 53504) ; DarkTurquoise
34 ("red" 4 45568 8704 8704) ; FireBrick
35 ("magenta" 5 35584 0 35584) ; DarkMagenta
36 ("brown" 6 40960 20992 11520) ; Sienna
37 ("lightgray" 7 48640 48640 48640) ; Gray
38 ("darkgray" 8 26112 26112 26112) ; Gray40
39 ("lightblue" 9 0 0 65535) ; Blue
40 ("lightgreen" 10 0 65535 0) ; Green
41 ("lightcyan" 11 0 65535 65535) ; Cyan
42 ("lightred" 12 65535 0 0) ; Red
43 ("lightmagenta" 13 65535 0 65535) ; Magenta
44 ("yellow" 14 65535 65535 0) ; Yellow
45 ("white" 15 65535 65535 65535))
46"A list of VGA console colors, their indices and 16-bit RGB values.")
47
c8ccffb1 48(declare-function x-setup-function-keys "term/common-win" (frame))
93c9df73 49(declare-function get-screen-color "w32console.c" ())
f6ebbb46
GM
50(declare-function w32-get-console-codepage "w32proc.c" ())
51(declare-function w32-get-console-output-codepage "w32proc.c" ())
aa360da1 52
2097e21d
JR
53(defun terminal-init-w32console ()
54 "Terminal initialization function for w32 console."
55 ;; Share function key initialization with w32 gui frames
56 (x-setup-function-keys (selected-frame))
20ba0cb4
EZ
57 ;; Set terminal and keyboard encodings to the current OEM codepage.
58 (let ((oem-code-page-coding
59 (intern (format "cp%d" (w32-get-console-codepage))))
60 (oem-code-page-output-coding
61 (intern (format "cp%d" (w32-get-console-output-codepage))))
62 oem-cs-p oem-o-cs-p)
63 (setq oem-cs-p (coding-system-p oem-code-page-coding))
64 (setq oem-o-cs-p (coding-system-p oem-code-page-output-coding))
65 (when oem-cs-p
66 (set-keyboard-coding-system oem-code-page-coding)
67 (set-terminal-coding-system
68 (if oem-o-cs-p oem-code-page-output-coding oem-code-page-coding))))
2097e21d
JR
69 (let* ((colors w32-tty-standard-colors)
70 (color (car colors)))
71 (tty-color-clear)
72 (while colors
73 (tty-color-define (car color) (cadr color) (cddr color))
74 (setq colors (cdr colors)
75 color (car colors))))
76 (clear-face-cache)
b0512a1d
EZ
77 ;; Figure out what are the colors of the console window, and set up
78 ;; the background-mode correspondingly.
79 (let* ((screen-color (get-screen-color))
80 (bg (cadr screen-color))
81 (descr (tty-color-by-index bg))
82 r g b bg-mode)
83 (setq r (nth 2 descr)
84 g (nth 3 descr)
85 b (nth 4 descr))
86 (if (< (+ r g b) (* .6 (+ 65535 65535 65535)))
87 (setq bg-mode 'dark)
88 (setq bg-mode 'light))
89 (set-terminal-parameter nil 'background-mode bg-mode))
2097e21d
JR
90 (tty-set-up-initial-frame-faces)
91 (run-hooks 'terminal-init-w32-hook))
3d9bd2bc 92
c8ccffb1 93;;; w32console.el ends here