Skip to content

Commit

Permalink
Only show pager when terminal is too small
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Aug 12, 2024
1 parent cebd0c8 commit 42ddd48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions ghcup.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ library ghcup-optparse

else
build-depends: unix ^>=2.7 || ^>=2.8
, terminal-size ^>=0.3.3

library ghcup-tui
import: app-common-depends
Expand Down
4 changes: 4 additions & 0 deletions lib-opt/GHCup/OptParse/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import System.Console.Pretty hiding ( color )

import qualified Data.Text as T
import qualified System.Console.Pretty as Pretty
import qualified System.Console.Terminal.Size as TP
import Control.Exception.Safe (MonadMask)
import GHCup.Types.Optics
import GHCup.Prelude.Logger (logDebug)
Expand Down Expand Up @@ -200,8 +201,11 @@ printListResult no_color (PagerConfig pList pCmd) raw lr = do
padded = fmap (\xs -> zipWith padTo xs lengths) rows

let text = fmap unwords (if raw then rows else padded)
tp <- liftIO TP.size
if | pList
, not raw
, Just (TP.Window h _) <- tp
, length text > h - 2
, Just cmd <- pCmd -> do
r <- liftIO $ sendToPager cmd (T.pack <$> text)
case r of
Expand Down

0 comments on commit 42ddd48

Please sign in to comment.