Recent

Author Topic: [Solved] Need Help With Ncurses and FPC  (Read 832 times)

NewbieToPascal

  • Newbie
  • Posts: 3
[Solved] Need Help With Ncurses and FPC
« on: November 22, 2024, 06:55:36 am »
I'm trying to make a really simple program using FPC and ncurses, it basic read a Char typed by the user and prints it back. The problem is the program does not show what the user wrote when a key is pressed and do not show the Char the user wrote.

The code is the fowling



Code: Pascal  [Select][+][-]
  1. uses ncurses;
  2. var ch : char;
  3. begin
  4.   ncurses.initscr;
  5.   ncurses.raw;
  6.   ncurses.keypad(stdscr, True);
  7.   ncurses.noecho;
  8.   ch :='0';
  9.   ncurses.printw('Type something: ');
  10.   ncurses.refresh;
  11.   ReadLn(ch);
  12.   ncurses.printw('You typed: ', ch);
  13.   ncurses.refresh;
  14.   ReadLn;
  15.   ncurses.endwin;
  16. end.    

The result is in the attachment picture
« Last Edit: November 22, 2024, 08:49:16 am by NewbieToPascal »

NewbieToPascal

  • Newbie
  • Posts: 3
Re: Need Help With Ncurses and FPC
« Reply #1 on: November 22, 2024, 08:48:49 am »
Solved using Bing Copilot (what great time to be alive)

In line 12, it reads

Code: Pascal  [Select][+][-]
  1.   ncurses.printw('You typed: ', ch);

it should be

Code: Pascal  [Select][+][-]
  1.   ncurses.printw('You typed: %c', ch);

And to the char appear while the user is typing it needs to be added to the screen as in the fowlling

Code: Pascal  [Select][+][-]
  1. uses ncurses;
  2. var ch : char;
  3.   c : Integer;
  4. begin
  5.   ncurses.initscr;
  6.   ncurses.raw;
  7.   ncurses.keypad(stdscr, True);
  8.   ncurses.noecho;
  9.   ch :='0';
  10.   ncurses.printw('Type something: ');
  11.   ncurses.refresh;
  12.   c:=getch;
  13.   ch:=Chr(c);
  14.   ncurses.addch(c); //this line adds the char the user typed to the screen
  15.   ncurses.refresh();
  16.   napms(2000);
  17.   clear();
  18.   ncurses.printw('You typed: %c', ch);
  19.   ncurses.refresh;
  20.   ReadLn;
  21.   ncurses.endwin;
  22. end.      

Thaddy

  • Hero Member
  • *****
  • Posts: 16363
  • Censorship about opinions does not belong here.
Re: [Solved] Need Help With Ncurses and FPC
« Reply #2 on: November 22, 2024, 08:57:23 am »
Nice, but I am curious why you used ncurses? That is usually not necessary in your particular case.
Note that I am a big fan of ncurses, but not here.
There is nothing wrong with being blunt. At a minimum it is also honest.

NewbieToPascal

  • Newbie
  • Posts: 3
Re: [Solved] Need Help With Ncurses and FPC
« Reply #3 on: November 22, 2024, 11:27:19 am »
Nice, but I am curious why you used ncurses? That is usually not necessary in your particular case.
Note that I am a big fan of ncurses, but not here.

Just to learn ncurses. I got the idea to make a TUI calculator as a learning task. I could easier do it using Lazarus, with all forms and buttons, but it would not be challenge enough.

BTW: I'm using this How To: https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
 
What library do you think is the "best" for TUI software ?

By "best" I meant specially open source and cross platform. I only know about Ncurses and Free Vision

 

TinyPortal © 2005-2018