From patchwork Mon Aug 29 23:56:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng Renquan X-Patchwork-Id: 1111342 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7TNvvjQ026498 for ; Mon, 29 Aug 2011 23:58:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755194Ab1H2X6D (ORCPT ); Mon, 29 Aug 2011 19:58:03 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:40909 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755086Ab1H2X6C (ORCPT ); Mon, 29 Aug 2011 19:58:02 -0400 Received: by iabu26 with SMTP id u26so970714iab.19 for ; Mon, 29 Aug 2011 16:58:01 -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=afUQUw4yLP+N+OlHJ9txOKkbs2KdAz+wYwf3C+AeTwk=; b=ZSkBKum6WwnP1Fw+V6noQKiUEHXDxklnBVaVEuyXmlBSPu/tLDkXyc4/Jl6Nk4Acjq UkRRQX+nHezrYvdE09mrEKVCB5uBuWebUUmyYjFIaDTTWizSv/5X5c25cCXSJmKYzV8K BN2R3sTAPfPX4SPu/ur3RT9XWATME0Tmm/a5Q= Received: by 10.42.75.194 with SMTP id b2mr5740214ick.62.1314662281449; Mon, 29 Aug 2011 16:58:01 -0700 (PDT) Received: from localhost.localdomain ([128.107.105.172]) by mx.google.com with ESMTPS id u1sm5993373icj.4.2011.08.29.16.57.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Aug 2011 16:57:59 -0700 (PDT) From: Cheng Renquan To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Nir Tzachar , Randy Dunlap , c.rq541@comcast.net Subject: [PATCH 4/5] scripts/kconfig/nconf: fix editing long strings Date: Mon, 29 Aug 2011 16:56:03 -0700 Message-Id: <1314662164-8565-4-git-send-email-crquan@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1314662164-8565-3-git-send-email-crquan@gmail.com> References: <1314662164-8565-1-git-send-email-crquan@gmail.com> <1314662164-8565-2-git-send-email-crquan@gmail.com> <1314662164-8565-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 (demeter1.kernel.org [140.211.167.41]); Mon, 29 Aug 2011 23:58:03 +0000 (UTC) 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]; keep the original cursor_position as cursor of the string result, for short strings, cursor_form_win is identical to cursor_position; for long strings, use (cursor_position-cursor_form_win) as begin offset to show part of the string in form_win; 2) whenever cursor of form_win is near (by 3 chars) to left or right edge of form_win, make a auto scroll by half prompt_width, to make this one line string editor more fun to use; 3) update len for later cursor_form_win correct calculation; Signed-off-by: Cheng Renquan --- scripts/kconfig/nconf.gui.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 files changed, 37 insertions(+), 6 deletions(-) diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index bc482ad..62a41d1 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; if (strlen(init) > *result_len) { do { @@ -413,7 +414,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); @@ -439,6 +442,8 @@ int dialog_inputbox(WINDOW *main_window, &result[cursor_position], len-cursor_position+1); cursor_position--; + cursor_form_win--; + len--; } break; case KEY_DC: @@ -446,18 +451,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))) { @@ -475,16 +484,38 @@ 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 (len <= prompt_width-1) + cursor_form_win = cursor_position; + else { + if (cursor_form_win <= 3) + cursor_form_win += prompt_width/2; + else if (cursor_form_win >= prompt_width-3) + cursor_form_win -= prompt_width/2; + + if (cursor_form_win < 0) + cursor_form_win = 0; + else if (cursor_form_win >= prompt_width-1) + cursor_form_win = prompt_width-1; + + if (cursor_form_win > cursor_position) + cursor_form_win = cursor_position; + if (cursor_form_win < (prompt_width-1) - (len-cursor_position)) + cursor_form_win = (prompt_width-1) - (len-cursor_position); + } + 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);