@@ -281,7 +281,7 @@ static void PrintRNTuple(std::ostream &stream, const ROOT::RNTupleDescriptor &de
281281 std::size_t maxNameLen = 0 , maxTypeLen = 0 ;
282282 std::vector<const ROOT::RFieldDescriptor *> fields;
283283 fields.reserve (rootField.GetLinkIds ().size ());
284- for (const auto &field: desc.GetFieldIterable (rootField.GetId ())) {
284+ for (const auto &field : desc.GetFieldIterable (rootField.GetId ())) {
285285 fields.push_back (&field);
286286 maxNameLen = std::max (maxNameLen, field.GetFieldName ().length ());
287287 maxTypeLen = std::max (maxTypeLen, field.GetTypeName ().length ());
@@ -481,11 +481,11 @@ static void PrintNodesInColumns(std::ostream &stream, const RootLsTree &tree,
481481
482482 const bool isTerminal = terminalSize.x + terminalSize.y > 0 ;
483483
484- bool mustIndent = false ;
484+ auto curCol = 0u ;
485485 for (auto i = 0u ; i < nNodes; ++i) {
486486 NodeIdx childIdx = nodesBegin[i];
487487 const auto &child = tree.fNodes [childIdx];
488- if ((i % nCols) == 0 || mustIndent ) {
488+ if (curCol == 0 ) {
489489 PrintIndent (stream, indent);
490490 }
491491
@@ -498,22 +498,39 @@ static void PrintNodesInColumns(std::ostream &stream, const RootLsTree &tree,
498498 stream << Color (kAnsiGreen );
499499 }
500500
501- const bool isExtremal = !(((i + 1 ) % nCols) != 0 && i != nNodes - 1 );
501+ // Handle line breaks. Lines are broken in the following situations:
502+ // - when the current column number reaches the max number of columns
503+ // - when we are in recursive mode and the item is a directory with children
504+ // - when we are in recursive mode and the NEXT item is a directory with children
505+
506+ const bool isDirWithRecursiveDisplay = isDir && (flags & RootLsArgs::kRecursiveListing ) && child.fNChildren > 0 ;
507+
508+ bool nextIsDirWithRecursiveDisplay = false ;
509+ if ((flags & RootLsArgs::kRecursiveListing ) && i < nNodes - 1 ) {
510+ NodeIdx nextChildIdx = nodesBegin[i + 1 ];
511+ const auto &nextChild = tree.fNodes [nextChildIdx];
512+ nextIsDirWithRecursiveDisplay =
513+ nextChild.fNChildren > 0 && ClassInheritsFrom (nextChild.fClassName .c_str (), " TDirectory" );
514+ }
515+
516+ const bool isExtremal = (((curCol + 1 ) % nCols) == 0 ) || (i == nNodes - 1 ) || isDirWithRecursiveDisplay ||
517+ nextIsDirWithRecursiveDisplay;
502518 if (!isExtremal) {
503- stream << std::left << std::setw (colWidths[i % nCols]) << child.fName ;
519+ stream << std::left << std::setw (colWidths[curCol % nCols]) << child.fName ;
504520 } else {
505521 stream << std::setw (1 ) << child.fName ;
506522 }
507523 stream << Color (kAnsiNone );
508524
509- if (isExtremal)
510- stream << " \n " ;
525+ if (isExtremal) {
526+ stream << ' \n ' ;
527+ curCol = 0 ;
528+ } else {
529+ ++curCol;
530+ }
511531
512- if (isDir && (flags & RootLsArgs::kRecursiveListing )) {
513- if (!isExtremal)
514- stream << " \n " ;
532+ if (isDirWithRecursiveDisplay) {
515533 PrintChildrenInColumns (stream, tree, childIdx, flags, indent + 2 );
516- mustIndent = true ;
517534 }
518535 }
519536}
0 commit comments