Make terminal ui binaries work well everywhere
Here's some screenshots of an emulator tui program that was compiled on Linux, then scp'd it to Windows, Mac, and FreeBSD. https://justine.storage.googleapis.com/blinkenlights-cmdexe.png https://justine.storage.googleapis.com/blinkenlights-imac.png https://justine.storage.googleapis.com/blinkenlights-freebsd.png https://justine.storage.googleapis.com/blinkenlights-lisp.png How is this even possible that we have a nontrivial ui binary that just works on Mac, Windows, Linux, and BSD? Surely a first ever achievement. Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in emulator for fun and profit.
This commit is contained in:
@ -38,8 +38,8 @@
|
||||
static struct CmdExe {
|
||||
bool result;
|
||||
struct OldNtConsole {
|
||||
unsigned codepage;
|
||||
unsigned mode;
|
||||
uint32_t codepage;
|
||||
uint32_t mode;
|
||||
int64_t handle;
|
||||
} oldin, oldout;
|
||||
} g_cmdexe;
|
||||
@ -82,6 +82,8 @@ static textwindows void NormalizeCmdExe(void) {
|
||||
SetConsoleCP(kNtCpUtf8);
|
||||
GetConsoleMode(handle, &g_cmdexe.oldin.mode);
|
||||
SetConsoleMode(handle, g_cmdexe.oldin.mode | kNtEnableProcessedInput |
|
||||
kNtEnableEchoInput | kNtEnableLineInput |
|
||||
kNtEnableWindowInput |
|
||||
kNtEnableVirtualTerminalInput);
|
||||
}
|
||||
if (GetFileType((handle = hstdout)) == kNtFileTypeChar ||
|
||||
@ -92,7 +94,10 @@ static textwindows void NormalizeCmdExe(void) {
|
||||
SetConsoleOutputCP(kNtCpUtf8);
|
||||
GetConsoleMode(handle, &g_cmdexe.oldout.mode);
|
||||
SetConsoleMode(handle, g_cmdexe.oldout.mode | kNtEnableProcessedOutput |
|
||||
kNtEnableVirtualTerminalProcessing);
|
||||
kNtEnableWrapAtEolOutput |
|
||||
(NtGetVersion() >= kNtVersionWindows10
|
||||
? kNtEnableVirtualTerminalProcessing
|
||||
: 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,11 +141,11 @@ textwindows int WinMain(void *hInstance, void *hPrevInstance,
|
||||
*(/*unconst*/ int *)&hostos = WINDOWS;
|
||||
cmd16 = GetCommandLine();
|
||||
env16 = GetEnvironmentStrings();
|
||||
count = getdosargv(cmd16, argblock, ARG_MAX, argarray, 512);
|
||||
count = GetDosArgv(cmd16, argblock, ARG_MAX, argarray, 512);
|
||||
for (i = 0; argarray[0][i]; ++i) {
|
||||
if (argarray[0][i] == '\\') argarray[0][i] = '/';
|
||||
}
|
||||
getdosenviron(env16, envblock, ENV_MAX, envarray, 512);
|
||||
GetDosEnviron(env16, envblock, ENV_MAX, envarray, 512);
|
||||
FreeEnvironmentStrings(env16);
|
||||
_executive(count, argarray, envarray, auxarray);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user