Colors 在Ada-ANSI转义码中打印彩色文本似乎不可能工作
我想使用ANSI转义序列来打印Ada中的样式文本 这就是我尝试过的:Colors 在Ada-ANSI转义码中打印彩色文本似乎不可能工作,colors,terminal,ada,Colors,Terminal,Ada,我想使用ANSI转义序列来打印Ada中的样式文本 这就是我尝试过的: with Ada.Text_IO; use Ada.Text_IO; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; procedure Main is begin -- No ESC character Put_Line("\033[93mHowdy!\033[0m"); Put_Line("033[31;1;4mHello\033[0m");
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
procedure Main is
begin
-- No ESC character
Put_Line("\033[93mHowdy!\033[0m");
Put_Line("033[31;1;4mHello\033[0m");
-- With ESC character
Put_Line(ESC & "\033[93m" & "Howdy!" & ESC & "\033[0m");
Put_Line(ESC & "033[93m" & "Howdy!" & ESC & "033[0m");
Put_Line(ESC & "033[31;1;4mHello" & ESC & "\033[0m");
Put_Line(ESC & "Howdy"); -- Prints "owdy", i.e. escapes the H
end;
他们都不工作!每一条语句都只是打印出纯文本。我想出来了——我太接近了
结果表明,字符序列\033
是ASCII转义字符,而不是带内信号的一部分
这是一个非常简单的修复,使用ESC
字符,如Ada.Characters.Latin\u 1
所定义:
Put_Line (ESC & "[93m" & "Howdy!" & ESC & "[0m");
以橙色文本打印“Howdy”。我想在Windows 10上执行此操作:它不适用于DOS控制台或Powershell。见下图 批处理文件工作并来自 我认为这与这里解释的问题有关: 源代码或:
据我所知,这只适用于类似Unix的终端,不是吗?可能吧。我只使用Unix机器,所以我不知道其他情况-对不起。@LoneAnder-不,IIRC,ANSI控制代码是硬件级别的,比如EGA或VGA。也许你应该看看这里(法语):在Ada中有ANSI控制台的完整包定义
with Ada.Text_IO;
with Ada.Wide_Text_IO;
with Ada.Characters.Latin_1;
with Ada.Characters.Wide_Latin_1;
pragma Wide_Character_Encoding (Utf8);
procedure hello is
begin
Ada.Text_IO.Put_Line ("");
Ada.Text_IO.Put_Line ("Ada.Text_IO");
Ada.Text_IO.Put (Ada.Characters.Latin_1.Percent_Sign);
Ada.Text_IO.Put
(Ada.Characters.Latin_1.ESC &
"[93m" &
"Howdy!" &
Ada.Characters.Latin_1.ESC &
"[0m");
Ada.Text_IO.Put_Line ("");
Ada.Text_IO.Put_Line ("");
Ada.Text_IO.Put_Line ("Ada.Wide_Text_IO");
Ada.Wide_Text_IO.Set_Output (File => Ada.Wide_Text_IO.Standard_Output);
Ada.Wide_Text_IO.Set_Error (File => Ada.Wide_Text_IO.Standard_Error);
Ada.Wide_Text_IO.Put (Ada.Characters.Wide_Latin_1.Percent_Sign);
Ada.Wide_Text_IO.Put_Line ("");
Ada.Wide_Text_IO.Put
(Ada.Characters.Wide_Latin_1.ESC &
"[93m" &
"Howdy!" &
Ada.Characters.Wide_Latin_1.ESC &
"[0m");
Ada.Text_IO.Put_Line ("");
Ada.Text_IO.Put_Line ("");
end;