mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-14 06:59:10 +00:00
Fix select() on Windows for timeout (#141)
This commit is contained in:
parent
3085ac7837
commit
50937be752
6 changed files with 108 additions and 36 deletions
47
third_party/linenoise/linenoise.c
vendored
47
third_party/linenoise/linenoise.c
vendored
|
@ -59,6 +59,27 @@
|
|||
│ - Ctrl+R search │
|
||||
│ - Thompson-Pike Encoding │
|
||||
│ │
|
||||
│ SHORTCUTS │
|
||||
│ │
|
||||
│ CTRL-L CLEAR SCREEN │
|
||||
│ CTRL-N NEXT HISTORY │
|
||||
│ CTRL-P PREVIOUS HISTORY │
|
||||
│ CTRL-F FORWARD CHAR │
|
||||
│ CTRL-B BACKWARD CHAR │
|
||||
│ CTRL-A BEGINNING OF LINE │
|
||||
│ CTRL-E END OF LINE │
|
||||
│ ALT-F FORWARD WORD │
|
||||
│ ALT-B BACKWARD WORD │
|
||||
│ CTRL-H DELETE CHAR BACKWARDS │
|
||||
│ CTRL-ALT-H DELETE WORD BACKWARDS │
|
||||
│ ALT-H DELETE WORD BACKWARDS │
|
||||
│ CTRL-W DELETE WORD BACKWARDS │
|
||||
│ CTRL-D DELETE CHAR FORWARDS │
|
||||
│ ALT-D DELETE WORD FORWARDS │
|
||||
│ CTRL-T TRANSPOSE CHARS │
|
||||
│ CTRL-K DELETE LINE FORWARDS │
|
||||
│ CTRL-U DELETE LINE BACKWARDS │
|
||||
│ │
|
||||
│ REFERENCE │
|
||||
│ │
|
||||
│ The big scary coding you 𝘮𝘶𝘴𝘵 use curses to abstract. │
|
||||
|
@ -533,25 +554,14 @@ static void abFree(struct abuf *ab) {
|
|||
/* Helper of refreshSingleLine() and refreshMultiLine() to show hints
|
||||
* to the right of the prompt. */
|
||||
static void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) {
|
||||
char seq[26], *p;
|
||||
if (hintsCallback && plen+l->len < l->cols) {
|
||||
int color = 0, bold = 0;
|
||||
char *hint = hintsCallback(l->buf,&color,&bold);
|
||||
const char *ansi1 = "\e[90m";
|
||||
const char *ansi2 = "\e[39m";
|
||||
char *hint = hintsCallback(l->buf,&ansi1,&ansi2);
|
||||
if (hint) {
|
||||
int hintlen = strlen(hint);
|
||||
int hintmaxlen = l->cols-(plen+l->len);
|
||||
if (hintlen > hintmaxlen) hintlen = hintmaxlen;
|
||||
if (bold && !color) color = 37;
|
||||
if (color || bold) {
|
||||
p=stpcpy(seq,"\e[");
|
||||
p+=int64toarray_radix10(bold&255,p),*p++=';';
|
||||
p+=int64toarray_radix10(color&255,p);
|
||||
p=stpcpy(p,";49m");
|
||||
abAppend(ab,seq,p-seq);
|
||||
}
|
||||
abAppend(ab,hint,hintlen);
|
||||
if (color != -1 || bold)
|
||||
abAppend(ab,"\e[0m",4);
|
||||
if (ansi1) abAppend(ab,ansi1,strlen(ansi1));
|
||||
abAppend(ab,hint,MIN(l->cols-(plen+l->len),strlen(hint)));
|
||||
if (ansi2) abAppend(ab,ansi2,strlen(ansi2));
|
||||
/* Call the function to free the hint returned. */
|
||||
if (freeHintsCallback) {
|
||||
freeHintsCallback(hint);
|
||||
|
@ -1061,6 +1071,9 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen,
|
|||
case 'd': /* "\ed" is alt-d */
|
||||
linenoiseEditDeleteNextWord(&l);
|
||||
break;
|
||||
case 'h': /* "\e" is alt-h */
|
||||
linenoiseEditDeletePrevWord(&l);
|
||||
break;
|
||||
case CTRL('H'): /* "\e\b" is ctrl-alt-h */
|
||||
linenoiseEditDeletePrevWord(&l);
|
||||
break;
|
||||
|
|
3
third_party/linenoise/linenoise.h
vendored
3
third_party/linenoise/linenoise.h
vendored
|
@ -9,7 +9,8 @@ typedef struct linenoiseCompletions {
|
|||
} linenoiseCompletions;
|
||||
|
||||
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
||||
typedef char *(linenoiseHintsCallback)(const char *, int *, int *);
|
||||
typedef char *(linenoiseHintsCallback)(const char *, const char **,
|
||||
const char **);
|
||||
typedef void(linenoiseFreeHintsCallback)(void *);
|
||||
|
||||
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
|
||||
|
|
3
third_party/python/Programs/python.c
vendored
3
third_party/python/Programs/python.c
vendored
|
@ -778,14 +778,13 @@ TerminalCompletion(const char *p, linenoiseCompletions *c)
|
|||
}
|
||||
|
||||
static char *
|
||||
TerminalHint(const char *p, int *color, int *bold)
|
||||
TerminalHint(const char *p, const char **ansi1, const char **ansi2)
|
||||
{
|
||||
char *h = 0;
|
||||
linenoiseCompletions c = {0};
|
||||
TerminalCompletion(p, &c);
|
||||
if (c.len == 1) {
|
||||
h = strdup(c.cvec[0] + strlen(p));
|
||||
*bold = 2;
|
||||
}
|
||||
linenoiseFreeCompletions(&c);
|
||||
return h;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue