shithub: vdir

Download patch

ref: ff9b7eba5ff98f144d9bb251a7000942bf57d20a
parent: 4cb40bf44feafa85d93450a7299f7014b4277f55
author: phil9 <telephil9@gmail.com>
date: Thu Oct 7 14:35:29 EDT 2021

dynamic column sizes computation

	the width of the file size column was hardcoded and far
	too big.
	We now compute the column size dynamically to allow for
	more space for the file name column.
	Thanks sigrid for the report/suggestion.

--- a/vdir.c
+++ b/vdir.c
@@ -56,6 +56,7 @@
 Image *viewfg;
 Image *scrollbg;
 Image *scrollfg;
+int sizew;
 int lineh;
 int nlines;
 int offset;
@@ -110,7 +111,7 @@
 void
 loaddirs(void)
 {
-	int fd;
+	int fd, i, m;
 
 	fd = open(path, OREAD);
 	if(fd<0){
@@ -123,6 +124,12 @@
 	qsort(dirs, ndirs, sizeof *dirs, (int(*)(void*,void*))dircmp);
 	offset = 0;
 	close(fd);
+	m = 0;
+	for(i=0; i < ndirs; i++){
+		if(dirs[i].length>m)
+			m=dirs[i].length;
+	}
+	sizew = 1+1+log(m)/log(10);
 }
 
 void
@@ -307,7 +314,7 @@
 	r = Rpt(p, addpt(p, Pt(Dx(viewr)-2*Toolpadding, lineh)));
 	draw(screen, r, selected?toolbg:viewbg, nil, ZP);
 	t = mdate(d);
-	snprint(buf, sizeof buf, "%12lld  %s", d.length, t);
+	snprint(buf, sizeof buf, "%*lld  %s", sizew, d.length, t);
 	free(t);
 	img = (d.qid.type&QTDIR) ? folder : file;
 	p.y -= Padding;