← 都来码 / Dolaima← 例程索引dbase/tty/demo_tty.prg 原文

dbase/tty/demo_tty.prg · 1547 字节 · 下载原文

* demo_tty.prg —— dBase (xBase) 第二层:**彩色命令行**(tty)
* demo_tty.prg -- dBase (xBase) layer 2: **colour command line** (tty)
*
* 这一层做「在字符界面上排版」:清屏、彩色文字、按行输出。
* This layer lays out a character screen: clear it, colour the text, print lines.
*
* 跑法(桌面 vmlcli):
* How to run (desktop vmlcli):
*   dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/dbase/tty/demo_tty.prg
*
* 实现说明:`Lib/dbase/` 下没有 tty 声明文件、`Lib/dbase/builtin.vml` 也没有链 tty.vml,
* Implementation note: there is no tty declaration file under Lib/dbase/ and Lib/dbase/builtin.vml does not link tty.vml either,
* 所以这里用 ANSI 转义串表达同一件事(清屏 ESC[2J、颜色 ESC[<n>m、复位 ESC[0m)。
* so this file expresses the same thing with ANSI escapes (clear ESC[2J, colour ESC[<n>m, reset ESC[0m).
* `CHR(27)` 是 dBase 标准函数,返回单字符串 —— ESC 就靠它拼出来。
* CHR(27) is the standard dBase function returning a one-character string -- that is how ESC is built.

esc = CHR(27)
? esc + "[2J" + esc + "[H" + esc + "[1;36m" + "=== dBase TTY demo ===" + esc + "[0m"
? esc + "[33m" + "  yellow: tty layer / color console" + esc + "[0m"
? esc + "[32m" + "  green : clear screen + SGR colors" + esc + "[0m"
? esc + "[35m" + "  magenta: loop follows" + esc + "[0m"

i = 1
DO WHILE i <= 3
  ? esc + "[34m" + "  loop line " + STR(i) + esc + "[0m"
  i = i + 1
ENDDO

? esc + "[0m"
? "dBase TTY demo: done"