mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 03:42:25 +03:00
cli:Improve pretty table rendering
This fixes table edges always using single-width intersections and adds support for double horizontal lines with single vertical lines
This commit is contained in:
parent
bc4ea83d86
commit
43b118c9b8
@ -83,29 +83,18 @@ renderHLine _ _ _ NoLine = []
|
||||
renderHLine pretty w h SingleLine = [renderHLine' pretty SingleLine w (horizontalBar pretty) h]
|
||||
renderHLine pretty w h DoubleLine = [renderHLine' pretty DoubleLine w (doubleHorizontalBar pretty) h]
|
||||
|
||||
doubleCross :: Bool -> String
|
||||
doubleCross pretty = if pretty then "╬" else "++"
|
||||
|
||||
doubleVerticalCross :: Bool -> String
|
||||
doubleVerticalCross pretty = if pretty then "╫" else "++"
|
||||
|
||||
cross :: Bool -> Char
|
||||
cross pretty = if pretty then '┼' else '+'
|
||||
|
||||
renderHLine' :: Bool -> Properties -> [Int] -> Char -> Header String -> String
|
||||
renderHLine' pretty prop is sep h = [ cross pretty, sep ] ++ coreLine ++ [sep, cross pretty]
|
||||
renderHLine' pretty prop is sep h = edge ++ sep : coreLine ++ sep : edge
|
||||
where
|
||||
edge = cross SingleLine prop
|
||||
coreLine = concatMap helper $ flattenHeader $ zipHeader 0 is h
|
||||
helper = either vsep dashes
|
||||
dashes (i,_) = replicate i sep
|
||||
vsep NoLine = replicate 2 sep -- match the double space sep in renderColumns
|
||||
vsep SingleLine = sep : cross pretty : [sep]
|
||||
vsep DoubleLine = sep : cross' ++ [sep]
|
||||
cross' = case prop of
|
||||
DoubleLine -> doubleCross pretty
|
||||
_ -> doubleVerticalCross pretty
|
||||
|
||||
-- padLeft :: Int -> String -> String
|
||||
-- padLeft l s = padding ++ s
|
||||
-- where padding = replicate (l - length s) ' '
|
||||
vsep v = sep : cross v prop ++ [sep]
|
||||
|
||||
-- vertical horizontal
|
||||
cross SingleLine SingleLine = if pretty then "┼" else "+"
|
||||
cross SingleLine DoubleLine = if pretty then "╪" else "+"
|
||||
cross DoubleLine SingleLine = if pretty then "╫" else "++"
|
||||
cross DoubleLine DoubleLine = if pretty then "╬" else "++"
|
||||
cross _ _ = ""
|
||||
|
Loading…
Reference in New Issue
Block a user