From 4310e75f759baa275f6524e4edbc52d8454ce856 Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 25 Jul 2016 20:43:54 +0000 Subject: [PATCH] =?UTF-8?q?make=20tmux=20hack=20workable=20for=20now=20(li?= =?UTF-8?q?btermcap=20is=E2=80=A6=20ugly)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • track $TERM for the types tmux uses /^screen(-.*)?$/ • when tmux is in use (or GNU screen, really), use the, now hardcoded, clear-to-EOL string; otherwise, use the old behaviour • drop unnecessary x_e_rebuildline() carefully tested to behave no worse than R52b --- edit.c | 39 ++++++++++++++++++++++----------------- sh.h | 3 ++- var.c | 10 ++++++++-- var_spec.h | 5 +++-- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/edit.c b/edit.c index 09e06a6..902b708 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.298 2016/07/25 00:04:39 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.299 2016/07/25 20:43:51 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -39,9 +39,6 @@ __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.298 2016/07/25 00:04:39 tg Exp $"); #ifndef MKSH_CLS_STRING #define MKSH_CLS_STRING "\033[;H\033[J" #endif -#ifndef MKSH_CLRTOEOL_STRING -#define MKSH_CLRTOEOL_STRING "\033[K" -#endif /* tty driver characters we are interested in */ typedef struct { @@ -68,6 +65,10 @@ static int xx_cols; /* for Emacs mode */ static int modified; /* buffer has been "modified" */ static char *holdbufp; /* place to hold last edit buffer */ +/* 0=dumb 1=tmux (for now) */ +static bool x_term_mode; + +static void x_adjust(void); static int x_getc(void); static void x_putcf(int); static void x_modified(void); @@ -102,7 +103,6 @@ static int x_command_glob(int, char *, char ***); static int x_locate_word(const char *, int, int, int *, bool *); static int x_e_getmbc(char *); -static int x_e_rebuildline(const char *); /* +++ generic editing functions +++ */ @@ -149,7 +149,7 @@ x_getc(void) /* redraw line in Emacs mode */ xx_cols = x_cols; x_init_prompt(false); - x_e_rebuildline(null); + x_adjust(); } } #endif @@ -977,7 +977,6 @@ static char *x_mapin(const char *, Area *); static char *x_mapout(int); static void x_mapout2(int, char **); static void x_print(int, int); -static void x_adjust(void); static void x_e_ungetc(int); static int x_e_getc(void); static void x_e_putc2(int); @@ -2064,18 +2063,12 @@ x_draw_line(int c MKSH_A_UNUSED) return (KSTD); } -static int -x_e_rebuildline(const char *clrstr) -{ - shf_puts(clrstr, shl_out); - x_adjust(); - return (KSTD); -} - static int x_cls(int c MKSH_A_UNUSED) { - return (x_e_rebuildline(MKSH_CLS_STRING)); + shf_puts(MKSH_CLS_STRING, shl_out); + x_adjust(); + return (KSTD); } /* @@ -2104,7 +2097,9 @@ x_redraw(int limit) xlp_valid = false; x_zots(xbp); if (limit >= xx_cols || xbp != xbuf || xep > xlp) - shf_puts(MKSH_CLRTOEOL_STRING, shl_out); + limit = xx_cols; + if (limit == xx_cols && x_term_mode == 1) + shf_puts("\033[K", shl_out); else if (limit >= 0) { if (xep > xlp) /* we fill the line */ @@ -5547,4 +5542,14 @@ x_done(void) afreeall(AEDIT); } #endif + +void +x_initterm(const char *termtype) +{ + /* default must be 0 (bss) */ + x_term_mode = 0; + /* this is what tmux uses, don't ask me about it */ + if (!strcmp(termtype, "screen") || !strncmp(termtype, "screen-", 7)) + x_term_mode = 1; +} #endif /* !MKSH_NO_CMDLINE_EDITING */ diff --git a/sh.h b/sh.h index 4b696f2..67c2085 100644 --- a/sh.h +++ b/sh.h @@ -175,7 +175,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.777 2016/07/25 00:04:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.778 2016/07/25 20:43:53 tg Exp $"); #endif #define MKSH_VERSION "R52 2016/07/24" @@ -1994,6 +1994,7 @@ void x_done(void); int x_read(char *); #endif void x_mkraw(int, mksh_ttyst *, bool); +void x_initterm(const char *); /* eval.c */ char *substitute(const char *, int); char **eval(const char **, int); diff --git a/var.c b/var.c index 673c61c..ca97a0d 100644 --- a/var.c +++ b/var.c @@ -28,7 +28,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.204 2016/07/25 00:04:48 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.205 2016/07/25 20:43:54 tg Exp $"); /*- * Variables @@ -133,7 +133,7 @@ initvar(void) struct tbl *tp; ktinit(APERM, &specials, - /* currently 14 specials: 75% of 32 = 2^5 */ + /* currently 15 specials: 75% of 32 = 2^5 */ 5); while (i < V_MAX - 1) { tp = ktenter(&specials, initvar_names[i], @@ -1290,6 +1290,9 @@ setspec(struct tbl *vp) /* clear tracked aliases */ flushcom(true); return; + case V_TERM: + x_initterm(str_val(vp)); + return; case V_TMPDIR: afree(tmpdir, APERM); tmpdir = NULL; @@ -1406,6 +1409,9 @@ unsetspec(struct tbl *vp) /* clear tracked aliases */ flushcom(true); break; + case V_TERM: + x_initterm(null); + return; case V_TMPDIR: /* should not become unspecial */ if (tmpdir) { diff --git a/var_spec.h b/var_spec.h index 7d09584..d6c84f9 100644 --- a/var_spec.h +++ b/var_spec.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009, 2011, 2012 + * Copyright (c) 2009, 2011, 2012, 2016 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -19,7 +19,7 @@ */ #if defined(VARSPEC_DEFNS) -__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.7 2015/12/12 21:08:44 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.8 2016/07/25 20:43:54 tg Exp $"); #define FN(name) /* nothing */ #elif defined(VARSPEC_ENUMS) #define FN(name) V_##name, @@ -53,6 +53,7 @@ FN(OPTIND) FN(PATH) FN(RANDOM) FN(SECONDS) +FN(TERM) FN(TMOUT) FN(TMPDIR)