fixed column behavior in qdls

This commit is contained in:
Valerie Wolfe 2024-06-10 13:05:12 -04:00
parent 1b42869e3f
commit 763ccb3291

View file

@ -1,5 +1,4 @@
 using Qdls;
using Qdls;
// collect args and consume flags // collect args and consume flags
List<string> arguments = args.ToList(); List<string> arguments = args.ToList();
@ -25,10 +24,10 @@ foreach(var arg in arguments) {
// state vars // state vars
var buffer = ""; var buffer = "";
var longest = children.OrderByDescending(s => Path.GetFileName(s).Length).First().Length; var longest = Path.GetFileName(children.OrderByDescending(s => s.Length).First()).Length;
var columns = Console.WindowWidth / (longest + 2); var columns = Console.WindowWidth / (longest + 2);
var multiline = columns < args.Length; var multiline = columns < children.Count();
var position = -1; var position = 0;
// print names if more than one target // print names if more than one target
if(args.Length > 1) if(args.Length > 1)
@ -46,13 +45,13 @@ foreach(var arg in arguments) {
buffer += Format.Directory; buffer += Format.Directory;
// if we pass max width, write buffer and clear // if we pass max width, write buffer and clear
if( multiline && (++position > columns) ) { if( (++position > columns) && multiline ) {
position = -1; position = 1;
Console.WriteLine(buffer); Console.WriteLine(buffer.TrimEnd());
buffer = ""; buffer = "";
} }
if(multiline) if(multiline)
buffer += $"{name}{Format.Reset}".PadRight(longest) + " "; buffer += $"{name}{Format.Reset}".PadRight(longest + 4);
else else
buffer += $"{name}{Format.Reset} "; buffer += $"{name}{Format.Reset} ";