I'd like to use ANSI escape sequences to print styled text in Ada.
This is what I've tried:
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;
None of them work! Every statement just prints the plaintext.
I figured it out -- I was so close!
It turns out that the character sequence \033 is the ASCII escape character, and not part of the in-band signal.
It's a very simple fix, using the ESC character as defined by Ada.Characters.Latin_1:
Put_Line (ESC & "[93m" & "Howdy!" & ESC & "[0m");
Prints "Howdy" in orange text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With