term stuff

This commit is contained in:
~d6 2023-02-04 16:02:21 -05:00
parent 3d81b6eeca
commit b0e380caaa
2 changed files with 15 additions and 11 deletions

24
term.c
View File

@ -1,7 +1,6 @@
#include <pty.h> #include <pty.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -10,20 +9,25 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
char *rom = argv[1]; char *rom = argv[1];
int fd = -1; int fdm = -1;
setenv("TERM", "ansi", 1);
pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
pid_t pid = forkpty(&fd, NULL, NULL, NULL); if (pid < 0) {
if (pid == 0) { // failure
printf("fork failed");
return 1;
} else if (pid == 0) {
// child // child
setenv("TERM", "ansi", 1); setsid();
execlp("bash", "bash"); execlp("bash", "bash");
} else { } else {
// parent // parent
char *argp = {0, 40, 0, 79, 0, 8, 0, 8}; // HHHH: height, width, 8, 8 // rows, cols, xpixels, ypixels (little endian)
ioctl(fd, TIOCSWINSZ, argp); char argp[] = {23, 0, 80, 0, 8, 0, 12, 0};
ioctl(fdm, TIOCSWINSZ, argp);
dup2(fd, STDIN); dup2(fdm, 0);
dup2(dup(fd), STDOUT); dup2(fdm, 1);
execlp("uxnemu", "uxnemu", rom); execlp("uxnemu", "uxnemu", rom);
} }
} }

View File

@ -32,7 +32,7 @@ def main():
# set the terminal size # set the terminal size
###cols, rows = 79, 40 ###cols, rows = 79, 40
cols, rows = 80, 24 cols, rows = 80, 24
size = struct.pack("HHHH", rows, cols, 8, 8) size = struct.pack("HHHH", rows, cols, 8, 12)
fcntl.ioctl(fd, termios.TIOCSWINSZ, size) fcntl.ioctl(fd, termios.TIOCSWINSZ, size)
# use fd for the terminals stdin/stdout # use fd for the terminals stdin/stdout