vindarel / lisp-journey

Discovering the Common Lisp ecosystem. https://lisp-journey.gitlab.io/
2 stars 0 forks source link

blog/cl-ansi-term--print-tables-with-style-and-other-script-utilities/ #41

Open utterances-bot opened 2 days ago

utterances-bot commented 2 days ago

cl-ansi-term: print tables with style, and other script utilities - Lisp journey

Discovering the Common Lisp language and ecosystem… and being highly productive in it.

https://lisp-journey.gitlab.io/blog/cl-ansi-term--print-tables-with-style-and-other-script-utilities/

vindarel commented 2 days ago

added: style each table cell with custom logic.

(update-style-sheet
'((:color :cyan   :bold)
    (:danger :red :bold)
    (:green :green)
    (:default :green)
    ))

(setf *default-cell-style* :green)

(defparameter objects '(("pk" "title" "price")
                          (1 "lisp" 9.90)
                          (2 "common lisp" 100)
                          ))

(table objects
        :cell-style (lambda (val header)
                      (when (equal "price" header)
                        (if (> val 10)
                            :danger
                            :color))))
vindarel commented 17 hours ago

added: the columns adapt their width automatically, we can also set them.

+-------------------------------------+---+-------------------------------------+
|name                                 |age|email                                |
+-------------------------------------+---+-------------------------------------+
|me                                   |7  |some@blah                            |
+-------------------------------------+---+-------------------------------------+
|this name is also very very very ver…|7  |some@with-some-very-very-very-very-v…|
+-------------------------------------+---+-------------------------------------+