wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.77k stars 795 forks source link

background table source.Color defaults to Cover and will crop depending on window size #2817

Open HotelCalifornia opened 1 year ago

HotelCalifornia commented 1 year ago

given the following configuration (wezterm version 20221119-145034-49b9839f and nightly version 20221127-215232-c6e29b78)

local wezterm = require('wezterm')
return {
    color_scheme = 'OneDark (Gogh)',
    initial_cols = 120,
    initial_rows = 36,
    font = wezterm.font('TamzenForPowerline'),
    font_size = 14.0,
    background = {
        {
            source = {
                Color = 'black',
            },
        },
        {
            source = {
                File = '/path/to/some/image.jpg',
            },
            hsb = {
                brightness = 0.06056213162296187,
            },
            height = 'Contain',
            repeat_y = 'NoRepeat',
            vertical_align = 'Middle',
        },
    },
}

I'd expect solid black to be rendered underneath the background image. instead, since the image height is set to Contain and the vertical align to Middle, there are two transparent strips above and below the image

image

I tried with a number of other values for Color (in addition to the named one above), including 'rgb(183, 198, 213)' and the equivalent '#b7c6d5' but nothing changes.

using the following config works as a hacky workaround (lower image is not bounded by Contain so you kinda get the desired effect but it doesn't work for images that have content by the edges) so i know that the layer compositing itself is working.

    background = {
        {
            source = {
                File = '/path/to/some/image.jpg',
            },
            hsb = {
                brightness = 0.06056213162296187,
            },
        },
        {
            source = {
                File = '/path/to/some/image.jpg',
            },
            hsb = {
                brightness = 0.06056213162296187,
            },
            height = 'Contain',
            repeat_y = 'NoRepeat',
            vertical_align = 'Middle',
        },
    }
HotelCalifornia commented 1 year ago

dug around in the code a bit and found a comment regarding a naive heuristic for the size of the generated Color image. confirmed that specifying height and width manually caused the configuration to work as expected

    background = {
        {
            source = {
                Color = 'black',
            },
            -- here:
            height = '100%',
            width = '100%',
        },
        {
            source = {
                File = '/path/to/some/image.jpg',
            },
            hsb = {
                brightness = 0.06056213162296187,
            },
            height = 'Contain',
            repeat_y = 'NoRepeat',
            vertical_align = 'Middle',
        },
    },
HotelCalifornia commented 1 year ago

recommend making a note of this in the docs

wez commented 1 year ago

Perhaps the default width/height for Color backgrounds should be set to Contain instead of Cover?

HotelCalifornia commented 1 year ago

Perhaps the default width/height for Color backgrounds should be set to Contain instead of Cover?

i tried removing the second background layer to test the default behavior and it worked as i expected (covered the entire window.... so it seems like maybe this is more to do with the layer compositing? though as i mentioned above layering two images on top of one another worked just fine.