Give a progress meter at the bottom of the source viewer

This is mostly to replace the now missing scrollbar.
The scrollbar is neat, but for now I consider it solely
aesthetic and the real info we want is the total line count
and the current position percentage.
This commit is contained in:
CrystalSplitter 2024-01-14 19:20:42 -08:00 committed by Jordan R AW
parent 898e00ef76
commit 301446ee85
2 changed files with 34 additions and 10 deletions

View File

@ -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
-- -------------------------------------------------------------------------------------------------

View File

@ -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)