comparison lisp/term/tty-colors.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 4dd143567eea
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; tty-colors.el --- color support for character terminals 1 ;;; tty-colors.el --- color support for character terminals
2 2
3 ;; Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 4 ;; 2005 Free Software Foundation, Inc.
5 ;; Author: Eli Zaretskii <eliz@is.elta.co.il> 5
6 ;; Author: Eli Zaretskii
6 ;; Maintainer: FSF 7 ;; Maintainer: FSF
7 ;; Keywords: terminals, faces 8 ;; Keywords: terminals, faces
8 9
9 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
10 11
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details. 20 ;; GNU General Public License for more details.
20 21
21 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02110-1301, USA.
25 26
26 ;;; Commentary: 27 ;;; Commentary:
27 28
28 ;; Emacs support for colors evolved from the X Window System; color 29 ;; Emacs support for colors evolved from the X Window System; color
29 ;; support for character-based terminals came later. Many Lisp 30 ;; support for character-based terminals came later. Many Lisp
58 ;; `tty-color-define' from your `.emacs' or `site-start.el'. For 59 ;; `tty-color-define' from your `.emacs' or `site-start.el'. For
59 ;; more-or-less standard definitions of VGA text-mode colors, see the 60 ;; more-or-less standard definitions of VGA text-mode colors, see the
60 ;; beginning of lisp/term/pc-win.el. 61 ;; beginning of lisp/term/pc-win.el.
61 62
62 ;;; Code: 63 ;;; Code:
64
65 (defvar msdos-color-values)
63 66
64 ;; The following list is taken from rgb.txt distributed with X. 67 ;; The following list is taken from rgb.txt distributed with X.
65 ;; 68 ;;
66 ;; WARNING: Some colors, such as "lightred", do not appear in this 69 ;; WARNING: Some colors, such as "lightred", do not appear in this
67 ;; list. If you think it's a good idea to add them, don't! The 70 ;; list. If you think it's a good idea to add them, don't! The
862 of gray, thus the name." 865 of gray, thus the name."
863 (let ((mag (sqrt (* 3 (+ (* r r) (* g g) (* b b)))))) 866 (let ((mag (sqrt (* 3 (+ (* r r) (* g g) (* b b))))))
864 (if (< mag 1) 0 (acos (/ (+ r g b) mag))))) 867 (if (< mag 1) 0 (acos (/ (+ r g b) mag)))))
865 868
866 (defun tty-color-approximate (rgb &optional frame) 869 (defun tty-color-approximate (rgb &optional frame)
867 "Given a list of 3 rgb values in RGB, find the color in `tty-color-alist' 870 "Find the color in `tty-color-alist' that best approximates RGB.
868 which is the best approximation in the 3-dimensional RGB space, 871 Value is a list of the form \(NAME INDEX R G B\).
869 and return its description. 872 The argument RGB should be an rgb value, that is, a list of three
870 873 integers in the 0..65535 range.
871 Value is a list of the form \(NAME INDEX R G B\). Note that the returned
872 NAME is not necessarily the same string as the argument COLOR, because
873 the latter might need to be approximated if it is not supported directly.
874
875 Each value of the RGB triplet should be in the range 0..65535 range.
876 FRAME defaults to the selected frame." 874 FRAME defaults to the selected frame."
877 (let* ((color-list (tty-color-alist frame)) 875 (let* ((color-list (tty-color-alist frame))
878 (candidate (car color-list)) 876 (candidate (car color-list))
879 (best-distance 195076) ;; 3 * 255^2 + 15 877 (best-distance 195076) ;; 3 * 255^2 + 15
880 (r (ash (car rgb) -8)) 878 (r (ash (car rgb) -8))
1045 (eq r g) (eq g b) 1043 (eq r g) (eq g b)
1046 (setq count (1+ count))) 1044 (setq count (1+ count)))
1047 (setq colors (cdr colors))) 1045 (setq colors (cdr colors)))
1048 count)) 1046 count))
1049 1047
1048 ;;; arch-tag: 84d5c3ef-ae22-4754-99ac-e6350c0967ae
1050 ;;; tty-colors.el ends here 1049 ;;; tty-colors.el ends here