Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background attribute behavior with layers #95

Closed
jtdaugherty opened this issue Jun 10, 2016 · 2 comments
Closed

Background attribute behavior with layers #95

jtdaugherty opened this issue Jun 10, 2016 · 2 comments

Comments

@jtdaugherty
Copy link
Owner

The following program behaves unexpectedly for me with Vty 5.5.0.

The actual behavior:
The apparent space in the first line above the text r --> has a blue background.

The expected behavior:
The apparent space in the first line above the text r --> has the default terminal background (i.e. the blue background stops at the end of the first line's string).

This behavior also manifests if you increase to translateY 2: the blue background still terminates after the end of the first line, but alignment with the right-hand side of the second string layer.

module Main where

import Graphics.Vty

topAttr :: Attr
topAttr = defAttr `withForeColor` white
                  `withBackColor` blue

topLayer :: Image
topLayer = string topAttr "<-- Top layer -->"

bottomAttr :: Attr
bottomAttr = defAttr `withForeColor` white
                     `withBackColor` green

bottomLayer :: Image
bottomLayer =
    translateY 1 $
    translateX 2 $
    string bottomAttr "<-- Bottom layer -->"

main :: IO ()
main = do
    cfg <- standardIOConfig
    vty <- mkVty cfg
    let pic = picForLayers [topLayer, bottomLayer]
    update vty pic
    e <- nextEvent vty
    shutdown vty
@jtdaugherty
Copy link
Owner Author

It turns out that the problem only arises when I leave the Picture's Background set to ClearBackground. If I set it to Background ' ' defAttr, I get the expected behavior.

Looking at substituteSkips, I see that for ClearBackground, currentAttr is used for the spaces that get used to fill in the skipped columns. I can see value in that behavior in some cases, but it is definitely causing this behavior.

I could work around this by just setting an explicit background on my Picture values, but since it is easy to get this behavior without trying very hard I'd like to find a way to change it. What I don't know is, how can this be changed without also being wrong sometimes? If a Skip always implied a change in attribute from the previous span operation to the background, that might break a bunch of interfaces.

It's almost like the BGFills that get added by the join functions need to result in different kinds of Skip handling later on in span conversion. One way this could go is that whenever you join two images you never get any implicit background sharing in the BGFills. If you wanted to get that, you could use a different join combinator that didn't do that, or you could pad the images yourself to get the desired effect.

Thoughts?

@jtdaugherty
Copy link
Owner Author

Incidentally, I noticed that the documentation for Background talks about how a picture with a clear background will permit you to see what's underneath in a layering situation, but I don't understand how that could ever happen because I don't see how you could layer Pictures. I just see a way to make a single Picture from Image layers. Am I missing something there?

jtdaugherty added a commit to jtdaugherty/brick that referenced this issue Jun 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant