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

Palette color of "transparent" set as segment foreground doesn't behave as expected #5790

Closed
1 task done
Nettifani opened this issue Oct 30, 2024 · 1 comment
Closed
1 task done
Assignees
Labels
🐛 bug Something isn't working

Comments

@Nettifani
Copy link

Code of Conduct

  • I agree to follow this project's Code of Conduct

What happened?

Whilst I was changing my oh-my-posh config to use palette colors, I noticed some curious behaviour when setting the segment foreground color to point to a palette color with value of transparent. The background color of the segment turned grey even though it was explicitly set to a different value in the config.

I can reproduce this issue with the provided config on the main branch (bbbc8c5). I expected the resulting output to be some text on a green background; however the actual output is some text on a grey background.

I think the bug might be related to this function:

func asAnsiColors(background, foreground color.Ansi) (color.Ansi, color.Ansi) {
if len(background) == 0 {
background = color.Background
}
if len(foreground) == 0 {
foreground = color.Foreground
}
background = background.Resolve(CurrentColors, ParentColors)
foreground = foreground.Resolve(CurrentColors, ParentColors)
inverted := foreground == color.Transparent && len(background) != 0
backgroundAnsi := getAnsiFromColorString(background, !inverted)
foregroundAnsi := getAnsiFromColorString(foreground, false)
return backgroundAnsi, foregroundAnsi
}

When the foreground color is set to p:text-foreground, inverted is false because foreground doesn't get resolved from a palette reference to the final actual value. I'm unsure why exactly does this cause problems, but after some experimenting I wrote a hacky workaround for myself (Nettifani@c77246a) which seems to resolve the issue. I hope the information I have provided is useful in some way :)

Theme

final_space = true
version = 2

[palette]
  text-foreground = "transparent"

[[blocks]]
  type = "prompt"
  alignment = "left"

  [[blocks.segments]]
    type = "text"
    style = "plain"
    foreground = "p:text-foreground" # Changing this to "transparent" works, but "p:text-foreground" doesn't.
    background = "green"
    template = "This text should have a green background."

What OS are you seeing the problem on?

Linux

Which shell are you using?

bash

Log output

Version: 

Shell: bash (5.2.37(2)-release)

Prompt:

This text should have a green background. 

Segments:

ConsoleTitle(false)                       -   0 ms
Text(true)                                -   0 ms

Run duration: 1.435084ms

Cache path: /home/nettis/.cache/oh-my-posh

Config path: /tmp/oh-my-posh/theme.min.toml

Logs:

�[38;2;191;207;240m[DEBUG] �[38;2;156;231;201m04:30:36.031 �[0mdebug.go:49�[38;2;156;231;201m →�[0m debug mode enabled
[DEBUG] 04:30:36.031 debug.go:49 → plain mode enabled
[DEBUG] 04:30:36.031 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.031 terminal.go:Getenv(LOCALAPPDATA) - 23.694µs
[DEBUG] 04:30:36.031 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.031 terminal.go:Getenv(OMP_CACHE_DIR) - 4.809µs
[DEBUG] 04:30:36.031 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.031 terminal.go:Getenv(XDG_CACHE_HOME) - 4.248µs
[TRACE] 04:30:36.031 terminal.go:CachePath() - 68.999µs
[DEBUG] 04:30:36.031 terminal.go:70 → loading cache file: /home/nettis/.cache/oh-my-posh/omp.cache
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: environment_platform
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: is_wsl
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: prompt_count_cache_1135791
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: upgrade_check
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: engine_cache_1135791
[TRACE] 04:30:36.032 terminal.go(/home/nettis/.cache/oh-my-posh/omp.cache) - 172.483µs
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.032 terminal.go:Getenv(LOCALAPPDATA) - 5.691µs
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.032 terminal.go:Getenv(OMP_CACHE_DIR) - 5.771µs
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.032 terminal.go:Getenv(XDG_CACHE_HOME) - 4.077µs
[TRACE] 04:30:36.032 terminal.go:CachePath() - 49.162µs
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache file: /home/nettis/.cache/oh-my-posh/omp.cache.a3cb8c0e-1c84-45f3-b945-3d3a0ac4640b
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: prompt_count_cache
[DEBUG] 04:30:36.032 terminal.go:70 → loading cache key: template_cache
[TRACE] 04:30:36.032 terminal.go(/home/nettis/.cache/oh-my-posh/omp.cache.a3cb8c0e-1c84-45f3-b945-3d3a0ac4640b) - 164.297µs
[TRACE] 04:30:36.032 terminal.go:setPromptCount() - 731ns
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → /tmp/oh-my-posh/theme.min.toml
[TRACE] 04:30:36.032 terminal.go:Getenv(POSH_THEME) - 5.56µs
[DEBUG] 04:30:36.032 terminal.go:ResolveConfigPath:96 → config set using POSH_THEME: /tmp/oh-my-posh/theme.min.toml
[TRACE] 04:30:36.032 terminal.go:ResolveConfigPath() - 25.578µs
[TRACE] 04:30:36.032 terminal.go:Init() - 625.099µs
[TRACE] 04:30:36.032 terminal.go:Flags() - 90ns
[TRACE] 04:30:36.032 load.go:loadConfig() - 170.499µs
[TRACE] 04:30:36.032 terminal.go:Flags() - 60ns
[DEBUG] 04:30:36.032 debug.go:57 → terminal program: Unknown
[DEBUG] 04:30:36.032 debug.go:57 → terminal shell: shell
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.032 terminal.go:Getenv(OMP_CACHE_DISABLED) - 4.508µs
[TRACE] 04:30:36.032 colors.go:SetAccentColor() - 1.102µs
[TRACE] 04:30:36.032 terminal.go:Shell() - 160ns
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → 5.2.37(2)-release
[TRACE] 04:30:36.032 terminal.go:Getenv(POSH_SHELL_VERSION) - 5.581µs
[DEBUG] 04:30:36.032 debug.go:PrintDebug:23 → segment: Title
[DEBUG] 04:30:36.032 text.go:Render:80 → rendering template: 
[TRACE] 04:30:36.032 terminal.go:Flags() - 80ns
[TRACE] 04:30:36.032 terminal.go:Shell() - 81ns
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.032 terminal.go:Getenv(POSH_CURSOR_LINE) - 4.258µs
[DEBUG] 04:30:36.032 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.032 terminal.go:Getenv(POSH_CURSOR_COLUMN) - 4.138µs
[TRACE] 04:30:36.032 terminal.go:Flags() - 50ns
[TRACE] 04:30:36.032 terminal.go:Flags() - 60ns
[TRACE] 04:30:36.032 terminal.go:Flags() - 120ns
[TRACE] 04:30:36.032 terminal.go:GOOS() - 110ns
[TRACE] 04:30:36.032 terminal.go:PathSeparator() - 6.261µs
[TRACE] 04:30:36.032 terminal.go:GOOS() - 50ns
[DEBUG] 04:30:36.032 terminal.go:Pwd:189 → /tmp/oh-my-posh/src
[TRACE] 04:30:36.032 terminal.go:Pwd() - 46.988µs
[TRACE] 04:30:36.032 terminal.go:GOOS() - 60ns
[DEBUG] 04:30:36.032 segment.go:SetEnabled:115 → segment: Text
[TRACE] 04:30:36.032 terminal_unix.go:Root() - 761ns
[TRACE] 04:30:36.032 terminal.go:Shell() - 100ns
[TRACE] 04:30:36.032 terminal.go:StatusCodes() - 91ns
[DEBUG] 04:30:36.032 terminal_unix.go:IsWsl:35 → false
[TRACE] 04:30:36.032 terminal_unix.go:IsWsl() - 13.034µs
[DEBUG] 04:30:36.032 terminal.go:TemplateCache:673 → environment: [SHELL=/bin/bash SESSION_MANAGER=local/nettis-pc:@/tmp/.ICE-unix/1532,unix/nettis-pc:/tmp/.ICE-unix/1532 WINDOWID=109155556568784 COLORTERM=truecolor XDG_CONFIG_DIRS=/home/nettis/.config/kdedefaults:/etc/xdg KGLOBALACCELD_PLATFORM=org.kde.kwin XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0 HISTCONTROL= XDG_MENU_PREFIX=plasma- HISTSIZE=3000 ICEAUTHORITY=/run/user/1000/iceauth_RoUUSv LANGUAGE= SSH_AUTH_SOCK=/run/user/1000/gnupg/S.gpg-agent.ssh MEMORY_PRESSURE_WRITE=c29tZSAyMDAwMDAgMjAwMDAwMAA= DESKTOP_SESSION=plasma GTK_RC_FILES=/etc/gtk/gtkrc:/home/nettis/.gtkrc:/home/nettis/.config/gtkrc EDITOR=nvim XDG_SEAT=seat0 PWD=/tmp/oh-my-posh/src XDG_SESSION_DESKTOP=KDE LOGNAME=nettis XDG_SESSION_TYPE=wayland SYSTEMD_EXEC_PID=1348 XAUTHORITY=/run/user/1000/xauth_LQSDJP MOTD_SHOWN=pam XKB_DEFAULT_MODEL=pc104 GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/nettis/.gtkrc-2.0:/home/nettis/.config/gtkrc-2.0 HOME=/home/nettis SSH_ASKPASS=ksshaskpass LANG=fi_FI.UTF-8 XDG_CURRENT_DESKTOP=KDE POSH_SHELL_VERSION=5.2.37(2)-release POSH_SESSION_ID=a3cb8c0e-1c84-45f3-b945-3d3a0ac4640b MEMORY_PRESSURE_WATCH=/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/plasma-kwin_wayland.service/memory.pressure WAYLAND_DISPLAY=wayland-0 OSTYPE=linux-gnu CONDA_PROMPT_MODIFIER=false XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 INVOCATION_ID=cf9935b29b78488d8f2c6751384eb832 MANAGERPID=1238 QT_QPA_PLATFORM=wayland;xcb KDE_SESSION_UID=1000 ALACRITTY_SOCKET=/run/user/1000/Alacritty-wayland-0-1135776.sock XKB_DEFAULT_LAYOUT=fi XDG_SESSION_CLASS=user TERM=alacritty USER=nettis PLASMA_USE_QT_SCALING=1 QT_WAYLAND_RECONNECT=1 KDE_SESSION_VERSION=6 DISPLAY=:0 SHLVL=1 XDG_VTNR=1 KWIN_DRM_DISABLE_TRIPLE_BUFFERING=0 XDG_SESSION_ID=1 POSH_THEME=/tmp/oh-my-posh/theme.min.toml  XDG_RUNTIME_DIR=/run/user/1000 LC_TIME=fi_FI.UTF-8 XKB_DEFAULT_VARIANT=nodeadkeys QT_AUTO_SCREEN_SCALE_FACTOR=0 JOURNAL_STREAM=9:31097 XDG_DATA_DIRS=/home/nettis/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share KDE_FULL_SESSION=true PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/home/nettis/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin:/home/nettis/.cargo/bin:/home/nettis/.local/bin:/home/nettis/bin ALACRITTY_LOG=/tmp/Alacritty-1135776.log HISTFILESIZE=3000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus KDE_APPLICATIONS_AS_SCOPE=1 MAIL=/var/spool/mail/nettis POWERLINE_COMMAND=oh-my-posh ALACRITTY_WINDOW_ID=109155556568784 OLDPWD=/home/nettis _=./src]
[TRACE] 04:30:36.032 terminal.go:Pwd() - 161ns
[DEBUG] 04:30:36.032 terminal_unix.go:IsWsl:35 → false
[TRACE] 04:30:36.032 terminal_unix.go:IsWsl() - 5.43µs
[TRACE] 04:30:36.032 terminal.go:GOOS() - 81ns
[TRACE] 04:30:36.032 terminal.go:GOOS() - 60ns
[TRACE] 04:30:36.032 terminal.go:GOOS() - 50ns
[TRACE] 04:30:36.032 terminal.go:GOOS() - 61ns
[TRACE] 04:30:36.032 terminal.go:GOOS() - 60ns
[DEBUG] 04:30:36.032 terminal.go:User:330 → nettis
[TRACE] 04:30:36.032 terminal.go:User() - 5.05µs
[DEBUG] 04:30:36.032 terminal.go:Host:347 → nettis-pc
[TRACE] 04:30:36.033 terminal.go:Host() - 7.033µs
[TRACE] 04:30:36.033 terminal.go:GOOS() - 90ns
[DEBUG] 04:30:36.033 terminal_unix.go:Platform:92 → arch
[DEBUG] 04:30:36.033 terminal.go:Getenv:164 → 1
[TRACE] 04:30:36.033 terminal.go:Getenv(SHLVL) - 6.683µs
[TRACE] 04:30:36.033 terminal.go:TemplateCache() - 178.424µs
[DEBUG] 04:30:36.033 text.go:Render:80 → rendering template: This text should have a green background.
[TRACE] 04:30:36.033 terminal.go:Flags() - 100ns
[DEBUG] 04:30:36.033 text.go:Render:80 → rendering template: plain
[TRACE] 04:30:36.033 terminal.go:Flags() - 70ns
[TRACE] 04:30:36.033 terminal.go:Shell() - 131ns
[TRACE] 04:30:36.033 terminal.go:Shell() - 71ns
[TRACE] 04:30:36.033 terminal.go:Shell() - 80ns
[DEBUG] 04:30:36.033 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.033 terminal.go:Getenv(LOCALAPPDATA) - 5.51µs
[DEBUG] 04:30:36.033 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.033 terminal.go:Getenv(OMP_CACHE_DIR) - 3.947µs
[DEBUG] 04:30:36.033 terminal.go:Getenv:164 → NO DATA
[TRACE] 04:30:36.033 terminal.go:Getenv(XDG_CACHE_HOME) - 9.157µs
[TRACE] 04:30:36.033 terminal.go:CachePath() - 54.662µs
[TRACE] 04:30:36.033 terminal.go:Flags() - 70ns
@Nettifani Nettifani added the 🐛 bug Something isn't working label Oct 30, 2024
@JanDeDobbeleer
Copy link
Owner

@Nettifani will be fixed in the next release (if I can't find issues, that's tomorrow).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants