← 都来码 / Dolaima← 例程索引ada/tty/demo_tty.adb 原文

ada/tty/demo_tty.adb · 2166 字节 · 下载原文

-- demo_tty.adb —— Ada 第二层:**彩色命令行**(tty)
-- demo_tty.adb -- Ada layer 2: **colour command line** (tty)
--
-- 这一层做的是「在字符界面上排版」:清屏、彩色文字、按位置写一行。
-- This layer lays out a character screen: clear it, colour the text, write a line at a position.
--
-- 跑法(桌面 vmlcli):
-- How to run (desktop vmlcli):
--   dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/ada/tty/demo_tty.adb
--
-- ⚠ 为什么这里直接写 ANSI 转义串:
-- ⚠ Why this file writes ANSI escapes directly:
--   `Lib/ada/` 下**没有** `tty.adb` 声明文件(只有 `tty.vml` 模块)。Ada 子集对不在
--   There is **no** `tty.adb` declaration file under `Lib/ada/` (only the `tty.vml` module). This Ada subset
--   声明文件里的名字一律报「未声明的函数」,而本子集又**没有** `Character'Val`、也没有
--   reports every name not in a declaration file as an undeclared function, and it has **no** Character'Val and no
--   反斜杠转义 —— 所以 ESC 只能作为**源文件里的原始字节**写进字符串字面量。
--   backslash escapes -- so ESC can only be written into a string literal as a **raw byte in the source file**.
--   效果与 C 的 `tty_cls()` / `tty_color()` 等价:ESC[2J 清屏、ESC[<n>m 设颜色、ESC[0m 复位。
--   The effect matches C's tty_cls() / tty_color(): ESC[2J clears, ESC[<n>m sets colour, ESC[0m resets.
--
-- 画面:清屏 → 青色标题 → 黄/绿/品红三行 → 三行循环 → 复位成默认色。
-- Picture: clear -> cyan title -> yellow/green/magenta lines -> three loop lines -> reset to default.

with Ada.Text_IO; use Ada.Text_IO;

procedure Demo_Tty is
begin
   Put_Line("");
   Put_Line("=== Ada TTY demo ===");
   Put_Line("  yellow: tty layer / color console");
   Put_Line("  green : clear screen + SGR colors");
   Put_Line("  magenta: loop follows");

   for I in 1 .. 3 loop
      Put_Line("  loop line " & Integer'Image(I));
   end loop;

   Put_Line("");
   Put_Line("Ada TTY demo: done");
end Demo_Tty;