Spawning a pty in D

Adam D. Ruppe destructionator at gmail.com
Thu Oct 17 07:12:35 PDT 2013


On Thursday, 17 October 2013 at 13:53:39 UTC, Colin Grogan wrote:
> Anyone have any experience with this?

I actually have been writing a terminal emulator for the last few 
weeks
https://github.com/adamdruppe/terminal-emulator

But for reading and writing from the pty, I just used the unix 
read and write syscalls instead of wrapping it. tbh I don't think 
there's much point in wrapping it; I think std.stdio.File is hard 
to use for any byte-at-a-time tasks anyway...

If you do want to wrap it... well I think you'd have to modify 
phobos. The constructor that takes a FILE* is private. (std.stdio 
is itself just a wrapper around C's <stdio.h>)


But I wouldn't even bother, it is easiest to just use "import 
core.sys.posix.unistd;" and then read()/write() to it.

> As an aside, I'd prefer to do this in a pure D way, and not 
> have to compile against any external C libraries, does anyone 
> know if it is possible to spawn a pty in D without resorting to 
> calling external C libs?

eh you could probably open /dev/ptmx and the other /dev/pts/* to 
test and reimplement what openpty does yourself, but there really 
is no pure D way, because it is perfectly normal in D to use C 
interfaces to talk to the operating system (it IS possible to use 
D without a C lib, but even druntime assumes it is there). I've 
never seen a unix install without the terminal util lib, so it is 
basically part of the OS.


More information about the Digitalmars-d-learn mailing list