Compare commits

..

2 commits

Author SHA1 Message Date
a761e242a4 Add 'doctest' as a cabal test
We provide a simple wrapper that executes `doctest` on our `src`
directory. This allows us to run all doctests during a regular `cabal
test` run.
2023-08-29 21:07:33 +02:00
48f054df37 Implement getScreenDimensions 2023-08-29 00:08:02 +02:00

View file

@ -4,8 +4,6 @@ module HCat.Internal where
import Data.Text (Text)
import Data.Text qualified as T
import System.IO
import System.Info qualified as SysInfo
import System.Process qualified as P
-- | @parseArgs@ takes a list of strings and returns a single FilePath if there was exactly one element.
@ -72,28 +70,7 @@ paginate (ScreenDimensions rows cols) =
type Pages = [Page]
type Page = Text
getTerminalSize :: IO ScreenDimensions
getTerminalSize = case SysInfo.os of
"linux" -> tputScreenDimensions
"darwin" -> tputScreenDimensions
_ -> pure $ defaultScreenDimensions{screenRows = 25, screenColumns = 80}
defaultScreenDimensions :: ScreenDimensions
defaultScreenDimensions = ScreenDimensions{screenRows = 25, screenColumns = 80}
tputScreenDimensions :: IO ScreenDimensions
tputScreenDimensions = ScreenDimensions <$> tput "lines" <*> tput "cols"
getScreenDimensions :: IO ScreenDimensions
getScreenDimensions = ScreenDimensions <$> tput "lines" <*> tput "cols"
where
tput cmd = read <$> P.readProcess "tput" [cmd] ""
data UserCommand = NextPage | Quit deriving (Show)
getUserCommand :: IO UserCommand
getUserCommand = do
hSetBuffering stdin NoBuffering
hSetEcho stdin False
input <- getChar
case input of
' ' -> pure NextPage
'q' -> pure Quit
_ -> getUserCommand