From patchwork Thu Sep 1 17:52:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng Renquan X-Patchwork-Id: 1120192 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p81Hs85F016137 for ; Thu, 1 Sep 2011 17:54:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757233Ab1IARxr (ORCPT ); Thu, 1 Sep 2011 13:53:47 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:49118 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757094Ab1IARxX (ORCPT ); Thu, 1 Sep 2011 13:53:23 -0400 Received: by mail-pz0-f42.google.com with SMTP id 37so3318485pzk.1 for ; Thu, 01 Sep 2011 10:53:23 -0700 (PDT) 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; bh=tNcdfEPnBRJEiXz3iSdsAQVNp+HAFlj5f/jU673Aq6Q=; b=mon8DsbBkfjDtQcXr4SaECXTomiPJBDZ9jJN+EeTdoGqcRtdN9CJWzt5kOHwkb5MUO vBHG6WpwcVLWgf1cK52BS3LhetlIPKcL/PyrXWnnta7oveMAt8PfiKPU4F+wexu+9Sy+ v7+6uxwV1WFchr56InUF1Pz4Cw+FZj0b8Z4OY= Received: by 10.68.44.3 with SMTP id a3mr482841pbm.227.1314899603131; Thu, 01 Sep 2011 10:53:23 -0700 (PDT) Received: from localhost.localdomain ([67.188.70.153]) by mx.google.com with ESMTPS id u2sm4649348pbq.9.2011.09.01.10.53.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Sep 2011 10:53:21 -0700 (PDT) From: crquan@gmail.com To: linux-kbuild@vger.kernel.org, Arnaud Lacombe Cc: Sam Ravnborg , Michal Marek , Nir Tzachar , Randy Dunlap , linux-kernel@vger.kernel.org, c.rq541@comcast.net Subject: [PATCH V3 4/5] scripts/kconfig/nconf: fix editing long strings Date: Thu, 1 Sep 2011 10:52:21 -0700 Message-Id: <1314899542-5848-4-git-send-email-crquan@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1314899542-5848-3-git-send-email-crquan@gmail.com> References: <1314899542-5848-1-git-send-email-crquan@gmail.com> <1314899542-5848-2-git-send-email-crquan@gmail.com> <1314899542-5848-3-git-send-email-crquan@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 01 Sep 2011 17:54:09 +0000 (UTC) From: Cheng Renquan The original dialog_inputbox doesn't work with longer than prompt_width strings, here fixed it in this way: 1) add variable cursor_form_win to record cursor of form_win, keep its value always between [0, prompt_width-1]; reuse the original cursor_position as cursor of the string result, use (cursor_position-cursor_form_win) as begin offset to show part of the string in form_win; Signed-off-by: Cheng Renquan Cc: Arnaud Lacombe Cc: Nir Tzachar --- scripts/kconfig/nconf.gui.c | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-) diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index d64bc1c..4b9d8b6 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -367,6 +367,7 @@ int dialog_inputbox(WINDOW *main_window, int i, x, y; int res = -1; int cursor_position = strlen(init); + int cursor_form_win; char *result = *resultp; if (strlen(init)+1 > *result_len) { @@ -410,7 +411,9 @@ int dialog_inputbox(WINDOW *main_window, fill_window(prompt_win, prompt); mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); - mvwprintw(form_win, 0, 0, "%s", result); + cursor_form_win = min(cursor_position, prompt_width-1); + mvwprintw(form_win, 0, 0, "%s", + result + cursor_position-cursor_form_win); /* create panels */ panel = new_panel(win); @@ -436,6 +439,8 @@ int dialog_inputbox(WINDOW *main_window, &result[cursor_position], len-cursor_position+1); cursor_position--; + cursor_form_win--; + len--; } break; case KEY_DC: @@ -443,18 +448,22 @@ int dialog_inputbox(WINDOW *main_window, memmove(&result[cursor_position], &result[cursor_position+1], len-cursor_position+1); + len--; } break; case KEY_UP: case KEY_RIGHT: - if (cursor_position < len && - cursor_position < min(*result_len, prompt_width)) + if (cursor_position < len) { cursor_position++; + cursor_form_win++; + } break; case KEY_DOWN: case KEY_LEFT: - if (cursor_position > 0) + if (cursor_position > 0) { cursor_position--; + cursor_form_win--; + } break; default: if ((isgraph(res) || isspace(res))) { @@ -470,16 +479,24 @@ int dialog_inputbox(WINDOW *main_window, len-cursor_position+1); result[cursor_position] = res; cursor_position++; + cursor_form_win++; + len++; } else { mvprintw(0, 0, "unknown key: %d\n", res); } break; } + if (cursor_form_win < 0) + cursor_form_win = 0; + else if (cursor_form_win > prompt_width-1) + cursor_form_win = prompt_width-1; + wmove(form_win, 0, 0); wclrtoeol(form_win); mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); - mvwprintw(form_win, 0, 0, "%s", result); - wmove(form_win, 0, cursor_position); + mvwprintw(form_win, 0, 0, "%s", + result + cursor_position-cursor_form_win); + wmove(form_win, 0, cursor_form_win); touchwin(win); refresh_all_windows(main_window);