digitalmars.D.learn - Mimicking a shell
- Jan (8/8) Dec 29 2019 Hi,
- Adam D. Ruppe (4/5) Dec 29 2019 yes, but it is platform specific and can be a decent amount of
- Jan (3/8) Jan 04 2020 I am using Linux (Fedora).
- Adam D. Ruppe (12/14) Jan 04 2020 ok, the starting point is `openpty` which gives you a
- Jan (6/9) Jan 06 2020 I think the suggestion of angel would be most fitting for my
- angel (5/13) Dec 29 2019 IMHO, this is kinda what you need:
Hi, Is there a way to forward all input and output from a shell? This implies that e.g. pressing the left arrow on the keyboard is immediately being forwarded to the shell and that the output from a shell would be *exactly* the same as output from my D program (that would include the prompt and VGA colouring). Kind regards, Jan
Dec 29 2019
On Sunday, 29 December 2019 at 17:03:14 UTC, Jan wrote:Is there a way to forward all input and output from a shell?yes, but it is platform specific and can be a decent amount of code. what OS are you on?
Dec 29 2019
On Sunday, 29 December 2019 at 19:21:53 UTC, Adam D. Ruppe wrote:On Sunday, 29 December 2019 at 17:03:14 UTC, Jan wrote:I am using Linux (Fedora). Thanks, angel. I'll take a look at your suggestion :)Is there a way to forward all input and output from a shell?yes, but it is platform specific and can be a decent amount of code. what OS are you on?
Jan 04 2020
On Saturday, 4 January 2020 at 18:43:13 UTC, Jan wrote:I am using Linux (Fedora).ok, the starting point is `openpty` which gives you a communication pipe that the other program sees as a terminal. from there if you are just forwarding you can perhaps shoot bytes to and from without interpreting them. but if you want to send like a synthetic arrow keystroke, well, things get ugly again, it will need to send the right series of bytes based on what terminal the program thinks you are. Like "\033[C" is right arrow on xterm, probably a reasonably safe bet you can make that work. hit ctrl+v then a key in your terminal to see the output. ^[ == "\033" btw there.Thanks, angel. I'll take a look at your suggestion :)yes good luck!
Jan 04 2020
I think the suggestion of angel would be most fitting for my case. As angel said, the using the C code for D would be a relatively small refactor.if you want to send like a synthetic arrow keystroke, well, things get ugly again, it will need to send the right series of bytes based on what terminal the program thinks you are.Using arrow key etc. would be very beneficial for my case. So I thank Adam for his solution, but I prefer angel's one. Thanks guys :)
Jan 06 2020
On Sunday, 29 December 2019 at 17:03:14 UTC, Jan wrote:Hi, Is there a way to forward all input and output from a shell? This implies that e.g. pressing the left arrow on the keyboard is immediately being forwarded to the shell and that the output from a shell would be *exactly* the same as output from my D program (that would include the prompt and VGA colouring). Kind regards, JanIMHO, this is kinda what you need: https://github.com/greenduck/shell-tunnel/blob/master/shell-tunnel.c Sorry, this code is in C, but converting it to D would be fairly straight forward.
Dec 29 2019