From patchwork Tue Jan 24 14:28:01 2012 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: 137561 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 79759B6EF2 for ; Wed, 25 Jan 2012 01:29:44 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EBB0E2815F; Tue, 24 Jan 2012 15:29:32 +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 CfNMCm1AtqOP; Tue, 24 Jan 2012 15:29:32 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C7B8628186; Tue, 24 Jan 2012 15:29:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AFD2228166 for ; Tue, 24 Jan 2012 15:28:58 +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 jjabbr+wTf19 for ; Tue, 24 Jan 2012 15:28: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-ww0-f52.google.com (mail-ww0-f52.google.com [74.125.82.52]) by theia.denx.de (Postfix) with ESMTPS id 1E9262814A for ; Tue, 24 Jan 2012 15:28:55 +0100 (CET) Received: by mail-ww0-f52.google.com with SMTP id dq12so4822869wgb.9 for ; Tue, 24 Jan 2012 06:28:55 -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=VXqP2l1dHjdb8S4YTgd6c12ch97bvYpyu8KdKzC6i5g=; b=hJz0RwvAlbIIZheCXzIxcxdoXc8At4d8IdHw07Kh4kIC8n8ADz0jf0Cx/6cIJMbmJI 2EuK3ocwR6/QKcJ1iolMpUjP5ag33HSP/ZWhDJNn6GgoMg5+rdvxIrrZpYgh5UHE055Q qDlz1PBlNlwMGZshT42qzELS8qBpB046j678E= Received: by 10.180.97.199 with SMTP id ec7mr21034434wib.8.1327415335840; Tue, 24 Jan 2012 06:28:55 -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 n3sm52913728wiz.9.2012.01.24.06.28.54 (version=SSLv3 cipher=OTHER); Tue, 24 Jan 2012 06:28:54 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: u-boot@lists.denx.de Date: Tue, 24 Jan 2012 15:28:01 +0100 Message-Id: <1327415291-13260-5-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1327415291-13260-1-git-send-email-pali.rohar@gmail.com> References: <1327415291-13260-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [U-Boot] [PATCH 04/14] Fix function readline in main.c 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 --- Changes since original version: - Fixed commit message 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 */