Recent

Author Topic: Free Pascal ncurses TUI  (Read 915 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1250
  • Professional amateur ;-P
Free Pascal ncurses TUI
« on: June 21, 2025, 08:38:29 pm »
Hey Y'All,

Been doing a bit of work trying to get the LCL pattern on top of ncurses:
FP-NCURSES-TUI on GitHub

I've been able to do a rudimentary approximation on these:
  • TApplication
  • TBaseComponent
  • TForm - Derives from TBaseComponent
  • TLabel - Derives from TBaseComponent

I'm sure some of you, and you now who you are @pavel, would like me to use generics on the form list and component list.
But I'm not sure if I'll extract the lists into self contained object. Having to create messages manually is not nice and it probably would make sense to do that on the list. Time will tell.  ;)

Working with ncurses is not hard, but it's quite the challenge when you implement an event system. Messages are firing left and right and one looses track on the flow of updates/refreshes/painting. At the moment the thing works, but if I'm fair, it's a bloody mess  :D

Please have a gander and tell me what you think. There will be downloadable executable binaries of the examples in a near future. I'm planning on implementing a Main Menu next, and thar will be the next example. Once I have those 2, I'll drop the GitHub workflows that will enable the executables to be downloaded.

Cheers,
Gus
« Last Edit: June 21, 2025, 08:46:48 pm by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

cdbc

  • Hero Member
  • *****
  • Posts: 2253
    • http://www.cdbc.dk
Re: Free Pascal ncurses TUI
« Reply #1 on: June 21, 2025, 09:05:18 pm »
Hi Gus
I've got a messagequeue and messagepump implemented, let me know if you can use something like that... -- no generics  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1250
  • Professional amateur ;-P
Re: Free Pascal ncurses TUI
« Reply #2 on: June 21, 2025, 09:16:14 pm »
Hey Benny,

I've got a messagequeue and messagepump implemented, let me know if you can use something like that... -- no generics  :D

Unfortunately, the container itself is rather irrelevant. The tricky part is managing the HandleMessages on each component.   >:(
At the moment, I did my best to try and put as much as I can on the ancestors: TBaseComponent and TForm, but it's still rather crappy  :-[
I'll need some keen eyes on that part, if any one can spare them.

Having said that, I'm always quite happy to expand the amount of items in my knowledge base, so I would be quite interested if you can point to that body of work for me to have a good gander!!!  :)
And I quite like the "no generics" wink :D

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

cdbc

  • Hero Member
  • *****
  • Posts: 2253
    • http://www.cdbc.dk
Re: Free Pascal ncurses TUI
« Reply #3 on: June 21, 2025, 10:07:27 pm »
Hi Gus
It so happens that I incorporated it in another framework and apps, so it's right here in Gitlab
The source files are placed in 'utils' and under 'apps' -> mqtt-client -> views -> 'view.log.pas/.lfm
The msg-producers are located in 'src' -> mqtt. -synacli.pas, -indycli.pas, lnetcli.pas & -fclncli.pas, which are all pluggable comms-threads...
Basically you need 'mqtt.msgqueue.pas', the rest is for you to see how to use it... The entire repo is selfcontained, meaning it contains both servers and clients, but can also run up against 'Mosquitto', it's actually tested with Mosquitto :)
Let me know what you think  8-)
Regards Benny

eta: also have a look in 'apps' -> 'mqtt-broker-synapse' -> 'mbs.lpr'
« Last Edit: June 21, 2025, 10:25:14 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1250
  • Professional amateur ;-P
Re: Free Pascal ncurses TUI
« Reply #4 on: June 22, 2025, 12:23:51 am »
Hey Benny,

It so happens that I incorporated it in another framework and apps, so it's right here in Gitlab
The source files are placed in 'utils' and under 'apps' -> mqtt-client -> views -> 'view.log.pas/.lfm
The msg-producers are located in 'src' -> mqtt. -synacli.pas, -indycli.pas, lnetcli.pas & -fclncli.pas, which are all pluggable comms-threads...
Basically you need 'mqtt.msgqueue.pas', the rest is for you to see how to use it... The entire repo is selfcontained, meaning it contains both servers and clients, but can also run up against 'Mosquitto', it's actually tested with Mosquitto :)
Let me know what you think  8-)

eta: also have a look in 'apps' -> 'mqtt-broker-synapse' -> 'mbs.lpr'

AWESOME SAUCE !! Thank you so very much!!
I'm about to go to bed, so I'll have a look at it later on.

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1250
  • Professional amateur ;-P
Re: Free Pascal ncurses TUI
« Reply #5 on: June 22, 2025, 12:29:16 am »
Hey Y'All,

After some introspection and a bit of chat with my lill friend, I got to the conclusion that I'm binding to ncurses too soon!!  >:(

Ultimately, this means that I need to perform a major refactor in the entire thing.

I was also having major headaches, sure completely my fault, with circular refs in this hierarchical architecture. I'm now a bit less burden with old stupidity and have a new approach that will fix that, finger crossed!!

I've started the refactor, but I'm rather pooped and need some ZzZZ in order to function.

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1250
  • Professional amateur ;-P
Re: Free Pascal ncurses TUI
« Reply #6 on: June 25, 2025, 03:52:42 am »
Hey Y'All,

Status report: I've finished my refactoring and I even added 2 components.

What changed:
  • Complete refactoring of the application, form and components with base classes for all
  • Addition of a wrapper class around the ncurses window. This will help with fakes/mocks when testing
  • The components now write directly to the form's window/rectangle. This will help with clipping, I hope!!
  • Added a label(Static Text)
  • Added a button
  • There now exist 4 examples: One Form, Two Forms, Component Label, Component Button
  • The GitHub repo now has a workflow to generate releases with compiled examples
  • Released version v0.0.7 just to trigger the above workflow and have the examples to download

Not quite sure what to do next, since my ToDo list is thus:
  • Mess about with colors in order to have themes
  • Mess about with layouts

Cheers,
Gus
« Last Edit: June 25, 2025, 04:01:43 am by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

 

TinyPortal © 2005-2018