如何在通用LISP中打印文本,以便可以使用逃生序列(类似于在球拍中显示)将其格式化?

发布于 2025-02-13 07:10:53 字数 407 浏览 0 评论 0原文

ho我是否在通用LISP中打印一个格式的输出? 在 conset 我与display> display一样, :

(display "\33[3min italics\33[m\n")

我已经尝试了(格式t“ 〜ain italics〜A”“ \ 33 [3M” “ \ 33 [m“”),但不起作用。这也不是:(格式t“ 〜CIN ITALICS〜C”#\ 33 [3M#\ 33 [M)

Ho do I print a formatted output in Common Lisp?
In Racket I do it with display, like so:

(display "\33[3min italics\33[m\n")

I've tried with (format t "~ain italics~a" "\33[3m" "\33[m") but it does not work. Neither does this: (format t "~cin italics~c" #\33[3m #\33[m).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉睡月亮 2025-02-20 07:10:53

这里的主要问题是如何获得正确的字符序列。 \ 33是ASCII CHAR 27或#\ ESC中的八十个八角中。

(format t "~C[3min italics~C[m~%" #\Esc #\Esc)

会做你想做的。

但是您可以做得更好。有一个名为 cl-interpol ,通过修改读取器来演示常见LISP的灵活性的库,可以使用已经熟悉的语法。
例如:

* (ql:quickload 'cl-interpol)
To load "cl-interpol":
  Load 1 ASDF system:
    cl-interpol
; Loading "cl-interpol"
...
(CL-INTERPOL)

* (named-readtables:in-readtable :interpol-syntax)
#<NAMED-READTABLE :INTERPOL-SYNTAX {1002E6D6B3}>

* (format t #?"\33[3min italics\33[m\n")
in italics
NIL

The main issue here is how to get the proper sequence of characters. \33 is octal for ascii char 27 or #\Esc in Common Lisp.

(format t "~C[3min italics~C[m~%" #\Esc #\Esc)

would do what you want.

But you could do better than that. There is a library called cl-interpol which demonstrates flexibility of Common Lisp by modifying the reader so you could use the already familiar syntax.
For example:

* (ql:quickload 'cl-interpol)
To load "cl-interpol":
  Load 1 ASDF system:
    cl-interpol
; Loading "cl-interpol"
...
(CL-INTERPOL)

* (named-readtables:in-readtable :interpol-syntax)
#<NAMED-READTABLE :INTERPOL-SYNTAX {1002E6D6B3}>

* (format t #?"\33[3min italics\33[m\n")
in italics
NIL
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文