-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#66] Print list of found templates in nicer way
- Loading branch information
1 parent
9c83ad6
commit 89bee01
Showing
6 changed files
with
74 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE StrictData #-} | ||
|
||
{-| | ||
Module : Headroom.UI.Table | ||
Description : UI components for rendering tables | ||
Copyright : (c) 2019-2021 Vaclav Svejcar | ||
License : BSD-3-Clause | ||
Maintainer : [email protected] | ||
Stability : experimental | ||
Portability : POSIX | ||
Module providing UI components for tables. | ||
-} | ||
|
||
module Headroom.UI.Table where | ||
|
||
import qualified Headroom.Data.Text as T | ||
import RIO | ||
import qualified RIO.List.Partial as LP | ||
import qualified RIO.Text as T | ||
|
||
|
||
-- | Represents two columns wide table. | ||
newtype Table2 = Table2 [(Text, Text)] deriving (Eq, Show) | ||
|
||
instance Display Table2 where | ||
textDisplay (Table2 rows) = | ||
let maxWidth = (+ 1) . maximum' . fmap (T.length . fst) $ rows | ||
aligned = fmap (\(c1, c2) -> T.justifyLeft maxWidth ' ' c1 <> c2) rows | ||
in T.fromLines aligned | ||
where | ||
maximum' [] = 0 | ||
maximum' xs = LP.maximum xs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Headroom.UI.TableSpec | ||
( spec | ||
) | ||
where | ||
|
||
import qualified Headroom.Data.Text as T | ||
import Headroom.UI.Table | ||
import RIO | ||
import Test.Hspec | ||
|
||
|
||
spec :: Spec | ||
spec = do | ||
describe "Display instance for Table2" $ do | ||
it "prints columns correctly aligned" $ do | ||
let sample = Table2 | ||
[ ("hello" , "world") | ||
, ("super super long first column", "foo") | ||
, ("bar" , "baz") | ||
] | ||
expected = T.fromLines | ||
[ "hello world" | ||
, "super super long first column foo" | ||
, "bar baz" | ||
] | ||
textDisplay sample `shouldBe` expected |