diff --git a/app/BrickUI.hs b/app/BrickUI.hs index d7cfc25..8f7ae71 100644 --- a/app/BrickUI.hs +++ b/app/BrickUI.hs @@ -15,7 +15,7 @@ import Control.Error (headMay) import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Graphics.Vty as V -import Lens.Micro ((^.)) +import Lens.Micro ((&), (^.)) import qualified Text.Wrap as Wrap import qualified AppConfig @@ -29,12 +29,14 @@ import AppState ) import qualified AppState import AppTopLevel (AppName (..)) +import qualified DrawSourceViewer import qualified Events import qualified Ghcitui.Ghcid.Daemon as Daemon import qualified Ghcitui.Loc as Loc import qualified Ghcitui.NameBinding as NameBinding import qualified HelpText -import qualified DrawSourceViewer +import qualified SourceWindow +import qualified Util -- | Alias for 'AppState AppName' convenience. type AppS = AppState AppName @@ -104,17 +106,37 @@ drawBaseLayer s = -- For seeing the source code. sourceWindowBox :: B.Widget AppName sourceWindowBox = - B.borderWithLabel sourceLabel + B.borderWithLabel sourceLabel . appendLastCommand . B.padRight B.Max . B.padBottom B.Max $ DrawSourceViewer.drawSourceViewer s where appendLastCommand w = - case headMay s.interpState.execHist of - Just h -> B.padBottom B.Max (w <=> B.hBorder <=> B.txt h) - _ -> w - + B.padBottom B.Max (w <=> B.hBorder <=> (lastCmdWidget <+> lineNumRatioWidget)) + where + selectedLine = AppState.selectedLine s + totalLines = s ^. AppState.sourceWindow & SourceWindow.srcWindowLength + percentageNum = + if totalLines > 0 + then (selectedLine * 100) `div` totalLines + else 0 + lineNumRatioWidget = + B.txt + ( Util.showT selectedLine + <> "/" + <> Util.showT totalLines + <> "L (" + <> Util.showT percentageNum + <> "%)" + ) + lastCmdWidget = + B.padRight + B.Max + ( case headMay s.interpState.execHist of + Just h -> B.txt h + _ -> B.txt " " + ) -- For the REPL. interpreterBox :: B.Widget AppName @@ -151,7 +173,7 @@ drawBaseLayer s = then let logDisplay = if null s.debugConsoleLogs then [" "] else s.debugConsoleLogs - applyVisTo (x:xs) = B.visible x : xs + applyVisTo (x : xs) = B.visible x : xs applyVisTo [] = [] in B.borderWithLabel (B.txt "Debug") . B.vLimit 10 @@ -262,7 +284,6 @@ markLabel False labelTxt focus = B.txt . appendFocusButton $ labelTxt markLabel True labelTxt _ = B.withAttr (B.attrName "highlight") (B.txt ("#> " <> labelTxt <> " <#")) - -- ------------------------------------------------------------------------------------------------- -- Brick Main -- ------------------------------------------------------------------------------------------------- diff --git a/app/SourceWindow.hs b/app/SourceWindow.hs index e2d12c3..d2fb62f 100644 --- a/app/SourceWindow.hs +++ b/app/SourceWindow.hs @@ -25,6 +25,9 @@ module SourceWindow , srcNameL , srcSelectedLineL , srcWindowStartL + + -- * Misc + , srcWindowLength ) where import qualified Brick as B @@ -112,7 +115,7 @@ scrollTo pos srcW@SourceWindow{srcWindowEnd = Just windowEnd} = | otherwise = newClampedSelectedLine renderHeight = windowEnd - srcWindowStart srcW isScrollingPastStart = pos < 1 - isScrollingPastEnd = pos > srcWindowLength srcW + isScrollingPastEnd = pos >= srcWindowLength srcW -- Using >= because of a hack. newClampedSelectedLine = Util.clamp (clampedPos, clampedPos + renderHeight)