Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Curses-based applications?

by vkon (Curate)
on Jan 01, 2025 at 19:34 UTC ( [id://11163484]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Curses-based applications?
in thread Curses-based applications?

very preliminary version is at https://github.com/vadrer/perl-tvision, far from CPAN-ready, and XS file have some edits in the middle, which makes it non-functional right now
some screenshot is at https://github.com/vadrer/perl-tvision/blob/main/demo/photo_2025-01-01_22-28-11.jpg
Fortunately will make it to CPAN release in a month or two.
However this is starting point and discussions are welcome on that project page

Replies are listed 'Best First'.
Re^4: Curses-based applications?
by NERDVANA (Priest) on Jan 02, 2025 at 19:27 UTC
    I wrote a blog post! Is that a useful level of detail? I can write more if you like it.

    All my examples are pure C, which get a little more convenient if you're doing it with C++.

      nice read.
      Thanks a lot!

      I have the following roadmap on the module.

      • Initially all objects were refs to scalars, now they are refs to array (for the sake of efficiency), probably they will be hash refs in future, if more flexibility will be needed
      • implement more widgets and their methods
      • typemaps are planned, and this is my next step. Your writing will make this step easier, thanks:)
      • Honestly, your idea about magic is fresh for me. I used magic some 25 years ago, it was nice and fun experience.
        I will sleep with this idea and - who knows - either switch to magic or otherwise will stand with blessed references.
        Now "TButton" is descendant of "TView" so it could use both TButton and TView methods because of @ISA - is the same possible in "magic" approach?
      • I don't affraid of users shooting themselves into the foot. After the damage they will fortunately survive and learn better :)
        Maybe I could write another user-safe wrapper module, around this thinner one, if there will be a request for that :)
        Now "TButton" is descendant of "TView" so it could use both TButton and TView methods because of @ISA - is the same possible in "magic" approach?

        Multiple inheritance is an interesting situation! I think it should work... Your magic would be for type 'TObject*' (or a record with a TObject* field, since extra fields are almost always needed) and then you could use dynamic_cast to find out whether the method was being called on the correct type.

        TVision.xs

        struct tvision_info { TObject *tobj; }; struct tvision_info* tvision_info_from_magic(SV *objref, int flags) { ... }

        typemap

        TYPEMAP TObject* O_TObject TView* O_TView TButton* O_TButton INPUT O_TObject $var= tvision_info_from_magic($arg, OR_DIE)->tobj; O_TView $var= dynamic_cast<TView*>(tvision_info_from_magic($arg, OR_DIE)->to +bj); if (!$var) croak("Not an instance of TView"); O_TButton $var= dynamic_cast<TButton*>(tvision_info_from_magic($arg, OR_DIE)-> +tobj); if (!$var) croak("Not an instance of TButton");

        later in TVision.xs

        bool focus(view) TView* view CODE: RETVAL= view->focus(); OUTPUT: RETVAL

        You might even be able to use a C++ template function to fetch the magic, but I've never tried that. (my C++ is rusty, don't expect this to work as-is)

        template <T> void tvision_obj_from_magic(T *dest, SV *objref, int flag +s) { struct tvision_info* tinfo= tvision_info_from_magic(objref, flags); T typed= tinfo->tobj? dynamic_cast<T>(tinfo->tobj) : NULL; if ((flags & OR_DIE) && !typed) croak("Wrong type of object"); *dest= typed; }
        O_TButton tvision_obj_from_magic(&$var, $arg, OR_DIE);
        Update

        There's no need for a C++ template here because Perl XS provides you a variable '$type'.

        TYPEMAP TObject* O_TObject TView* O_TObject TButton* O_TObject INPUT O_TObject $var= dynamic_cast<$type>(tvision_info_from_magic($arg, OR_DIE)->tob +j); if (!$var) croak("Object is not a $type");

      NERDVANA this is absolutely fantastic and fills a gap or two. Thanks!

      That was really good! It partly answers a nagging question I had after doing those speed comparisons between your Math::3Space vector calculations and doing it in PDL, which is still a bit slow in transitioning between Perl-land and C-land. One thing I know, thanks to using cachegrind, is that looking up a PDL object's pdl* spends a lot of time in hv_common, from sv_derived_from via isa_lookup, as called by the typemap-used pdl_SvPDLV.

      In your opinion, would using this Perl magic scheme be quicker? And if so, does any hero feel like PR-ing (or just commenting some part-way code on https://github.com/PDLPorters/pdl/issues/451, the PDL performance issue) to make PDL-pointer-getting go quicker? (That issue has my previous research that found the hv_common stuff, and also links to the Math::3Space discussion issue)

        Yes I think there are some speedups to be had using Magic for this code, but it's dealing with an awful lot of special cases, so hard to say exactly what the best change would be. I'll leave comments on the issue since it's sort of offtopic for this thread.
Re^4: Curses-based applications?
by NERDVANA (Priest) on Jan 02, 2025 at 04:10 UTC
    I loved the old Borland products, and I used Turbo Vision in the form of SETEdit for a few years in college, and it would be awesome to have it for Perl!

    I have some advice for the XS... but too much advice for here. I might write a blog post...

      SETEdit looks nice :)
      thanks for the link to it
Re^4: Curses-based applications?
by marioroy (Prior) on Jan 04, 2025 at 23:49 UTC
      fantasic!
      So you've managed tvision to run on termux and provided a fix for it?

      Cool!

      Thanks! )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11163484]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2025-02-16 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found