Recent

Author Topic: Draw ANSI/ASCII art in terminal support and suggestions wanted.  (Read 1102 times)

d-_-b

  • New Member
  • *
  • Posts: 35
Hi,

I hope someone can point me to some general pascal libraries to draw ascii art border like in this examples i found on the forum?

I also tested the Unicode support on windows 10 using dos, ubuntu wsl console, and mobaxterm.

Unfortunately only mobaxterm is rendering correctly.  :o  >:(

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$APPTYPE CONSOLE}
  5.  
  6. uses
  7.   {$IFDEF WINDOWS}
  8.   Windows, {for setconsoleoutputcp}
  9.   {$ENDIF}
  10.   Classes;
  11. const
  12.   // ANSI table drawing chars
  13.   tdTopLeft      = #27'(0l'#27'(B';  // ┌
  14.   tdTopCenter    = #27'(0w'#27'(B';  // ┬
  15.   tdTopRight     = #27'(0k'#27'(B';  // ┐
  16.   tdMidLeft      = #27'(0t'#27'(B';  // ├
  17.   tdMidCenter    = #27'(0n'#27'(B';  // ┼
  18.   tdMidRight     = #27'(0u'#27'(B';  // ┤
  19.   tdBottomLeft   = #27'(0m'#27'(B';  // └
  20.   tdBottomCenter = #27'(0v'#27'(B';  // ┴
  21.   tdBottomRight  = #27'(0j'#27'(B';  // ┘
  22.   tdHorzLine     = #27'(0q'#27'(B';  // ─
  23.   tdVertLine     = #27'(0x'#27'(B';  // │    
  24. var
  25.   i: byte;
  26.   s: string;
  27.   ch: Char;
  28. begin
  29.   {$IFDEF WINDOWS}
  30.   SetConsoleOutputCP(CP_UTF8);
  31.   {$ENDIF}
  32.  
  33.   // thanks wp, https://f...content-available-to-author-only...l.org/index.php/topic,36945.msg246843.html#msg246843
  34.   WriteLn('┌──────────────────────┐');
  35.   WriteLn('│ Text in a box        │');
  36.   WriteLn('╘══════════════════════╛');
  37.   WriteLn;
  38.   i := 0;
  39.   for ch := #32 to #255 do begin
  40.     Write(ch, ' ');
  41.     inc(i);
  42.     if i mod 16 = 0 then WriteLn;
  43.   end;
  44.   WriteLn;
  45.   WriteLn(' 1           ');
  46.   WriteLn(' ⌠           ');
  47.   WriteLn(' │ 2 x dx = 1');
  48.   WriteLn(' ⌡           ');
  49.   WriteLn(' 0           ');
  50.   WriteLn;
  51.   WriteLn(' __');
  52.   WriteLn('√ 2 = ', sqrt(2));
  53.   WriteLn;
  54.  
  55.   // thanks wp, https://f...content-available-to-author-only...l.org/index.php/topic,38910.msg265726.html#msg265726
  56.   // Use Unicode range "Box Drawing" in Lazarus' character map
  57.   WriteLn('┏━━┓  ┏━━┓');
  58.   WriteLn('┛  ┗━━┛  ┗');
  59.   WriteLn;
  60.  
  61.   // Thanks Mr Bee aka @pak_lebah, from ansicrt.pas unit
  62.   for i:= 1 to 10 do s:= s + tdHorzLine;
  63.   WriteLn(tdTopLeft + s + tdTopRight);
  64.                          
  65.  
  66.   ReadLn;
  67. end.
  68.  

~ Code In Online Pascal Compiler
Code: Pascal  [Select][+][-]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9260
  • FPC developer.
Re: Draw ANSI/ASCII art in terminal support and suggestions wanted.
« Reply #1 on: April 18, 2020, 09:47:23 pm »
Ansi escape sequences are not very portable, nor universal. Sometimes they need addtional drivers or configuration for emulation purposes.

Here on windows everything but the last for loop seems to be ok.

winni

  • Hero Member
  • *****
  • Posts: 2316
Re: Draw ANSI/ASCII art in terminal support and suggestions wanted.
« Reply #2 on: April 18, 2020, 10:17:04 pm »
Hi!

You are playing around with code from the 80s.

Nearly all terminals use Unicode and not the IBM 8 Bit with the semi graphik frames - like Turbo Pascal did.

For example:

is UTF8 Codepoint U2554

The codeblock in the UTF table is called Box Drawing and is from

U2500 .. U257F


Have a look at the UTF8 table:

https://www.utf8-chartable.de/unicode-utf8-table.pl

Winni

 

TinyPortal © 2005-2018