我正在用Lisp编写一个简单的connect-4程序,理想情况下,每个玩家(红色、黑色)在显示游戏状态时都会有自己的颜色。有人知道如何打印彩色ASCII字符吗?一般来说,这是如何完成的?我使用的是emacs 23,因此解决方案可能特定于emacs本身。
无论如何,我已经检查了hyperspec,看看格式是否可以做到这一点,但到目前为止还没有。提前谢谢。
发布于 2010-03-11 02:32:19
不知羞耻的自插:你可能想试试this,这是一个在web浏览器中运行的Common Lisp的图形终端。它使用html来打印内容,所以你可以这样做:
(gtfl-out (:p :style "color:red;" "some characters"))发布于 2013-06-04 02:49:42
我刚写了一个Elisp defun来测试颜色。例如,在设置Linux VT的常规颜色时,它可能很有用。注意颜色列表(“黑色”、“红色”等)只是按照惯例和通常的定义-如果你将它们设置为其他颜色,也许红色将不再是红色。尽管如此,它对测试还是有用的。
;;;; 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)example output http://user.it.uu.se/~embe8573/cols.png
发布于 2015-08-22 14:57:12
我正在寻找同样的答案,并一直在这里,过了一段时间后,我从另一个链接[Change the color of the text in the Common Lisp REPL]找到了答案。
我想也许你需要它,答案是:
区块引用
您可以使用ANSI转义代码打印彩色文本:
(格式t "~c[31mabc~c[0m~%“#\ESC #\ESC);这将为大多数现代终端打印一个红色的"abc”。
共享改进此答案于13年10月6日16:06回答
SaltyEgg 626412
区块报价
https://stackoverflow.com/questions/2419225
复制相似问题