mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
Improve linenoise and get it working on Windows
Some progress has been made on introducing completion but there's been difficulties using the Python C API to get local shell variables.
This commit is contained in:
parent
968474d291
commit
5029e20bef
23 changed files with 408 additions and 209 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "libc/bits/bits.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/log.h"
|
||||
|
||||
/**
|
||||
|
@ -29,6 +30,7 @@
|
|||
relegated wontreturn void __die(void) {
|
||||
static bool once;
|
||||
if (cmpxchg(&once, false, true)) {
|
||||
__restore_tty();
|
||||
if (IsDebuggerPresent(false)) DebugBreak();
|
||||
ShowBacktrace(2, NULL);
|
||||
}
|
||||
|
|
|
@ -2,16 +2,19 @@
|
|||
#define COSMOPOLITAN_LIBC_LOG_INTERNAL_H_
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/termios.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern int kCrashSigs[8] hidden;
|
||||
extern struct termios g_oldtermios hidden;
|
||||
extern struct sigaction g_oldcrashacts[8] hidden;
|
||||
|
||||
void __start_fatal(const char *, int) hidden;
|
||||
void __start_fatal_ndebug(void) hidden;
|
||||
void __oncrash(int, struct siginfo *, struct ucontext *) relegated;
|
||||
void __restore_tty(void);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
45
libc/log/oldtermios.c
Normal file
45
libc/log/oldtermios.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#define SHOW_CURSOR "\e[?25h"
|
||||
#define DISABLE_MOUSE "\e[?1000;1002;1015;1006l"
|
||||
#define ANSI_RESTORE SHOW_CURSOR DISABLE_MOUSE
|
||||
|
||||
struct termios g_oldtermios;
|
||||
|
||||
static textstartup void g_oldtermios_init() {
|
||||
if (isatty(1)) {
|
||||
tcgetattr(1, &g_oldtermios);
|
||||
}
|
||||
}
|
||||
|
||||
const void *const g_oldtermios_ctor[] initarray = {
|
||||
g_oldtermios_init,
|
||||
};
|
||||
|
||||
void __restore_tty(void) {
|
||||
if (isatty(1)) {
|
||||
write(1, ANSI_RESTORE, strlen(ANSI_RESTORE));
|
||||
tcsetattr(1, TCSAFLUSH, &g_oldtermios);
|
||||
}
|
||||
}
|
|
@ -20,7 +20,9 @@
|
|||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/termios.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -41,6 +43,7 @@
|
|||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Abnormal termination handling & GUI debugging.
|
||||
|
@ -262,6 +265,7 @@ relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
|
|||
: 0);
|
||||
}
|
||||
if (gdbpid > 0 && (sig == SIGTRAP || sig == SIGQUIT)) return;
|
||||
__restore_tty();
|
||||
ShowCrashReport(err, STDERR_FILENO, sig, si, ctx);
|
||||
exit(128 + sig);
|
||||
unreachable;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/typedef/sigaction_f.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/check.h"
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
relegated void __start_fatal(const char *file, int line) {
|
||||
bool colorful;
|
||||
char s[16 + 16 + 16 + 16 + PATH_MAX + 16 + NAME_MAX + 16], *p = s;
|
||||
__restore_tty();
|
||||
colorful = cancolor();
|
||||
*p++ = '\r';
|
||||
if (colorful) p = stpcpy(p, "\e[J\e[30;101m");
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
*/
|
||||
relegated void __start_fatal_ndebug(void) {
|
||||
char s[16 + 16 + 16 + 16 + PATH_MAX + 16], *p = s;
|
||||
__restore_tty();
|
||||
*p++ = '\r';
|
||||
if (cancolor()) p = stpcpy(p, "\e[J");
|
||||
p = stpcpy(p, "error:");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue