From patchwork Mon Dec 19 04:19:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 706930 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3thnmG1f8gz9s65 for ; Mon, 19 Dec 2016 15:21:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="MIZb32QJ"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3thnmG0gGVzDwJG for ; Mon, 19 Dec 2016 15:21:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="MIZb32QJ"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3thnkp5d3QzDwHh for ; Mon, 19 Dec 2016 15:20:02 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="MIZb32QJ"; dkim-atps=neutral Received: from skellige.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id 31782143FAE; Mon, 19 Dec 2016 12:19:59 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1482121200; bh=hcopH7yD3vE4J1b3CH2vM1GK6wmjKoQjQYtM8oagBXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MIZb32QJl6NM/NpMa50C/sro6rtutPT6PSQ+sOFiuut9fPhE+7TZx1OwkqyDUu0er 5GQYfYBoC5btkee3Ogq+8nt81KNf0qW8WI8VebNShG50z4/SXjl4abvfGe+MO9A1Ut Rwu0FjCdvdeN6WC1MCNSnJKhE2+HXFvV94IGv9WQ= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 21/29] ui/ncurses/text-screen: trim long lines Date: Mon, 19 Dec 2016 15:19:07 +1100 Message-Id: <20161219041915.30497-22-sam@mendozajonas.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161219041915.30497-1-sam@mendozajonas.com> References: <20161219041915.30497-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Jeremy Kerr When a text_screen is given a long line, it'll wrap to the next, overstepping the left margin. We already have folded text for flowed text screens, so just trim long lines at the correct column. This exposes an off-by-one with the automatic wrapping in text_screen_set_text(), where we may overrun the last char, so fix that too. Signed-off-by: Jeremy Kerr Signed-off-by: Samuel Mendoza-Jonas --- ui/ncurses/nc-textscreen.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ui/ncurses/nc-textscreen.c b/ui/ncurses/nc-textscreen.c index 55428e7..a460188 100644 --- a/ui/ncurses/nc-textscreen.c +++ b/ui/ncurses/nc-textscreen.c @@ -41,14 +41,15 @@ struct text_screen *text_screen_from_scr(struct nc_scr *scr) void text_screen_draw(struct text_screen *screen) { - int max_y, i; + int max_y, max_x, i; max_y = getmaxy(screen->scr.sub_ncw); + max_x = getmaxx(screen->scr.sub_ncw) - 1; max_y = min(max_y, screen->scroll_y + screen->n_lines); for (i = screen->scroll_y; i < max_y; i++) - mvwaddstr(screen->scr.sub_ncw, i, 1, screen->lines[i]); + mvwaddnstr(screen->scr.sub_ncw, i, 1, screen->lines[i], max_x); wrefresh(screen->scr.sub_ncw); } @@ -56,6 +57,7 @@ void text_screen_draw(struct text_screen *screen) static void text_screen_scroll(struct text_screen *screen, int key) { int win_lines = getmaxy(screen->scr.sub_ncw); + int win_cols = getmaxx(screen->scr.sub_ncw) - 1; int delta; if (key == KEY_UP) @@ -74,11 +76,12 @@ static void text_screen_scroll(struct text_screen *screen, int key) wscrl(screen->scr.sub_ncw, delta); if (delta > 0) { - mvwaddstr(screen->scr.sub_ncw, win_lines - 1, 1, - screen->lines[screen->scroll_y+win_lines-1]); + mvwaddnstr(screen->scr.sub_ncw, win_lines - 1, 1, + screen->lines[screen->scroll_y+win_lines-1], + win_cols); } else if (delta < 0) { - mvwaddstr(screen->scr.sub_ncw, 0, 1, - screen->lines[screen->scroll_y]); + mvwaddnstr(screen->scr.sub_ncw, 0, 1, + screen->lines[screen->scroll_y], win_cols); } wrefresh(screen->scr.sub_ncw); @@ -135,7 +138,7 @@ static int text_screen_fold_cb(void *arg, const char *buf, int len) void text_screen_set_text(struct text_screen *screen, const char *text) { - fold_text(text, getmaxx(screen->scr.sub_ncw), text_screen_fold_cb, + fold_text(text, getmaxx(screen->scr.sub_ncw) - 1, text_screen_fold_cb, screen); }