I'm writing a simple connect-4 program in Lisp and ideally each player (red, black) would have their own color when the game state is displayed. Does anyone know how to print colored ASCII characters? How is this done in general? I'm using emacs 23, so the solution might be specific to emacs itself.
Anyways, I've checked the hyperspec to see if FORMAT can do it but no luck so far. Thanks in advance.
The appearance of text in Emacs is controlled by faces. Face can be changed through either overlay or text properties. Here is an example using the latter:
;; Emacs-Lisp (insert (propertize "foo" 'font-lock-face '(:foreground "red")))
However, if the game is implemented in SBCL, you'll need a way to communicate with Emacs from your SBCL program. As it seems that you're using Slime, using Swank, which is a part of Slime, might be the most convenient:
;; Common-Lisp (swank::eval-in-emacs '(with-current-buffer (slime-repl-buffer) (insert (propertize "foo" 'font-lock-face '(:foreground "red")))))
Shameless self plug: you might want to try this, which is a graphical terminal for Common Lisp running in a web browser. It uses html for printing stuff, so you could do something like:
(gtfl-out (:p :style "color:red;" "some characters"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With