Thread overview
Mimicking a shell
Dec 29, 2019
Jan
Dec 29, 2019
Adam D. Ruppe
Jan 04, 2020
Jan
Jan 04, 2020
Adam D. Ruppe
Jan 06, 2020
Jan
Dec 30, 2019
angel
December 29, 2019
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
December 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?
December 30, 2019
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,
> Jan

IMHO, 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.
January 04, 2020
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:
>> 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?

I am using Linux (Fedora).

Thanks, @angel. I'll take a look at your suggestion :)
January 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!
January 06, 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 :)