Git Product home page Git Product logo

Comments (6)

AmokHuginnsson avatar AmokHuginnsson commented on May 18, 2024

Hello.

I am willing to accept pull request introducing a change that would provide
equivalent functionality.

I imagine adding rx->set_input_timeout( count_ms ) API call for each
rx->input(prompt) call. In case of timeout rx->input(prompt) would return nullptr and errno would be set to EINTR just like when user press CTRL+C.

I am against handling this functionality though timers or signals, or threads.

What would have to implemented is timeout aware low level (working on Linux and Windows) character reading routines.

You can look at io.cxx for place where one would start implementing such feature.

from replxx.

AmokHuginnsson avatar AmokHuginnsson commented on May 18, 2024

Requested behavior can now be achieved through replxx->emulate_key_press() API call.

from replxx.

aasimon avatar aasimon commented on May 18, 2024

I have experimented with using the emulate_key_press method to achieve this functionality but am failing to see how I could manage it.
Ideally I would send some key sequence that would get caught in the rx.input(prompt) loop which would then be able to handle this sequence before resuming at the point where the users actual input was at the time.

If you could describe how you imagine emulate_key_press used to get the desired behavior it would be most helpful :-)

from replxx.

AmokHuginnsson avatar AmokHuginnsson commented on May 18, 2024

I think the easiest solution is to send sequence CTRL+C and CTRL+D from other thread that measures the timeout.

rx.emulate_key_press( Replxx::KEY::control('C') );
rx.emulate_key_press( Replxx::KEY::control('D') );

Or (if you want cleaner terminal) CTRL+U, CTRL+K, CTRL+D.

from replxx.

aasimon avatar aasimon commented on May 18, 2024

But that would terminate the entire application. I have not been clear on my original intention for the feature request; What I need is a way to have (in the same thread) a callback being called which will perform reading from a socket that can activate commands from a remote host.
If a user is already typing a command this should be preserved and the carrier resumed from the same position after the callback has terminated.

This is the behavior of rl_set_keyboard_input_timeout as is has been implemented in libreadline.

from replxx.

AmokHuginnsson avatar AmokHuginnsson commented on May 18, 2024

It seems to me that you want to multiplex(*) stdin with sockets and it seems to me that your request for timeout API is purely accidental and unrelated to the core of your need.
In my opinion GNU readline time-out API is not meant to provide multiplexing capabilities.
I am not sure that replxx will ever support explicit timeouts API or multiplexing with other input streams as both needs can be satisfied using multi-threading.

In theory, I/O multiplexing could be added to replxx but it would result in dangerous project scope creep, replxx still has ambitions to be small and simple.
I am not sure that even GNU readline with its huge API supports your actual scenario.

  • central I/O->handler dispatcher supporting stdin and other fds (sockets)

from replxx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.