MyHLは、haribote HL-8cを改造したバージョンです。
SIGCONTシグナルを処理してREPLをフォアグラウンドにする
@@ -21,6 +21,7 @@ #if defined(__APPLE__) || defined(__linux__) #include <unistd.h> #include <termios.h> +#include <signal.h> #endif typedef unsigned char *String; @@ -1595,6 +1596,26 @@ char *readLine(char *str, int size, FILE *stream) setCanonicalMode(); return NULL; } + +int resumeAfterSuspend = 0; + +typedef void (*SigHandler)(int); + +SigHandler trapSignal(int sig, SigHandler handler) +{ + struct sigaction act, old; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_RESTART; + return sigaction(sig, &act, &old) < 0 + ? NULL + : old.sa_handler; +} + +void contHandler(int signum) +{ + resumeAfterSuspend = 1; +} #else #define readLine fgets #endif @@ -1610,12 +1631,22 @@ int main(int argc, const char **argv) exit(0); } +#if defined(__APPLE__) || defined(__linux__) + trapSignal(SIGCONT, contHandler); +#endif + int status = 0; initTerm(); for (int next = 1, nLines = 0;;) { if (next) printf("[%d]> ", ++nLines); if (readLine(text, LINE_SIZE, stdin) == NULL) { +#if defined(__APPLE__) || defined(__linux__) + if (resumeAfterSuspend) { + resumeAfterSuspend = 0; + continue; + } +#endif printf("\n"); goto exit; }
hariboteのREPLからターミナルのシェルに戻り、lsを打った後にfgコマンドで再開しようとしたらできなかったので直しました。