From b687795db6d57188d6f7d65437f0a8dc0f9a89a4 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 8 Oct 2025 21:48:15 +0530 Subject: Add truncate for current directory --- lib/Daffm/View.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/Daffm/View.hs') diff --git a/lib/Daffm/View.hs b/lib/Daffm/View.hs index e65a13a..da6a11b 100644 --- a/lib/Daffm/View.hs +++ b/lib/Daffm/View.hs @@ -1,7 +1,7 @@ module Daffm.View where -import Brick.Types (Widget) -import Brick.Widgets.Core (Padding (Max, Pad), emptyWidget, hBox, hLimit, padLeft, padRight, str, txt, vBox, vLimit, withAttr, (<+>)) +import Brick.Types (Context (availWidth), Size (Fixed), Widget (Widget, render), getContext) +import Brick.Widgets.Core (Padding (Max, Pad), TextWidth (textWidth), emptyWidget, hBox, hLimit, padLeft, padRight, str, txt, vBox, vLimit, withAttr, (<+>)) import Brick.Widgets.Edit (renderEditor) import qualified Brick.Widgets.List as L import Daffm.Attrs (directoryAttr, directoryLinkAttr, directorySelectedAttr, fileAttr, fileSelectedAttr, invalidLinkAttr, linkAttr, searchMarchAttr) @@ -27,7 +27,15 @@ hFixed :: Int -> Widget n -> Widget n hFixed w = hLimit w . padRight Max headerView :: AppState -> Widget n -headerView (AppState {stateCwd}) = txt stateCwd +headerView (AppState {stateCwd}) = Widget Fixed Fixed $ do + c <- getContext + let width = availWidth c - 2 -- with padding + render . toWidget . trunc width $ stateCwd + where + toWidget = padLeft (Pad 1) . padRight (Pad 1) . txt + trunc width text + | width < textWidth text = "…" <> Text.takeEnd (width - 1) text + | otherwise = Text.takeEnd width text fileItemView :: AppState -> Int -> Bool -> FileInfo -> Widget FocusTarget fileItemView appState index sel fileInfo@(FileInfo {filePath, fileSize, fileType, fileMode}) = -- cgit v1.3.1