shithub: vdir

Download patch

ref: 0bdf44080b3cbd88ad1876a737ede1098bdb15b0
parent: e54d87be8a5d33e8b1ee3ea6c87b5d615ae9036c
author: phil9 <telephil9@gmail.com>
date: Mon Oct 11 03:41:07 EDT 2021

display ellipsis at the beginning of text (thanks igor)

	the most interesting part of a path or filename is at the
	end so we now put the ellipsis at the beginning of the string
	instead of the end.

--- a/vdir.c
+++ b/vdir.c
@@ -279,19 +279,17 @@
 Point
 drawtext(Point p, Image *i, char* t, int n)
 {
-	int d;
 	char *s;
 	Rune  rn;
 
-	d = stringwidth(font, " ")+stringwidth(font, ellipsis);
-	for(s = t; *s; s++){
-		if(p.x+d>=n){
-			string(screen, p, i, ZP, font, ellipsis);
-			break;
-		}else{
-			s += chartorune(&rn, s) - 1;
-			p = runestringn(screen, p, i, ZP, font, &rn, 1);
-		} 
+	s = t;
+	if(*s && (p.x+stringwidth(font, s)) > n){
+		p = string(screen, p, i, ZP, font, ellipsis);
+		while (*s && (p.x+stringwidth(font, s)) > n) s++;
+	}
+	for( ; *s; s++){
+		s += chartorune(&rn, s) - 1;
+		p = runestringn(screen, p, i, ZP, font, &rn, 1);
 	}
 	return p;
 }