Forum > Beginners

[Solved] Need Help With Ncurses and FPC

(1/1)

NewbieToPascal:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ncurses;var ch : char;begin  ncurses.initscr;  ncurses.raw;  ncurses.keypad(stdscr, True);  ncurses.noecho;  ch :='0';  ncurses.printw('Type something: ');  ncurses.refresh;  ReadLn(ch);  ncurses.printw('You typed: ', ch);  ncurses.refresh;  ReadLn;  ncurses.endwin;end.    
The result is in the attachment picture

NewbieToPascal:
Solved using Bing Copilot (what great time to be alive)

In line 12, it reads


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  ncurses.printw('You typed: ', ch);
it should be


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ncurses;var ch : char;  c : Integer;begin  ncurses.initscr;  ncurses.raw;  ncurses.keypad(stdscr, True);  ncurses.noecho;  ch :='0';  ncurses.printw('Type something: ');  ncurses.refresh;  c:=getch;  ch:=Chr(c);  ncurses.addch(c); //this line adds the char the user typed to the screen  ncurses.refresh();  napms(2000);  clear();  ncurses.printw('You typed: %c', ch);  ncurses.refresh;  ReadLn;  ncurses.endwin;end.      

Thaddy:
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.

NewbieToPascal:

--- Quote from: Thaddy 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.

--- End quote ---

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

Navigation

[0] Message Index

Go to full version