From patchwork Sun Dec 18 21:34:01 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: 132127 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 8F081B700C for ; Mon, 19 Dec 2011 09:08:48 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 67D7B28312; Sun, 18 Dec 2011 23:08:20 +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 V3CWcrbE2gkY; Sun, 18 Dec 2011 23:08:20 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9A4FE28313; Sun, 18 Dec 2011 23:07:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9D8F8281E3 for ; Sun, 18 Dec 2011 22:35:04 +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 6cjsTksSqyKS for ; Sun, 18 Dec 2011 22:34:58 +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 D4DA4281D1 for ; Sun, 18 Dec 2011 22:34:51 +0100 (CET) Received: by mail-ee0-f44.google.com with SMTP id c14so3969612eek.3 for ; Sun, 18 Dec 2011 13:34:51 -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=z0iDBlxzTy7+J7XYWX3sPQFH/txNvPIQo3RegMBCVF8=; b=PCcG9WCFS+nm0JDJShjtppmhXE5aet6GDSCNbh1UoReZ/eprnmC8ntblGQdYf+Bnuc nGlL5Fw5cF1TyuM3NGQCD0ayNROJIkYDuKvP+xJBsDJfEfb0KFxsUSYOruSa3yxODEYx QsTccdgGQaslUjp7tXFZxBGNLYNvYYClnT9lQ= Received: by 10.14.32.20 with SMTP id n20mr3055316eea.42.1324244091637; Sun, 18 Dec 2011 13:34:51 -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 t1sm35684688eeb.3.2011.12.18.13.34.50 (version=SSLv3 cipher=OTHER); Sun, 18 Dec 2011 13:34:50 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: u-boot@lists.denx.de Date: Sun, 18 Dec 2011 22:34:01 +0100 Message-Id: <1324244051-25756-5-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1324244051-25756-1-git-send-email-pali.rohar@gmail.com> References: <1778406.ezGto4lKnu@pali-elitebook> <1324244051-25756-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 18 Dec 2011 23:07:27 +0100 Cc: Sebastian Reichel , Marcel Mol , Martin Jansa Subject: [U-Boot] [PATCH 05/15] 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 codes for moving cursor, which are generated by keyboard Signed-off-by: Pali Rohár --- common/main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/common/main.c b/common/main.c index e96c95a..e7b5516 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,57 @@ 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 */