* * *

Author Topic: ncurses: alternate characters on Mac  (Read 919 times)

ulrichsg

  • Newbie
  • Posts: 2
ncurses: alternate characters on Mac
« on: May 21, 2017, 10:00:11 am »
Hello all,

I am trying to port a Turbo Pascal DOS program I wrote over 20 years ago to FPC (using v3.0.2 on OSX). For screen manipulation and special characters I am using ncurses and the oCrt unit. But special characters aren't quite working as advertised: nFrame() and nDrawBox() draw boxes with no top and bottom borders (highlighting them shows they actually consist of invisible � characters); nHLine() shows the same behavior, unsurprisingly. Most of the "alternate character" functions also yield (visible) �s when printed with nWriteAC(), and the few that don't yield characters completely different from what they should.

I've already tried to forgo the ACS entirely and rely on UTF-8 instead, but couldn't quite figure out the right way to do so. It seems to me I should convert a Unicode string literal like '█' (U+2588) to pwchar_t (how?), use setcchar() to further convert it to pcchar_t and finally use mvwadd_wch to print it, but without documentation I'm not even sure if I'm just doing it incorrectly or if I've got the completely wrong idea.

Any help - with either ACS or UTF-8 - would be greatly appreciated.

Edit: And just like that, progress! I found out how to do Unicode without all the conversion stuff - I was just missing the 'uses cwstring' declaration. Now I can have as many █s as I want.

I guess I could use that to roll my own version of nDrawBox() as well, but I'd still like to know if there's an easier way.
« Last Edit: May 21, 2017, 10:12:19 am by ulrichsg »

Thaddy

  • Hero Member
  • *****
  • Posts: 4779
Re: ncurses: alternate characters on Mac
« Reply #1 on: May 21, 2017, 10:24:21 am »
The easiest is to use FreeVision. That's the library the basic fp terminal mode editor uses. It almost equals TurboVision.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

wp

  • Hero Member
  • *****
  • Posts: 3956
Re: ncurses: alternate characters on Mac
« Reply #2 on: May 21, 2017, 11:47:47 am »
This sample code brings back old DOS feeling (I assume you are on Windows):

Code: Pascal  [Select]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. var
  6.   ch: Char;
  7.   i: Integer;
  8.  
  9. begin
  10.   WriteLn('┌──────────────────────┐');
  11.   WriteLn('│ Text in a box        │');
  12.   WriteLn('╘══════════════════════╛');
  13.   WriteLn;
  14.   i := 0;
  15.   for ch := #32 to #255 do begin
  16.     Write(ch, ' ');
  17.     inc(i);
  18.     if i mod 16 = 0 then WriteLn;
  19.   end;
  20.   WriteLn;
  21.   WriteLn(' 1           ');
  22.   WriteLn(' ⌠           ');
  23.   WriteLn(' │ 2 x dx = 1');
  24.   WriteLn(' ⌡           ');
  25.   WriteLn(' 0           ');
  26.   WriteLn;
  27.   WriteLn(' __');
  28.   WriteLn('√ 2 = ', sqrt(2));
  29. end.  

Please make sure that this source file is stored with encoding CP437 - right-click on the file in the Lazarus editor, select "File settings" > "Encoding" > "CP437". And, in order to show all characters correctly in the console, you must switch the console to codepage 437, i.e. you type "chcp 437" in the console. (The wiki article http://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode#Problem_System_encoding_and_Console_encoding_.28Windows.29 shows a method how to integrate codepage switching into the program directly, but this does not seem to work).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Bart

  • Hero Member
  • *****
  • Posts: 2762
    • Bart en Mariska's Webstek
Re: ncurses: alternate characters on Mac
« Reply #3 on: May 21, 2017, 12:08:08 pm »
@wp: you did notice TS is on a Mac?

Bart

wp

  • Hero Member
  • *****
  • Posts: 3956
Re: ncurses: alternate characters on Mac
« Reply #4 on: May 21, 2017, 12:39:28 pm »
No...
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

ulrichsg

  • Newbie
  • Posts: 2
Re: ncurses: alternate characters on Mac
« Reply #5 on: May 22, 2017, 06:31:10 pm »
Thanks for your replies. As Bart noted, I am not using Windows (nor Lazarus), so fiddling with codepages won't be possible. And using FreeVision would be overkill for what I'm doing, so I'll just go ahead and write my own box drawing code. I appreciate you trying to help me though :)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus