Last active
November 5, 2015 19:03
-
-
Save creationix/a360ac322855931461b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = require('ffi') | |
local uv = require('uv') | |
local wrapStream = require('coro-channel').wrapStream | |
local wrapRead = require('coro-channel').wrapRead | |
local split = require('coro-split') | |
ffi.cdef[[ | |
struct winsize { | |
unsigned short ws_row; | |
unsigned short ws_col; | |
unsigned short ws_xpixel; /* unused */ | |
unsigned short ws_ypixel; /* unused */ | |
}; | |
int openpty(int *amaster, int *aslave, char *name, | |
void *termp, | |
const struct winsize *winp); | |
]] | |
local master = ffi.new("int[1]") | |
local slave = ffi.new("int[1]") | |
local name = ffi.new("char[1024]") | |
local winp = ffi.new("struct winsize") | |
winp.ws_row = 24 | |
winp.ws_col = 80 | |
-- Create the pty | |
ffi.C.openpty(master, slave, name, nil, winp) | |
-- Convert to lua values, freeing the ffi values. | |
master, slave, name = master[0], slave[0], ffi.string(name) | |
p { | |
master = master, | |
slave = slave, | |
name = name | |
} | |
uv.spawn("/bin/stty", { | |
args = {"-a"}, | |
stdio = {slave, slave, slave} | |
}, function (...) | |
p("onexit", ...) | |
end) | |
local pipe = uv.new_pipe(false) | |
pipe:open(master) | |
pipe:read_start(function (err, data) | |
assert(not err, err) | |
print(data) | |
end) | |
uv.run() | |
uv.tty_reset_mode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Output: