abbreviateSegmentPath function
Renders segment text on a ~-abbreviated, length-clamped cwd
(omp's shortenPath semantics: abbreviate ~/, then tuiFitWidth to
maxLength cells, then collapse leading components when still cut —
the ladder re-renders through StatusLineSegmentOptions.withPathMaxLength).
Implementation
String abbreviateSegmentPath(
String cwd, {
String? homeDir,
required bool abbreviate,
required int maxLength,
String? workRoot,
required bool stripWorkPrefix,
}) {
var path = cwd;
// Work-root strip first (raw path): inside the workspace the display
// root is the workspace itself, so `~` never appears.
if (stripWorkPrefix &&
workRoot != null &&
workRoot.isNotEmpty &&
(path == workRoot || path.startsWith('$workRoot/'))) {
return tuiFitWidth(
path == workRoot ? '.' : path.substring(workRoot.length + 1),
maxLength,
);
}
return _homeAbbreviatedFit(
path,
abbreviate: abbreviate,
homeDir: homeDir,
maxLength: maxLength,
);
}