cobol/tty/demo_tty.cob · 2456 字节 · 下载原文
*> demo_tty.cob —— COBOL 第二层:**彩色命令行**(tty)
*> demo_tty.cob -- COBOL layer 2: **colour command line** (tty)
*>
*> 这一层做「在字符界面上排版」:清屏、定位、设前景/背景色、写一行。
*> This layer lays out a character screen: clear, position, set fg/bg colour, write a line.
*>
*> 跑法(桌面 vmlcli):
*> How to run (desktop vmlcli):
*> dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/cobol/tty/demo_tty.cob
*>
*> 实现说明:`Lib/cobol/builtin.vml` 已经 `.linked "../shared/tty.vml"`,
*> Implementation note: Lib/cobol/builtin.vml already has `.linked "../shared/tty.vml"`,
*> 所以 `tty_*` 可以像 `ui_*` 一样用 `CALL "名字" USING …` 直接调(没有声明文件也能链上)。
*> so tty_* can be called with `CALL "name" USING ...` just like ui_* (no declaration file needed).
*>
*> 坐标 **1 起算**、`tty_goto(列, 行)`;颜色 **0–15 索引色**(14=黄 11=亮青 7=浅灰)。
*> Coordinates are **1-based**, `tty_goto(column, row)`; colours are **indexed 0-15** (14=yellow 11=light cyan 7=light grey).
IDENTIFICATION DIVISION.
PROGRAM-ID. DEMO-TTY.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-I PIC S9(9) VALUE 0.
01 WS-ROW PIC S9(9) VALUE 0.
PROCEDURE DIVISION.
MAIN-PARA.
CALL "tty_cls".
CALL "tty_color" USING 11 0.
CALL "tty_goto" USING 2 2.
CALL "tty_puts" USING "=== COBOL TTY demo ===".
CALL "tty_color" USING 14 1.
CALL "tty_goto" USING 2 4.
CALL "tty_puts" USING " yellow on blue ".
CALL "tty_color" USING 10 0.
CALL "tty_goto" USING 2 6.
CALL "tty_puts" USING " light green on black ".
CALL "tty_color" USING 13 0.
CALL "tty_goto" USING 2 8.
CALL "tty_puts" USING " light magenta on black ".
PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 3
ADD 10 TO WS-I GIVING WS-ROW
CALL "tty_color" USING 12 0
CALL "tty_goto" USING 2 WS-ROW
CALL "tty_puts" USING " loop line "
END-PERFORM.
CALL "tty_color" USING 7 0.
CALL "tty_goto" USING 1 24.
CALL "tty_puts" USING "COBOL TTY demo: done".
STOP RUN.