@@ -485,7 +485,22 @@ func (fileBrowser *FileBrowserComponent) SetSelectedSnapshot(snapshot *data.Snap
485485
486486func (fileBrowser * FileBrowserComponent ) Refresh () {
487487 fileBrowser .showMessage (status_message .NewInfoStatusMessage ("Refreshing..." ))
488- title := fmt .Sprintf ("Path: %s" , fileBrowser .path )
488+
489+ _ , _ , width , _ := fileBrowser .tableContainer .GetLayout ().GetRect ()
490+ if width == 0 {
491+ width = 80
492+ }
493+ // title is " Path: Path: <path> "
494+ // theme.CreateTitleText adds 2 spaces.
495+ // Box adds borders (2 chars).
496+ // "Path: " is 6 chars.
497+ // So available is width - 2 (borders) - 2 (spaces) - 6 (prefix) = width - 10.
498+ maxWidth := width - 10
499+ if maxWidth < 20 {
500+ maxWidth = 20
501+ }
502+
503+ title := fmt .Sprintf ("Path: %s" , fileBrowser .truncatePath (fileBrowser .path , maxWidth ))
489504 fileBrowser .tableContainer .SetTitle (title )
490505
491506 entries , err := fileBrowser .computeTableEntries ()
@@ -499,6 +514,48 @@ func (fileBrowser *FileBrowserComponent) Refresh() {
499514 fileBrowser .showMessage (status_message .NewInfoStatusMessage ("" ))
500515}
501516
517+ func (fileBrowser * FileBrowserComponent ) truncatePath (path string , maxWidth int ) string {
518+ if len ([]rune (path )) <= maxWidth {
519+ return path
520+ }
521+
522+ separator := string (os .PathSeparator )
523+ parts := strings .Split (path , separator )
524+
525+ if len (parts ) <= 1 {
526+ runes := []rune (path )
527+ if len (runes ) > maxWidth && maxWidth > 3 {
528+ return "..." + string (runes [len (runes )- maxWidth + 3 :])
529+ }
530+ return path
531+ }
532+
533+ // Try shortening parts from left to right, except the last one
534+ for i := 0 ; i < len (parts )- 1 ; i ++ {
535+ if parts [i ] == "" || parts [i ] == "." || parts [i ] == ".." {
536+ continue
537+ }
538+
539+ runes := []rune (parts [i ])
540+ if len (runes ) > 1 {
541+ parts [i ] = string (runes [0 ]) + "…"
542+ newPath := strings .Join (parts , separator )
543+ if len ([]rune (newPath )) <= maxWidth {
544+ return newPath
545+ }
546+ }
547+ }
548+
549+ // If still too long, truncate the resulting path with ellipsis at the beginning
550+ finalPath := strings .Join (parts , separator )
551+ finalRunes := []rune (finalPath )
552+ if len (finalRunes ) > maxWidth && maxWidth > 3 {
553+ return "..." + string (finalRunes [len (finalRunes )- maxWidth + 3 :])
554+ }
555+
556+ return finalPath
557+ }
558+
502559func (fileBrowser * FileBrowserComponent ) selectFileEntry (newSelection * data.FileBrowserEntry ) {
503560 if fileBrowser .GetSelection () == newSelection || (fileBrowser .GetSelection () != nil && newSelection != nil && fileBrowser .GetSelection ().GetRealPath () == newSelection .GetRealPath ()) {
504561 return
0 commit comments