cl-charms icon indicating copy to clipboard operation
cl-charms copied to clipboard

charms/ll:has_colors is charms/ll:FALSE on a truecolor terminal

Open ArnaudValette opened this issue 2 years ago • 2 comments

When I use <curses.h> in a C program, has_colors() is true. When following along the charms crash course linked in the README, charms/ll:has_colors is charms/ll:FALSE on my terminal (kitty).

Removing the test indeed lead to a situation in which the code written in the article doesn't display any color.

ArnaudValette avatar Oct 12 '23 14:10 ArnaudValette

I can reproduce with this code: https://stackoverflow.com/questions/77614661/getting-your-terminal-does-not-support-color-error-in-common-lisp-cl-charms

There's a preliminary check:


(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))))

which errors out. If I replace its call in the main function by charms/ll:start-color, I can see a grey rectangle window, but no "hello world" message.

libncurses5 v6.2, SBCL 2.1.5, cl-charms from quicklisp "2023-02-15".

vindarel avatar Dec 14 '23 10:12 vindarel

I also had this issue, (following the same tutorial as all you) -- I had a look at what the LEM project is doing, and their code works fine.

define-color-pair is actually a ncurses call, which you must call from within a ncurses form.

(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)))))

Move the define-color-pair into the charms:with-curses form like this:

(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)))

Then I get the expected output, no error. image

Dotrar avatar Jul 14 '24 08:07 Dotrar