From patchwork Thu Jan 22 04:11:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1771 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769055184; bh=F8eGPQYfzOQq91/3mVXzwrQjjOeiy17xYIH7FfSqdNM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=UD4FI/+fWfGwu6av2UdFLNeeYgbn6EORuOgEh8mo87sxTYm9znQBFBNBKJlvzK4Pl G/Pd0vrWlCB2ZgcHL/2LSJtqZWiKHUABYjL+dyUucqdCB+1bjAw4GO8VeRL0Y1nuiL ALhuUpBBiafEKVPUT639Ou+JOLp3qWFGnrfeREfY/PbNoJKS2Fxv8vBHn3BlzacOGm 3XklN/O0+vQDxjECEsPejPX1iqj69kg9GpK+meDU4OUYtEVsGIJhyJzFDv8c4NYrlo 1wGCCDU9dhERN4o3s+4D7dsgd3eREK6cbxAaeFKnIPwNy86oUJJJyeIhTsf04uRFxg YLtmhY3nm2Cww== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 780F96962D for ; Wed, 21 Jan 2026 21:13:04 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 7JjPOfgsiynO for ; Wed, 21 Jan 2026 21:13:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769055184; bh=F8eGPQYfzOQq91/3mVXzwrQjjOeiy17xYIH7FfSqdNM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=UD4FI/+fWfGwu6av2UdFLNeeYgbn6EORuOgEh8mo87sxTYm9znQBFBNBKJlvzK4Pl G/Pd0vrWlCB2ZgcHL/2LSJtqZWiKHUABYjL+dyUucqdCB+1bjAw4GO8VeRL0Y1nuiL ALhuUpBBiafEKVPUT639Ou+JOLp3qWFGnrfeREfY/PbNoJKS2Fxv8vBHn3BlzacOGm 3XklN/O0+vQDxjECEsPejPX1iqj69kg9GpK+meDU4OUYtEVsGIJhyJzFDv8c4NYrlo 1wGCCDU9dhERN4o3s+4D7dsgd3eREK6cbxAaeFKnIPwNy86oUJJJyeIhTsf04uRFxg YLtmhY3nm2Cww== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6728A6962A for ; Wed, 21 Jan 2026 21:13:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769055181; bh=lUPY1xNC75WYzlDRD1UDoXSrGOpfX1LHw0ifRWwFXTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WPc86nLGd3SiS1Z5uAQ/pBMBDClhMGyqIUE5z1Fw94xNfwjFc48Mrn4t26cmNM+7x df6ZebIPOOLy4L3sFUy5LTNsSPkk8ddf1snsbf4DbBj9WUUOyFcqEwUmDi1sjGutiA SS4K1TPaSSuf0OZr0AJGNTnKhrRPJWJKjA6RmWtucbAqSu7OdBCVIPMMTwGScTQjxY iOZIBEJmyoqX7uA9M6tpVVAFkCdGnCiNDwQ2rzwT7dgc1aoa/PCmvHWkgOP+0OU/L8 gPQUgM+GxQkCE2dfJtPY3JvjepcKXNm/Hdxvk5QnGAM1woLAM6pnl/jJZIEFcmxEId 0y+skvlTozrSQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C1E2B694CC; Wed, 21 Jan 2026 21:13:01 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id H4er0IEXq9cN; Wed, 21 Jan 2026 21:13:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769055177; bh=ng7QAkB68g2tawt0FdlhzhwptzvSATv7qMP3Z6DuNF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fsfvuhMlYIFAHTOLyzzD+KGKQET8a7Zfy0+keof98gF8+WvgiyZO4WKPTZbackDD5 EqFNqGSd8y8L/A4X7tyW0Oa5JxNa6kVsqIPtdURDOeuIT8vo+sODhXHQRnQO11hxF3 FnYfO+ZL5ulyh6S0cWE257LVPgh8bd8H024N2TzLfTT6HAeVUVNbwNCv8jtWNGjpUr ybtgdgTDdPeXZUAyn7WVRnPa1dsG4SqtfiSa3rF+Lj6TteXSSaiUI5yzsDyTEq4wCn z7z35iFc6lK8EsrWhItSoGar1DSOttICkOA+eoe8DmWpmtf3BSJO7nTiVivvKXlAbb EfoJB2yWp/vvQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7451669616; Wed, 21 Jan 2026 21:12:57 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 21 Jan 2026 21:11:40 -0700 Message-ID: <20260122041155.174721-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260122041155.174721-1-sjg@u-boot.org> References: <20260122041155.174721-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 4NFW2AIXCJ6XT47WH3XXGZ3KDQU25MXV X-Message-ID-Hash: 4NFW2AIXCJ6XT47WH3XXGZ3KDQU25MXV X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/16] cli: Add multiline support to CLI line editing List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add support for multi-line input in CLI line editing: - Add multiline bool to indicate input may contain multiple lines - Add line_nav callback for Ctrl-P/N navigation between visual lines When multiline is true, Ctrl-P/N call the line_nav callback instead of accessing command history. The callback returns the new cursor position or a negative value if at the boundary. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- common/cli_readline.c | 17 +++++++++++++++++ include/cli.h | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/common/cli_readline.c b/common/cli_readline.c index 27fecd835a0..38f825184df 100644 --- a/common/cli_readline.c +++ b/common/cli_readline.c @@ -405,6 +405,23 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar) break; case CTL_CH('p'): case CTL_CH('n'): + if (cls->multiline && cls->line_nav) { + int new_num; + + new_num = cls->line_nav(cls, ichar == CTL_CH('p')); + if (new_num < 0) { + getcmd_cbeep(cls); + break; + } + + /* + * Just update the position - the callback handles + * cursor display since backspaces don't work across + * wrapped line boundaries + */ + cls->num = new_num; + break; + } if (cls->history) { char *hline; diff --git a/include/cli.h b/include/cli.h index a02e228bf8a..f1e5887fa56 100644 --- a/include/cli.h +++ b/include/cli.h @@ -34,10 +34,15 @@ struct cli_ch_state { * @history: true if history should be accessible * @cmd_complete: true if tab completion should be enabled (requires @prompt to * be set) + * @multiline: true if input may contain multiple lines (enables Ctrl-P/N for + * line navigation instead of history) * @buf: Buffer containing line * @prompt: Prompt for the line * @putch: Function to call to output a character (NULL to use putc()) - * @priv: Private data for putch callback + * @line_nav: Function to call for multi-line navigation (Ctrl-P/N). Called with + * @up true for previous line, false for next. Returns new cursor position, + * or -ve if at boundary + * @priv: Private data for callbacks */ struct cli_line_state { uint num; @@ -46,9 +51,11 @@ struct cli_line_state { bool insert; bool history; bool cmd_complete; + bool multiline; char *buf; const char *prompt; void (*putch)(struct cli_line_state *cls, int ch); + int (*line_nav)(struct cli_line_state *cls, bool up); void *priv; };