From patchwork Sat Dec 17 17:03:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 132006 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 38C421007DB for ; Sun, 18 Dec 2011 04:18:12 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6CDE3282F4; Sat, 17 Dec 2011 18:17:47 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LR-v+4yYkkZ2; Sat, 17 Dec 2011 18:17:47 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 65A122829D; Sat, 17 Dec 2011 18:17:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3928C282D1 for ; Sat, 17 Dec 2011 18:04:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IpLKwmDOK+0H for ; Sat, 17 Dec 2011 18:04:30 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ee0-f44.google.com (mail-ee0-f44.google.com [74.125.83.44]) by theia.denx.de (Postfix) with ESMTPS id E7A53282D7 for ; Sat, 17 Dec 2011 18:04:29 +0100 (CET) Received: by mail-ee0-f44.google.com with SMTP id c14so2998501eek.3 for ; Sat, 17 Dec 2011 09:04:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=6MWPLgbj2jsSPFNZ2sU7VoxblmfKsWPybcAgFJeCvJM=; b=nCQP5gGqQqKHnxBhz/S9cS0r/r638dwMvrPwnPRnGnz5aCs0nnWuzd7kxcEqAV9CrP JlLXc/EYWzsP6iKKDKUAEBbCMrDaCAIZUiv/9/btnVEzEU6nHnawielBCAFnfDhYAAii OOxmDsBPwzNBU9c5f/BiZ5BaPQu2lWqIzicsY= Received: by 10.213.19.19 with SMTP id y19mr1291409eba.140.1324141469755; Sat, 17 Dec 2011 09:04:29 -0800 (PST) Received: from Pali-EliteBook.kolej.mff.cuni.cz (pali.kolej.mff.cuni.cz. [78.128.193.202]) by mx.google.com with ESMTPS id a60sm17652568eeb.4.2011.12.17.09.04.28 (version=SSLv3 cipher=OTHER); Sat, 17 Dec 2011 09:04:28 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: u-boot@lists.denx.de Date: Sat, 17 Dec 2011 18:03:07 +0100 Message-Id: <1324141398-14859-5-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1324141398-14859-1-git-send-email-pali.rohar@gmail.com> References: <2772527.Czs1Sl5aoH@pali-elitebook> <1324141398-14859-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 17 Dec 2011 18:17:05 +0100 Cc: Sebastian Reichel , Marcel Mol , Martin Jansa , =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [U-Boot] [PATCH 05/16] common/main.c: Fix function readline X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de * Ignore ANSI escape sequences for moving cursor, which are generated by keyboard Signed-off-by: Pali Rohár --- common/main.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) diff --git a/common/main.c b/common/main.c index e96c95a..5531130 100644 --- a/common/main.c +++ b/common/main.c @@ -958,6 +958,7 @@ int readline_into_buffer (const char *const prompt, char * buffer) int n = 0; /* buffer index */ int plen = 0; /* prompt length */ int col; /* output column cnt */ + int esc = 0; /* ansi escape char */ char c; /* print prompt */ @@ -1024,7 +1025,55 @@ int readline_into_buffer (const char *const prompt, char * buffer) p=delete_char(p_buf, p, &col, &n, plen); continue; + case '\e': /* ANSI escape char */ + esc = 1; + continue; + default: + + /* + * Check for ANSI escape chars + */ + if (esc == 0 && c == '\e') { + esc = 1; + continue; + } else if (esc == 1) { + if (c == '[') { + esc = 2; + continue; + } + if (n < CONFIG_SYS_CBSIZE-2) { + ++n; + *p++ = '\e'; + putc('\e'); + } + esc = 0; + } else if (esc == 2 || esc == 3) { + if (esc == 2 && c == '1') { + esc = 3; + continue; + } + /* Ignore ANSI escape sequences generated by keyboard */ + /* \e [ 1 A-D and \e [ A-D */ + if ( c >= 'A' && c <= 'D' ) { + esc = 0; + continue; + } + if (esc == 2 && n < CONFIG_SYS_CBSIZE-3) { + n += 2; + *p++ = '\e'; + *p++ = '['; + puts("\e["); + } else if (esc == 3 && n < CONFIG_SYS_CBSIZE-4) { + n += 3; + *p++ = '\e'; + *p++ = '['; + *p++ = '1'; + puts("\e[1"); + } + esc = 0; + } + /* * Must be a normal character then */