From 8370c0dd4dce4ac2357ad9e570683d956271e6ac Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 12 Jul 2016 23:07:10 +0000 Subject: [PATCH] experimentally use MKSH_CLRTOEOL_STRING instead of lots of spaces followed by lots of backspaces for many clearing scenarios; requested by tmux user slagtc on IRC --- check.t | 6 +++--- edit.c | 27 +++++++++++++-------------- sh.h | 19 +++++-------------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/check.t b/check.t index fd16cf7..179b5cd 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.739 2016/06/26 00:44:55 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.740 2016/07/12 23:07:06 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R52 2016/06/25 + @(#)MIRBSD KSH R52 2016/07/12 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R52 2016/06/25 + @(#)LEGACY KSH R52 2016/07/12 description: Check version of legacy shell. stdin: diff --git a/edit.c b/edit.c index 79d9d20..81cde11 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.296 2016/05/05 22:56:12 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.297 2016/07/12 23:07:09 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -149,7 +149,7 @@ x_getc(void) /* redraw line in Emacs mode */ xx_cols = x_cols; x_init_prompt(false); - x_e_rebuildline(MKSH_CLRTOEOL_STRING); + x_e_rebuildline(null); } } #endif @@ -1183,6 +1183,12 @@ x_e_getmbc(char *sbuf) return (pos); } +/* + * minimum required space to work with on a line - if the prompt + * leaves less space than this on a line, the prompt is truncated + */ +#define MIN_EDIT_SPACE 7 + static void x_init_prompt(bool doprint) { @@ -1826,7 +1832,6 @@ x_goto_hist(int c MKSH_A_UNUSED) static void x_load_hist(char **hp) { - int oldsize; char *sp = NULL; if (hp == histptr + 1) { @@ -1839,17 +1844,12 @@ x_load_hist(char **hp) if (sp == NULL) sp = *hp; x_histp = hp; - oldsize = x_size_str(xbuf); if (modified) strlcpy(holdbufp, xbuf, LINE); strlcpy(xbuf, sp, xend - xbuf); xbp = xbuf; xep = xcp = xbuf + strlen(xbuf); - xlp_valid = false; - if (xep <= x_lastcp()) { - x_redraw(oldsize); - } - x_goto(xep); + x_adjust(); modified = 0; } @@ -2103,9 +2103,9 @@ x_redraw(int limit) x_displen = xx_cols - 2 - x_col; xlp_valid = false; x_zots(xbp); - if (xbp != xbuf || xep > xlp) - limit = xx_cols; - if (limit >= 0) { + if (limit >= xx_cols || xbp != xbuf || xep > xlp) + shf_puts(MKSH_CLRTOEOL_STRING, shl_out); + else if (limit >= 0) { if (xep > xlp) /* we fill the line */ i = 0; @@ -3015,7 +3015,6 @@ x_set_arg(int c) static int x_comment(int c MKSH_A_UNUSED) { - int oldsize = x_size_str(xbuf); ssize_t len = xep - xbuf; int ret = x_do_comment(xbuf, xend - xbuf, &len); @@ -3026,7 +3025,7 @@ x_comment(int c MKSH_A_UNUSED) xep = xbuf + len; *xep = '\0'; xcp = xbp = xbuf; - x_redraw(oldsize); + x_redraw(xx_cols); if (ret > 0) return (x_newline('\n')); } diff --git a/sh.h b/sh.h index 370961a..7f8be17 100644 --- a/sh.h +++ b/sh.h @@ -175,9 +175,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.774 2016/06/26 00:44:59 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.775 2016/07/12 23:07:10 tg Exp $"); #endif -#define MKSH_VERSION "R52 2016/06/25" +#define MKSH_VERSION "R52 2016/07/12" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -1087,18 +1087,9 @@ EXTERN char *current_wd; #else #define LINE (16384 - ALLOC_OVERHEAD) #endif -/* - * Minimum required space to work with on a line - if the prompt leaves - * less space than this on a line, the prompt is truncated. - */ -#define MIN_EDIT_SPACE 7 -/* - * Minimum allowed value for x_cols: 2 for prompt, 3 for " < " at end of line - */ -#define MIN_COLS (2 + MIN_EDIT_SPACE + 3) -#define MIN_LINS 3 -EXTERN mksh_ari_t x_cols E_INIT(80); /* tty columns */ -EXTERN mksh_ari_t x_lins E_INIT(24); /* tty lines */ +/* columns and lines of the tty */ +EXTERN mksh_ari_t x_cols E_INIT(80); +EXTERN mksh_ari_t x_lins E_INIT(24); /* Determine the location of the system (common) profile */