Recent

Author Topic: Drawing a Box like MC  (Read 519 times)

BSaidus

  • Hero Member
  • *****
  • Posts: 540
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Drawing a Box like MC
« on: February 03, 2023, 11:42:49 pm »
Hello.
I'm trying to draw a box like MC(midnight commander) do but, It wont work in windows or FreeBSD.
the box look like.
Code: Pascal  [Select][+][-]
  1. WriteLn( '  ┌──────────────────────────────────────────────────────────────────────┐ ' );
  2. WriteLn( '  │                                                                      │'  );
  3. WriteLn( '  ├──────────────────────────────────────────────────────────────────────┤'  );
  4. WriteLn( '  │                                                                      │'  );
  5. WriteLn( '  │                                                                      │'  );
  6. WriteLn( '  │                                                                      │'  );
  7. WriteLn( '  │                                                                      │'  );
  8. WriteLn( '  │                                                                      │'  );
  9. WriteLn( '  │                                                                      │'  );
  10. WriteLn( '  ├──────────────────────────────────────────────────────────────────────┤'  );
  11. WriteLn( '  │                                                                      │'  );
  12. WriteLn( '  │                                                                      │'  );
  13. WriteLn( '  │                                                                      │'  );
  14. WriteLn( '  │                                                                      │'  );
  15. WriteLn( '  │                                                                      │'  );
  16. WriteLn( '  │                                                                      │'  );
  17. WriteLn( '  ├──────────────────────────────────────────────────────────────────────┤'  );
  18. WriteLn( '  │                                                                      │'  );
  19. WriteLn( '  └──────────────────────────────────────────────────────────────────────┘'  );
  20.  

Caracters are printed using
Code: [Select]
ALT + CODE // CODE = 185, ....
but the result is some charaters other then wanted.

Any idea about this ??

Thank you

lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Drawing a Box like MC
« Reply #1 on: February 04, 2023, 12:00:59 am »
If you use Lazarus, try this: menu Edit -> Insert from character map ... and select tab Unicode and item "Box drawing" from the combo below.
It looks fine here, i.e. I got the same characters in writeln('╔═════╗'); and in output.
« Last Edit: February 04, 2023, 12:03:32 am by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Drawing a Box like MC
« Reply #2 on: February 04, 2023, 04:20:44 am »
I asked openAI to write a program for this.

I tweaked the output slightly.
Code: Pascal  [Select][+][-]
  1. program TestDrawBookshelf;
  2. {$mode objfpc}{$H+}
  3.  
  4. uses
  5.   SysUtils;
  6.  
  7. const
  8.  
  9.   HORIZONTAL_LINE: AnsiString = #$E2#$94#$80;
  10.   VERTICAL_LINE: AnsiString = #$E2#$94#$82;
  11.   UPPER_LEFT_CORNER: AnsiString = #$E2#$94#$8C;
  12.   LOWER_LEFT_CORNER: AnsiString = #$E2#$94#$94;
  13.   UPPER_RIGHT_CORNER: AnsiString = #$E2#$94#$90;
  14.   LOWER_RIGHT_CORNER: AnsiString = #$E2#$94#$98;
  15.   LEFT_SHELF_INTERSECTION: AnsiString = #$E2#$94#$9C;
  16.   RIGHT_SHELF_INTERSECTION: AnsiString = #$E2#$94#$A4;
  17.  
  18. procedure DrawBookshelf(width: Integer; shelfHeights: array of Integer);
  19. var
  20.   i, j, k, shelfHeight: Integer;
  21. begin
  22.   // Draw the top of the bookshelf
  23.   Write(UPPER_LEFT_CORNER);
  24.   for i := 1 to width do
  25.     Write(HORIZONTAL_LINE);
  26.   WriteLn(UPPER_RIGHT_CORNER);
  27.  
  28.   // Draw the shelves
  29.   for i := 0 to High(shelfHeights) do
  30.   begin
  31.     shelfHeight := shelfHeights[i];
  32.     Write(LEFT_SHELF_INTERSECTION);
  33.     for j := 1 to width do
  34.       Write(HORIZONTAL_LINE);
  35.     WriteLn(RIGHT_SHELF_INTERSECTION);
  36.  
  37.     // Draw the shelf contents
  38.     for j := 1 to shelfHeight do
  39.     begin
  40.       Write(VERTICAL_LINE);
  41.       for k := 1 to width do
  42.         Write(' ');
  43.       WriteLn(VERTICAL_LINE);
  44.     end;
  45.   end;
  46.  
  47.   // Draw the bottom of the bookshelf
  48.   Write(LOWER_LEFT_CORNER);
  49.   for i := 1 to width do
  50.     Write(HORIZONTAL_LINE);
  51.   WriteLn(LOWER_RIGHT_CORNER);
  52. end;
  53.  
  54. var
  55.   width: Integer;
  56.   shelfHeights: array of Integer;
  57.   i: Integer;
  58. begin
  59.   // Get the width of the bookshelf
  60.   width := StrToInt(ParamStr(1));
  61.  
  62.   // Get the shelf heights
  63.   SetLength(shelfHeights, ParamCount - 1);
  64.   for i := 2 to ParamCount do
  65.     shelfHeights[i - 2] := StrToInt(ParamStr(i));
  66.  
  67.   // Draw the bookshelf
  68.   DrawBookshelf(width, shelfHeights);
  69. end.

The above with ./testdrawbookshelf 40 5 5 0 produces:
Code: Pascal  [Select][+][-]
  1. ┌────────────────────────────────────────┐
  2. ├────────────────────────────────────────┤
  3. │                                        │
  4. │                                        │
  5. │                                        │
  6. │                                        │
  7. │                                        │
  8. ├────────────────────────────────────────┤
  9. │                                        │
  10. │                                        │
  11. │                                        │
  12. │                                        │
  13. │                                        │
  14. ├────────────────────────────────────────┤
  15. └────────────────────────────────────────┘


 

TinyPortal © 2005-2018