From bc75dcc4ce682562390fa32e7cd63c08160e21b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Sun, 17 Apr 2022 13:20:54 +0200 Subject: [PATCH] vendor/bc: import version 5.2.4 This update fixes an issue in input line editing: when going left to the start of the line, the cursor would jump to the end of the line instead. --- NEWS.md | 10 ++++++++++ include/version.h | 2 +- src/data.c | 2 +- src/history.c | 36 +++++++++++++++++++++++++++++++++--- tests/script.sh | 15 +++++++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0f28d552df18..3a388b0dc316 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,15 @@ # News +## 5.2.4 + +This is a production release that fixes two bugs in history: + +* Without prompt, the cursor could not be placed on the first character in a + line. +* Home and End key handling in `tmux` was fixed. + +Any users that do not care about these improvements do not need to upgrade. + ## 5.2.3 This is a production release that fixes one bug, a parse error when passing a diff --git a/include/version.h b/include/version.h index a7d1640a87a2..4621b50bcbeb 100644 --- a/include/version.h +++ b/include/version.h @@ -37,6 +37,6 @@ #define BC_VERSION_H /// The current version. -#define VERSION 5.2.3 +#define VERSION 5.2.4 #endif // BC_VERSION_H diff --git a/src/data.c b/src/data.c index 959af600c1af..4dc77e7e746c 100644 --- a/src/data.c +++ b/src/data.c @@ -68,7 +68,7 @@ const uchar dc_sig_msg_len = (uchar) (sizeof(dc_sig_msg) - 1); /// The copyright banner. const char bc_copyright[] = - "Copyright (c) 2018-2021 Gavin D. Howard and contributors\n" + "Copyright (c) 2018-2022 Gavin D. Howard and contributors\n" "Report bugs at: https://git.yzena.com/gavin/bc\n\n" "This is free software with ABSOLUTELY NO WARRANTY.\n"; diff --git a/src/history.c b/src/history.c index 9f158413efc2..7e2661486a8b 100644 --- a/src/history.c +++ b/src/history.c @@ -781,11 +781,14 @@ static void bc_history_refresh(BcHistory *h) { if (pos >= h->buf.len - extras_len) bc_vec_grow(&h->buf, pos + extras_len); - // Move cursor to original position. + // Move cursor to original position. Do NOT move the putchar of '\r' to the + // printf with colpos. That causes a bug where the cursor will go to the end + // of the line when there is no prompt. + bc_file_putchar(&vm.fout, bc_flush_none, '\r'); colpos = bc_history_colPos(h->buf.v, len - extras_len, pos) + h->pcol; // Set the cursor position again. - if (colpos) bc_file_printf(&vm.fout, "\r\x1b[%zuC", colpos); + if (colpos) bc_file_printf(&vm.fout, "\x1b[%zuC", colpos); bc_file_flush(&vm.fout, bc_flush_none); } @@ -1193,7 +1196,34 @@ static void bc_history_escape(BcHistory *h) { if (BC_ERR(BC_HIST_READ(seq + 2, 1))) bc_vm_fatalError(BC_ERR_FATAL_IO_ERR); - if (seq[2] == '~' && c == '3') bc_history_edit_delete(h); + if (seq[2] == '~') { + + switch(c) { + + case '1': + { + bc_history_edit_home(h); + break; + } + + case '3': + { + bc_history_edit_delete(h); + break; + } + + case '4': + { + bc_history_edit_end(h); + break; + } + + default: + { + break; + } + } + } else if(seq[2] == ';') { // Read two characters into seq. diff --git a/tests/script.sh b/tests/script.sh index 162437af8f22..5942e13159fe 100755 --- a/tests/script.sh +++ b/tests/script.sh @@ -154,6 +154,21 @@ elif [ "$generate" -eq 0 ]; then printf 'Skipping %s script %s\n' "$d" "$f" exit 0 else + + set +e + + # This is to check that the command exists. If not, we should not try to + # generate the test. Instead, we should just skip. + command -v "$d" + err="$?" + + set -e + + if [ "$err" -ne 0 ]; then + printf 'Could not find %s to generate results; skipping %s script %s\n' "$d" "$d" "$f" + exit 0 + fi + # This sed, and the script, are to remove an incompatibility with GNU bc, # where GNU bc is wrong. See the development manual # (manuals/development.md#script-tests) for more information.