我正在使用Lisp编写一个简单的连四游戏程序,理想情况下每个玩家(红色,黑色)在游戏状态显示时都有自己的颜色。有人知道如何打印彩色ASCII字符吗?通常是如何实现的?我正在使用emacs 23,因此解决方案可能特定于emacs本身。
无论如何,我已经检查了hyperspec,看看是否可以使用FORMAT,但目前为止没有运气。提前致谢。
无论如何,我已经检查了hyperspec,看看是否可以使用FORMAT,但目前为止没有运气。提前致谢。
不要介意我自己打广告:你可以尝试这个,它是一个在Web浏览器中运行的Common Lisp图形终端。它使用HTML来输出内容,所以你可以像这样做:
(gtfl-out (:p :style "color:red;" "some characters"))
我刚刚编写了一个Elisp defun来测试颜色。它可能在设置Linux VTs的通用颜色时很有用。请注意,颜色列表(“black”,“red”等)只是传统上和通常定义的方式 - 如果您将它们设置为其他颜色,则红色可能不再是红色。尽管如此,这仍然可以是一个有用的测试工具。
;;;; insert colored and/or bright text
(defun insert-colored-text (str clr bright)
"Inserts str at point, in color clr, bright or not."
(interactive (list (read-string " String: ")
(read-string " Color: ")
(y-or-n-p " Bright? ") ))
(insert (propertize str 'font-lock-face
`(:weight ,(if bright 'bold 'normal) :foreground ,clr) )))
(defalias 'ict 'insert-colored-text)
(defun test-all-faces ()
"Prints a test string in al colors, both normal and bright."
(interactive)
(let ((str "This is what it looks like"))
(dolist (bold '(nil t) nil)
(dolist (color
'("black" "red" "green" "yellow" "blue"
"magenta" "cyan" "white") nil)
(insert-colored-text
(format "%s in %s (that is %sbold)\n" str color
(if bold "" "not ")) color bold) ))))
(defalias 'taf 'test-all-faces)
(format t "~c[31m红色~:*~c[32m绿色~:*~c[34m蓝色~:*~c[m无格式~%" (code-char 27))
。 - Devon