@@ -17,7 +17,6 @@ import (
1717 "time"
1818
1919 "github.com/spf13/cobra"
20- "github.com/wavetermdev/waveterm/pkg/util/colprint"
2120 "github.com/wavetermdev/waveterm/pkg/util/utilfn"
2221 "github.com/wavetermdev/waveterm/pkg/wshrpc"
2322 "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
@@ -435,32 +434,46 @@ func fileMvRun(cmd *cobra.Command, args []string) error {
435434}
436435
437436func filePrintColumns (filesChan <- chan wshrpc.RespOrErrorUnion [wshrpc.CommandRemoteListEntriesRtnData ]) error {
438- width := 80 // default if we can't get terminal
439- if w , _ , err := term .GetSize (int (os .Stdout .Fd ())); err == nil {
437+ width := 80
438+ w , _ , err := term .GetSize (int (os .Stdout .Fd ()))
439+ if err == nil {
440440 width = w
441441 }
442442
443- numCols := width / 10
443+ var allNames []string
444+ maxLen := 0
445+ for respUnion := range filesChan {
446+ if respUnion .Error != nil {
447+ return respUnion .Error
448+ }
449+ for _ , f := range respUnion .Response .FileInfo {
450+ allNames = append (allNames , f .Name )
451+ if len (f .Name ) > maxLen {
452+ maxLen = len (f .Name )
453+ }
454+ }
455+ }
456+
457+ colWidth := maxLen + 2
458+ numCols := width / colWidth
444459 if numCols < 1 {
445460 numCols = 1
446461 }
447462
448- return colprint .PrintColumnsArray (
449- filesChan ,
450- numCols ,
451- 100 , // sample size
452- func (respUnion wshrpc.RespOrErrorUnion [wshrpc.CommandRemoteListEntriesRtnData ]) ([]string , error ) {
453- if respUnion .Error != nil {
454- return []string {}, respUnion .Error
455- }
456- strs := make ([]string , len (respUnion .Response .FileInfo ))
457- for i , f := range respUnion .Response .FileInfo {
458- strs [i ] = f .Name
459- }
460- return strs , nil
461- },
462- os .Stdout ,
463- )
463+ col := 0
464+ for _ , name := range allNames {
465+ fmt .Fprintf (os .Stdout , "%-*s" , colWidth , name )
466+ col ++
467+ if col >= numCols {
468+ fmt .Fprintln (os .Stdout )
469+ col = 0
470+ }
471+ }
472+ if col > 0 {
473+ fmt .Fprintln (os .Stdout )
474+ }
475+
476+ return nil
464477}
465478
466479func filePrintLong (filesChan <- chan wshrpc.RespOrErrorUnion [wshrpc.CommandRemoteListEntriesRtnData ]) error {
0 commit comments