Hi Y'All,
I'm rather baffled by the fact that one or more
fpc switch combos affects
ncurses so much!!!
The program where I'm seeing this happen:
program laz_nCurses;
{$mode objfpc}{$H+}
uses
ncurses, sysutils, initc;
procedure setlocale(cat : integer; p : pchar); cdecl; external clib;
const
LC_ALL = 6;
var
index: Integer;
win_bg: Smallint = COLOR_BLUE;
win_top,
win_bottom: PWINDOW;
has_colours: Boolean = False;
use_default_colours: Boolean = False;
ch: chtype;
command_str, clear_str: String;
begin
command_str:= '';
setlocale(LC_ALL, '');
try
initscr;
noecho;
cbreak;
keypad(stdscr, TRUE);
meta(stdscr, TRUE);
halfdelay(10);
if has_colors then
begin
has_colours:= True;
start_color;
if (use_default_colors = OK) then
begin
use_default_colours:= True;
win_bg := -1;
end;
init_pair(1, COLOR_WHITE, win_bg);
end;
win_top:= newwin(LINES-5, COLS, 0, 0);
win_bottom:= newwin(5, COLS, LINES-5, 0);
if has_colours then
begin
wbkgd(win_top, COLOR_PAIR(1));
wbkgd(win_bottom, COLOR_PAIR(1));
end;
erase;
refresh;
box(win_top, ACS_VLINE, ACS_HLINE);
box(win_bottom, ACS_VLINE, ACS_HLINE);
if has_colours then
mvwaddstr(win_top, 1, 2, 'Has colours');
if use_default_colours then
mvwaddstr(win_top, 2, 2, 'Use default colours');
mvwaddstr(win_bottom, 4, 1, ' Press F1 to exit ');
wmove(win_bottom, 3,1);
wrefresh(win_top);
wrefresh(win_bottom);
clear_str:='';
for index:= 1 to COLS-3 do
begin
clear_str+= ' ';
end;
repeat
ch:= getch;
case ch of
chtype('a')..chtype('z'),
chtype('A')..chtype('Z'):begin
if Length(command_str) <= (COLS - 4) then
begin
command_str+= char(ch);
end
else
begin
flash;
end;
end;
KEY_BACKSPACE:begin
if Length(command_str) > 0 then
begin
SetLength(command_str, Length(command_str) - 1);
end;
end;
10:begin
flash;
end;
KEY_RESIZE:begin
wclear(win_bottom);
mvwin(win_bottom,LINES-5,0);
box(win_bottom, ACS_VLINE, ACS_HLINE);
mvwaddstr(win_bottom, 4, 1, ' Press F1 to exit ');
wrefresh(win_bottom);
wclear(win_top);
wresize(win_top, LINES-5, COLS);
box(win_top, ACS_VLINE, ACS_HLINE);
mvwaddstr(win_top,5,1,PCHAR(format('Lines: %d; Cols: %d',[LINES,COLS])));
wrefresh(win_top);
end;
end;
wmove(win_bottom, 3,1);
waddstr(win_bottom, PCHAR(clear_str));
wmove(win_bottom, 3,1);
waddstr(win_bottom, PCHAR(command_str));
wrefresh(win_bottom);
until ch = KEY_F(1);
finally
delwin(win_top);
delwin(win_bottom);
endwin;
//WriteLN('Command entered: ', command_str);
end;
end.
The script I'm using to compile it:
#!/bin/bash
/home/gcarreno/FreePascal/fpc/bin/x86_64-linux/fpc.sh \
-MObjFPC \
-Scghi \
-O1 \
-g \
-gl \
-l \
-vewnhibq \
-Fi/home/gcarreno/Programming/lazNCurses/bin/lib/x86_64-linux \
-Fu/home/gcarreno/Programming/lazNCurses/src/ \
-FU/home/gcarreno/Programming/lazNCurses/bin/lib/x86_64-linux/ \
-FE/home/gcarreno/Programming/lazNCurses/bin/ \
/home/gcarreno/Programming/lazNCurses/src/laz_nCurses.pas
NOTE: The same
fpcupdeluxe install dir is being used by the script and the IDE, that contains
trunk, if anyone mentions apples to apples comparison!!

When I use the above script as is, I get the result shown in the
lazncurses-O1 image below.
When I change the optimisation to
-O2 on the above script, I get the result shown in the
lazncurses-O2 image below.
When I
don't use the above script, but use Lazarus 4.99 ( Updated today 22 Jun 2025 ), I get the result in the
lazncurses-Lazarus-4.99 image below.
Many things now baffle me!!
- On the
-O1 and
-O2 cases, I'm able to have the
ACS_* thing working. But somehow,
-O2 makes the text on the upper box go away.
- When running the binary compiled by Lazarus, the text works, but the
ACS_* does not work.
BTW, the
ACS_* is a set of functions that allows to translate characters to cardinals. And you can rely on that to manage the border characters used with the
box utility. They kinda work like constants, but somehow are functions... go figure...
I'm rather confused by this. Especially because I was under the impression that the
ACS_* stuff was reliant on the console being in
UTF8 mode. And this kinda denies it... I think... Still not sure because I haven't taken the time to see what switches differ from my script and the default set of switches that Lazarus employs( I don't think I've messed with those )
Can anyone, please,
PLEASE, with sugar on top, help me suss out what's going on here?
Many,
MANY thanks in advance !!!
Cheers,
Gus