View Single Post
Old 01-22-2025, 01:26 PM   #776
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,529
Karma: 8075744
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Comfy.n View Post
Hi,

I'm using the above composite to display human readable format sizes and this looks fine on Book Details but I wanted to prevent the trailing pipe showing when there's only one format available, so instead of...

💾 EPUB: 1.2 MB |

the ideal output would be:

💾 EPUB: 1.2 MB

Ideas?
Put this just before the last line:
Code:
	if substr(out, -2, 0) == '| ' then
		out = substr(out, 0, -3)
	fi;
For fun, here is a template that does almost the same thing but hundreds of around fifty times faster. A difference is that the formats are output in alphabetic order, not the order you specified.
Code:
program: 
	out = '  💾  ';
	fmts = list_sort(formats_sizes(), 0, ',') ;
	for fmt_data in fmts:
		fmt = sublist(fmt_data, 0, 1, ':');
		size = sublist(fmt_data, 1, 2, ':'); 
		str = if size ># 0 then strcat(fmt, ': ', human_readable(size), ' | ') else '' fi;
		out=strcat(out, str) 
	rof;
	if substr(out, -2, 0) == '| ' then
		out = substr(out, 0, -3)
	fi;
	out

Last edited by chaley; 01-22-2025 at 02:06 PM.
chaley is offline   Reply With Quote