integrate patch from handlerug

This commit is contained in:
~d6 2023-02-04 18:48:06 -05:00
parent fd5afa4833
commit 625527799c
2 changed files with 42 additions and 3 deletions

35
term.c
View File

@ -1,18 +1,42 @@
#include <pwd.h>
#ifdef __APPLE__
#include <util.h>
#include <sys/ioctl.h>
#else
#include <pty.h> #include <pty.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
// compile with gcc term.c -lutil // compile with gcc term.c -lutil
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc < 2) { if (argc < 2) {
printf("usage: %s ROM\n", argv[0]); printf("usage: %s ROM [LOGIN]\n", argv[0]);
return 1; return 1;
} }
char *rom = argv[1]; // find term.rom char *rom = argv[1]; // find term.rom
int fdm = -1; // allocate file descriptor int login = argc > 2; // any extra arg signals login shell
// detect the user's shell
char *shell = getenv("SHELL");
if (shell == NULL) {
struct passwd *passwd = getpwuid(getuid());
if (passwd != NULL) {
shell = passwd->pw_shell;
}
}
if (shell == NULL) {
shell = "/bin/sh";
}
// find the shell's name
char *slash = strrchr(shell, '/');
char *name = slash == NULL ? shell : slash + 1;
// allocate a pty, fork, inititialize file descriptor // allocate a pty, fork, inititialize file descriptor
int fdm = -1; // allocate file descriptor
pid_t pid = forkpty(&fdm, NULL, NULL, NULL); pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
if (pid < 0) { // failure if (pid < 0) { // failure
@ -20,7 +44,12 @@ int main(int argc, char **argv) {
return 1; return 1;
} else if (pid == 0) { // child } else if (pid == 0) { // child
setenv("TERM", "ansi", 1); setenv("TERM", "ansi", 1);
execlp("bash", "bash", NULL); // exec bash // execute shell
if (login) {
execlp(name, shell, "-l", "-i", NULL);
} else {
execlp(name, shell, NULL);
}
perror("exec bash failed"); perror("exec bash failed");
} else { // parent } else { // parent
struct winsize ws = {23, 80, 8, 12}; // rows, cols, xps, ypx struct winsize ws = {23, 80, 8, 12}; // rows, cols, xps, ypx

View File

@ -377,6 +377,12 @@
DUP LIT "9 GTH ?end-arg DUP LIT "9 GTH ?end-arg
!add-to-arg !add-to-arg
@on-read-osc ( -> )
.Console/r DEI
DUP #07 ( bell ) EQU ?&end-osc
#9c ( esc-\ ) EQU ?&end-osc BRK
&end-osc ;on-read .Console/vect DEO2 BRK
@debug-arg ( n* -> ) @debug-arg ( n* -> )
&short SWP debug-arg/byte &short SWP debug-arg/byte
&byte DUP #04 SFT debug-arg/char &byte DUP #04 SFT debug-arg/char
@ -612,6 +618,7 @@
@on-read-esc ( -> ) @on-read-esc ( -> )
.Console/r DEI .Console/r DEI
DUP LIT "[ EQU ?start-csi DUP LIT "[ EQU ?start-csi
DUP LIT "] EQU ?start-osc
DUP LIT "( EQU ?start-charset DUP LIT "( EQU ?start-charset
DUP LIT ") EQU ?start-charset DUP LIT ") EQU ?start-charset
DUP LIT "7 EQU ?&skip ( save cursor ) DUP LIT "7 EQU ?&skip ( save cursor )
@ -635,6 +642,9 @@
@start-csi ( c^ -> ) @start-csi ( c^ -> )
POP reset-args ;on-read-csi .Console/vect DEO2 BRK POP reset-args ;on-read-csi .Console/vect DEO2 BRK
@start-osc ( c^ -> )
POP reset-args ;on-read-osc .Console/vect DEO2 BRK
@on-read ( -> ) @on-read ( -> )
.Console/r DEI .Console/r DEI
DUP ?&ok POP BRK DUP ?&ok POP BRK