jtdaugherty / brick

A declarative Unix terminal UI library written in Haskell
Other
1.6k stars 164 forks source link

Banners #53

Closed hojberg closed 8 years ago

hojberg commented 8 years ago

Hi,

Thanks for a really cool lib.

I'm interested in sorta doing full width banners or headers. I mean full width of the viewport.

I want to do the equivalent of this

screen shot 2016-05-09 at 3 51 33 pm

and color the background.

I know I can do this manually with spaces, but looking for a way to do it automatically to the 'edge of view' or something like that.

(Apologizes in advance, i'm new to both Brick and Haskell, but having a lot of fun so far)

jtdaugherty commented 8 years ago

There are a couple of ways to do what you want.

If you want to left-justify:

vLimit 1 (str "TODAY (Sunday)" <+> fill ' ')

If you want to right-justify:

vLimit 1 (fill ' ' <+> str "TODAY (Sunday)")

If you want to center:

hCenter $ str "TODAY (Sunday)"

or even

hCenterWith '-' $ str "TODAY (Sunday)"

And to set the attribute (e.g. in the centering case), use withDefAttr:

withDefAttr someAttr $ hCenter $ str "TODAY (Sunday)"

and define someAttr to be some attribute name like

{-# LANGUAGE OverloadedStrings #-}
someAttr :: AttrName
someAttr = "headerAttr"

and then add it to the AttrMap used by your App value:

myAttrMap :: AttrMap
myAttrMap = attrMap defAttr
    [ (someAttr, black `on` yellow)
    ]

app :: App s e
app = App { ..., appAttrMap = const myAttrMap }
jtdaugherty commented 8 years ago

If that helps, please close the issue (or let me know what else I can do). Thanks!

hojberg commented 8 years ago

Nice! I'll check this out. Thank you so much. Didn't know about fill