From bf11df40e24aa832057d7e89254a110fe526f7f7 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sun, 13 Feb 2022 23:12:25 +0100 Subject: [PATCH] readline: give the possibility to ignore the empty line in the history (#13452) --- cmd/tools/vrepl.v | 4 +++- vlib/readline/readline.v | 1 + vlib/readline/readline_linux.c.v | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index cfa177a7a..936acb180 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -42,7 +42,9 @@ enum FnType { fn new_repl() Repl { return Repl{ - readline: readline.Readline{} + readline: readline.Readline{ + skip_empty: true + } modules: ['os', 'time', 'math'] vstartup_lines: os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines() // Test file used to check if a function as a void return or a diff --git a/vlib/readline/readline.v b/vlib/readline/readline.v index 620c6f746..f3e426753 100644 --- a/vlib/readline/readline.v +++ b/vlib/readline/readline.v @@ -28,6 +28,7 @@ mut: prompt string prompt_offset int previous_lines [][]rune + skip_empty bool // skip the empty lines when calling .history_previous() search_index int is_tty bool } diff --git a/vlib/readline/readline_linux.c.v b/vlib/readline/readline_linux.c.v index aed8fa6ca..2bd562391 100644 --- a/vlib/readline/readline_linux.c.v +++ b/vlib/readline/readline_linux.c.v @@ -551,9 +551,14 @@ fn (mut r Readline) history_previous() { r.previous_lines[0] = r.current } r.search_index++ - r.current = r.previous_lines[r.search_index] - r.cursor = r.current.len - r.refresh_line() + prev_line := r.previous_lines[r.search_index] + if r.skip_empty && prev_line == [] { + r.history_previous() + } else { + r.current = prev_line + r.cursor = r.current.len + r.refresh_line() + } } // history_next sets current line to the content of the next line in the history buffer. -- 2.30.2