Common Lisp cl-charms 中出现“您的终端不支持颜色”错误 - 如何启用颜色输出?

问题描述 投票:0回答:1

我在 Lisp 中遇到 cl-charms 库的问题。编译代码时,我收到错误“您的终端不支持颜色”。以下是重现该问题的代码:

(require 'uiop)
(load "~/.sbclrc")
(ql:quickload :cl-charms)

(defun start-color ()
  (when (eql (charms/ll:has-colors) charms/ll:FALSE)
    (error "Your terminal does not support color."))
  (let ((ret-code (charms/ll:start-color)))
    (if (= ret-code 0)
        T
        (error "start-color error ~s." ret-code))))

(eval-when (:load-toplevel :compile-toplevel :execute)
  (defconstant +black+   charms/ll:COLOR_BLACK)
  (defconstant +red+     charms/ll:COLOR_RED)
  (defconstant +green+   charms/ll:COLOR_GREEN)
  (defconstant +yellow+  charms/ll:COLOR_YELLOW)
  (defconstant +blue+    charms/ll:COLOR_BLUE)
  (defconstant +magenta+ charms/ll:COLOR_MAGENTA)
  (defconstant +cyan+    charms/ll:COLOR_CYAN)
  (defconstant +white+   charms/ll:COLOR_WHITE))

(defmacro define-color-pair ((name pair) foreground background)
  `(progn
     (start-color)
     (defparameter ,name (progn (charms/ll:init-pair ,pair ,foreground ,background)
                                (charms/ll:color-pair ,pair)))))

(define-color-pair (+white/blue+ 1) +white+ +blue+)
(define-color-pair (+black/red+ 2) +black+ +red+)

(defun draw-window-background (window color-pair)
  (charms/ll:wbkgd (charms::window-pointer window) color-pair))

(defmacro with-colors ((window color-pair) &body body)
  (let ((winptr (gensym)))
    (alexandria:once-only (color-pair)
      `(let ((,winptr (charms::window-pointer ,window)))
         (charms/ll:wattron ,winptr ,color-pair)
         ,@body
         (charms/ll:wattroff ,winptr ,color-pair)))))

(defun pretty-hello-world ()
  (charms:with-curses ()
    (charms:disable-echoing)
    (charms:enable-raw-input)
    (start-color)
    (loop named hello-world
       with window = (charms:make-window 50 15 10 10)
       do (progn
            (charms:clear-window window)
            (draw-window-background window +white/blue+)
            (with-colors (window +white/blue+)
              (charms:write-string-at-point window "Hello world!" 0 0))
            (with-colors (window +black/red+)
              (charms:write-string-at-point window "Hello world!" 0 1))
            (charms:refresh-window window)

            ;; Process input
            (when (eql (charms:get-char window :ignore-error t) #\q)
              (return-from hello-world))
            (sleep 0.1)))))

(defun main ()
  (pretty-hello-world))

(sb-ext:save-lisp-and-die "colors2.exe" :toplevel #'main :executable t)

我尝试通过检查我的终端设置来排除故障,它们似乎支持颜色。

任何有关我可能遇到此问题的原因的见解将不胜感激!

terminal colors common-lisp ncurses curses
1个回答
0
投票

这是 Dotrar 的答案:https://github.com/HiTECNOLOGYs/cl-charms/issues/64

您必须从

define-color-pair
内部致电
ncurses

(defmacro define-color-pair ((name pair) foreground background)
  `(progn
     (start-color)
     (defparameter ,name (progn (charms/ll:init-pair ,pair ,foreground ,background)
                                (charms/ll:color-pair ,pair)))))

(defun main ()
  (charms:with-curses ()
    (charms:disable-echoing)
    (charms:enable-raw-input :interpret-control-characters t)
    (charms:enable-non-blocking-mode charms:*standard-window*)
; here is where i define my color pairs
    (define-color-pair (+white/blue+ 1) +white+ +blue+)
    (define-color-pair (+black/red+ 2) +black+ +red+)
    (define-color-pair (+green/black+ 3) +green+ +black+)
    (loop :named driver-loop
          ....other forms)))

(我正在将此答案作为社区维基)

© www.soinside.com 2019 - 2024. All rights reserved.