Comments (6)
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.
Requested behavior can now be achieved through replxx->emulate_key_press()
API call.
from replxx.
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.
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.
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.
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)
- stdin loses unbuffered setting during callbacks HOT 1
- Memory handling for replxx_add_completion() / replxx_add_color_completion() undocumented HOT 1
- Pressing enter right after incremental search doesn't show the accepted line HOT 2
- retrieve last line before EOF HOT 1
- Replxx submitted to Fedora HOT 2
- Prompt is not re-rendered when I press "up" HOT 1
- Multiline text with <tab> leads to crash HOT 4
- How to abort "input" in another thread? HOT 5
- Help: wired behavior of Ctrl-A HOT 2
- segmentation fault on down arrow keypress HOT 5
- How to break loop when user press CTRL+C or CTRL+D or CTRL+Z or ESC ? HOT 2
- Support the switch of beep.
- How to enable multiline HOT 1
- Support custom file descriptors
- Homebrew integration for mac
- Undo
- New warning from gcc 13
- Looks like Marcin Konarski died in November 2021 HOT 5
- Colored user input while displaying hints
- compare() without pos and length
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from replxx.