Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing coloured text in Ada -- ANSI escape codes seem impossible to get working

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.

like image 225
haz Avatar asked Dec 17 '25 20:12

haz


1 Answers

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.

like image 195
haz Avatar answered Dec 19 '25 23:12

haz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!