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

Merging attributes #8

Closed
rneswold opened this issue Apr 11, 2016 · 5 comments
Closed

Merging attributes #8

rneswold opened this issue Apr 11, 2016 · 5 comments

Comments

@rneswold
Copy link

It would be nice, when overlaying one image on another, that if the upper image doesn't specify a background, it uses the lower image's background. Right now, it seems the upper image will have a black background (unless I missed an important operator or combinator.) Maybe a new operator <//> to overlay and blend the two images?

Something like that would make it easy to do things like:

open Notty
open Notty.Infix

let progress_bar w pcnt =
  let pcnt = max 0.0 (min 1.0 pcnt) in
  let w' = truncate (float w *. pcnt) in
  I.(hsnap w (strf ~attr:A.(fg yellow) "%.0f%%" (pcnt *. 100.))) </>
    I.((char A.(bg cyan) ' ' w' 1) <|> (char A.(bg blue) ' ' (w - w') 1))

The progress is displayed using the background attribute. I'd like it to continue behind the numeric string but, instead, the background of the text is always black. And it's not necessarily easy to implement what I want using the current combinators. I'd have to keep the string and conditionally cut it up so half can be displayed with one background the other half with the other background. I'd also have to stop using hsnap since I'd have to carefully control how it's centered to make sure the backgrounds lined up properly.

@rneswold
Copy link
Author

A more formal way to say it might be:

When blending two images, the top image's contents and attributes are used. If the top image is missing an attribute (a foreground and/or background attribute), then the lower image's corresponding attribute is used.

@hannesm
Copy link

hannesm commented Apr 12, 2016

If I understand you correctly, you want to have support for a transparent (or void) colour (if used on an overlay, the underlying colour is used)?

@pqwy
Copy link
Owner

pqwy commented Apr 12, 2016

This has to do with something I wanted to write on #7, which is that in principle, I'm reluctant to add more abstraction mechanisms which are paralleled by functions. So the first time around, I didn't want to have images open in the attribute.

But early on, notty did have this feature, of influencing the attributes of a constructed image, and I'm increasingly convinced this is useful. It's still a bit unclear what's the most compact system of describing that, but I'm planning something like that for the next release.

@rneswold
Copy link
Author

@hannesm Exactly. Although I believe A.empty should behave as A.(fg transparent ++ bg transparent) so that, by default, unspecified attributes use the underlying attributes.

@rneswold
Copy link
Author

Let #24 handle this issue.

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

3 participants