-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pause Cursive program and pass stdin and stdout to subprocess #199
Comments
Hi! Cursive currently sets up the terminal at creation ( Being able to "pause" the cursive app while executing something else sounds like a good use-case, and shouldn't be too hard. Maybe something like |
I am interested in this functionality, too: for spawning vim from a cursive app. |
@matthiasbeyer I'm building a terminal widget. It can't handle control codes yet but I am working on it. This can give you a window you can attach an external command to. It's currently buried in https://github.com/igbc/cue but I can break it into a crate as soon as someone want's it for something. |
@IGBC I tried running your program but I get a whole bunch of errors if I try to run anything more complex than I tried messing with this some more but still got nowhere. I added this function to pub fn pause(&mut self) {
self.running = false; // what quit() calls
self.backend.finish(); // what drop() calls
} But, even if I called that before the I thought it might have something to do with the separate thread fn init() -> Self {
...
let process_input = true;
thread::spawn(move || {
for key in ::std::io::stdin().events() {
if process_input {
if let Ok(key) = key {
sender.send(key)
}
}
}
});
...
}
...
fn pause(&mut self) {
self.process_input = false;
print!("{}", ToMainScreen); // what AlternateScreen's drop() calls
} But calling It seems like Cursive doesn't really clean up after itself and return the terminal to normal until after the whole Rust program exits, and I can't get that same process to happen while the program is still running. |
yes the output is passed back into cursive, the idea is to create an embedded terminal emulator inside of cursive. The errors you are encountering are because this is still a work in progress and not remotely shipable yet. |
There are still some issues with launching a sub-program from within Cursive that have not been solved (see: gyscos/cursive#199). But, it works for the most part.
I am also interested by getting access to stdout, my use case is much simpler. I want to be able to get the output of cursive and use as part of some command, for example
This doesn't work today because Cursive uses Let me know what you think :) |
Ah indeed, I didn't know about Latest master should now use this instead of |
@gyscos the |
We still print a few things to stdout, I still need to replace these with writing to the tty. |
Ah yes, I was able to reproduce the issue with extra characters after going in circles for a while. The extra characters are not visible, gotta love it. |
2729e77 should remove the last bits we were writing to For the pancurses backend, we're waiting on a new release to make |
I confirm that back-tick use case works for me with the latest commit 👍 Looking forward to the next release - and maybe we can get also cursive_table_view to upgrade. |
Just added the
|
Maybe just me, but much minimal - even artificial - example showing this feature would be also welcome. |
Ah, sorry, the example only shows how stdin/stdout are now free for other usages, like piping data. This "feature" is more abstract and really simple, so I hope it won't be too confusing. |
Maybe a multiplexer-mode can be added? To make a terminal emulator inside cursive to allow other interactive terminal apps will be a killing feature. I think it can be implemented similar to this |
There is already a multiplexer for cursive! |
@matthiasbeyer They are different. I want to open other TUI app inside, not just another internal cursive view. |
I understood that! You think of a terminal emulator that can be used to start, for example, vim inside a cursive app. There's no need for a tiling functionality, because there's the cursive-multiplex crate that can handle that part. |
So there's a bunch of different needs here:
The last point seems to be what |
@gyscos Indeed writing a terminal emulator properly is fair amount of work. Maybe |
I'd rather use a VTE binding library to implement one, tbh. |
additional event loop implementation will be needed to terminal emulation if just using rust VTE crate. |
The latest commit starts experimenting with the idea of pausable/resumable backends. More specifically:
As a result you should be able to run an event loop; when it exits, the terminal will be reset, and you can run another process (bash, vim, ...), and when that process completes, you can re-use the same It's quite a big change, and will likely take a major version bump. In particular, it moves the error handling from cursive creation to running the event loop. A It's still experimental though: I'm not 100% sure yet if backends can be initialized again multiple times without issue. There may very well be memory leaks or possibly lost input - will need to test some more. |
Added the |
The example seems to be located here now 😃. |
I am new to Rust and this library so I'm not sure if this is currently possible.
Problem description
I'm trying to make a Cursive program that will launch another interactive program and then resume after the program exits. I'm using the Termion backend. I have tried this on the callback of a submit:
But it seems like Cursive in the background is still reacting to the stdin and the spawned program isn't working correctly (I have to hit tab multiple times before w3m responds and goes to the next link, there's no cursor, etc.). If I run that code above in a fresh main.rs without Cursive, the spawned program behaves fine.
blessed, a terminal UI library in Node.js has a function for this called spawn.
The cursor would have to be shown again and Cursive would need to stop processing stdin until the spawned program closes.
Environment
locale
in a terminal): en_US.UTF-8Thanks for creating this library. I've been able to get a lot done with it so far!
The text was updated successfully, but these errors were encountered: