diff --git a/term.c b/term.c index fddbeb5..ec4b2aa 100644 --- a/term.c +++ b/term.c @@ -1,18 +1,42 @@ +#include +#ifdef __APPLE__ +#include +#include +#else #include +#endif #include #include +#include #include // compile with gcc term.c -lutil int main(int argc, char **argv) { if (argc < 2) { - printf("usage: %s ROM\n", argv[0]); + printf("usage: %s ROM [LOGIN]\n", argv[0]); return 1; } 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 + int fdm = -1; // allocate file descriptor pid_t pid = forkpty(&fdm, NULL, NULL, NULL); if (pid < 0) { // failure @@ -20,7 +44,12 @@ int main(int argc, char **argv) { return 1; } else if (pid == 0) { // child 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"); } else { // parent struct winsize ws = {23, 80, 8, 12}; // rows, cols, xps, ypx diff --git a/term.tal b/term.tal index fb35b4d..0187aa8 100644 --- a/term.tal +++ b/term.tal @@ -377,6 +377,12 @@ DUP LIT "9 GTH ?end-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* -> ) &short SWP debug-arg/byte &byte DUP #04 SFT debug-arg/char @@ -612,6 +618,7 @@ @on-read-esc ( -> ) .Console/r DEI DUP LIT "[ EQU ?start-csi + DUP LIT "] EQU ?start-osc DUP LIT "( EQU ?start-charset DUP LIT ") EQU ?start-charset DUP LIT "7 EQU ?&skip ( save cursor ) @@ -635,6 +642,9 @@ @start-csi ( c^ -> ) 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 ( -> ) .Console/r DEI DUP ?&ok POP BRK