{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{-# HLINT ignore "Use newtype instead of data" #-}
module DataFrame.Display where

import qualified Data.Text.IO as T
import qualified DataFrame.Internal.DataFrame as D
import qualified DataFrame.Operations.Subset as D

import Data.Function

data DisplayOptions = DisplayOptions
    { {-- | Maximum number of rows to render.
      --
      --   * If this value is less than or equal to 0, no rows are printed.
      --   * If it is greater than the number of rows in the frame, all rows are printed.
      --}
      DisplayOptions -> Int
displayRows :: Int
    }

defaultDisplayOptions :: DisplayOptions
defaultDisplayOptions :: DisplayOptions
defaultDisplayOptions = Int -> DisplayOptions
DisplayOptions Int
10

-- | Render a 'DataFrame' to stdout according to 'DisplayOptions'.
display :: DisplayOptions -> D.DataFrame -> IO ()
display :: DisplayOptions -> DataFrame -> IO ()
display DisplayOptions
opts DataFrame
df = DataFrame
df DataFrame -> (DataFrame -> DataFrame) -> DataFrame
forall a b. a -> (a -> b) -> b
& Int -> DataFrame -> DataFrame
D.take (DisplayOptions -> Int
displayRows DisplayOptions
opts) DataFrame -> (DataFrame -> Text) -> Text
forall a b. a -> (a -> b) -> b
& (DataFrame -> Bool -> Text
`D.asText` Bool
False) Text -> (Text -> IO ()) -> IO ()
forall a b. a -> (a -> b) -> b
& Text -> IO ()
T.putStrLn