[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] lineedit: fix output formatting for tab completion
From:       Tomas Heinrich <heinrich.tomas () gmail ! com>
Date:       2010-05-23 21:34:22
Message-ID: 4BF99F5E.1080808 () gmail ! com
[Download RAW message or body]

Hi,

there are two minor bugs in lineedit's tab completion output with regard 
to unicode chars:

- unicode chars with visual width != 1 cause the columnar output to misalign
   $ touch /tmp/a<U+2329>b
   $ ls /tmp/^I^I

- chars configured as unsupported don't get substituted in the output

The attached patch should fix this.

Tomas

["0001-lineedit-fix-output-formatting-for-tab-completion-an.patch" (text/x-patch)]

>From 27a4b71520740cfde41c2f3a9d6402d591eeea7c Mon Sep 17 00:00:00 2001
From: Tomas Heinrich <heinrich.tomas@gmail.com>
Date: Sun, 23 May 2010 22:53:21 +0200
Subject: [PATCH] lineedit: fix output formatting for tab completion and substitute unsupported chars

---
 libbb/lineedit.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 18664b8..7439c8c 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -992,7 +992,12 @@ static void showfiles(void)
 
 	/* find the longest file name - use that as the column width */
 	for (row = 0; row < nrows; row++) {
-		l = unicode_strlen(matches[row]);
+		if (ENABLE_UNICODE_SUPPORT) {
+			uni_stat_t uni_stat;
+			printable_string(&uni_stat, matches[row]);
+			l = uni_stat.unicode_width;
+		} else
+			l = strlen(matches[row]);
 		if (column_width < l)
 			column_width = l;
 	}
@@ -1009,13 +1014,23 @@ static void showfiles(void)
 	for (row = 0; row < nrows; row++) {
 		int n = row;
 		int nc;
+		const char *s;
 
 		for (nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) {
-			printf("%s%-*s", matches[n],
-				(int)(column_width - unicode_strlen(matches[n])), ""
-			);
+			if (ENABLE_UNICODE_SUPPORT) {
+				uni_stat_t uni_stat;
+				s = printable_string(&uni_stat, matches[n]);
+				l = (int)(column_width - uni_stat.unicode_width);
+			} else {
+				s = matches[n];
+				l = (int)(column_width - strlen(s));
+			}
+			printf("%s%-*s", s, l, "");
 		}
-		puts(matches[n]);
+		if (ENABLE_UNICODE_SUPPORT)
+			puts(printable_string(NULL, matches[n]));
+		else
+			puts(matches[n]);
 	}
 }
 
-- 
1.7.0



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic