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

Error_symbol does not work correctly #3485

Closed
mylo17 opened this issue Jan 21, 2022 · 3 comments · Fixed by #3584
Closed

Error_symbol does not work correctly #3485

mylo17 opened this issue Jan 21, 2022 · 3 comments · Fixed by #3584
Labels
🐛 bug Something isn't working as expected.

Comments

@mylo17
Copy link

mylo17 commented Jan 21, 2022

Bug Report

Current Behavior

After the previous command fals Error_symbol does not change color as per the config file

Expected Behavior

error_symbol should turn red when the previous command fails

Additional context/Screenshots

Further evidence

Possible Solution

Environment

  • Starship version: 1.2.1
  • Shell type: Powershell
  • Shell version: 7.2.0
  • Shell plugin manager: [if present, e.g. oh-my-fish, oh-my-zsh, fisher, antigen]
  • Terminal emulator:Windows Terminal Preview
  • Operating system: Windows 10

Relevant Shell Configuration

Invoke-Expression (&starship init powershell)


# enable completion in current shell, use absolute path because PowerShell Core not respect $env:PSModulePath
Import-Module "$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\scoop-completion"

$ENV:EDITOR = "code"
$ENV:VISUAL = "code"

Import-Module -Name Terminal-Icons
Import-Module z
##Alises
Set-Alias ll Get-ChildItem
Set-Alias touch New-Item
Set-Alias g git
Set-Alias .. cd..
Set-Alias grep findstr
Set-Alias s scoop



function ... {Set-Location ..\..}
function .... {Set-Location ..\..\..}
#function scup {scoop update *}
#function sin {scoop install $args}
#function sser {scoop search $args} 

function which ($command) {
    Get-Command -Name $command -ErrorAction SilentlyContinue |
      Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
  }
  



$env:PYTHONIOENCODING="utf-8"

Invoke-Expression "$(thefuck --alias)"

# Shows navigable menu of all options when hitting Tab
#Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineOption -PredictionSource History
#Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows

Starship Configuration

[time]
disabled = true
style = "213"
format = "[🕙 $time]($style) "


[character]                            # The name of the module we are configuring is "character"

format = "[ ](bold green)"
error_symbol = "[ ](bold red)"


[perl]
version_format = "v${raw}"
symbol = "🐪 "
format ="via [$symbol($version )]($style)"

[java]
version_format = "v${raw}"

[golang]
format = "via [$symbol($version )]($style)"
version_format = "v${raw}"


[cmd_duration]
disabled = false
format = "took [$duration]($style)"

[directory]
truncation_symbol = "…/"
read_only_style = "red"
truncation_length = 5
format = "[$path]($style)[$lock_symbol]($lock_style) "
truncate_to_repo = false # truncates directory to root folder if in github repo
style = " #00BFFF"
disabled = false

[git_metrics]
added_style = "bold green"
deleted_style = ["bold red"]
format = '[+$added]($added_style)/[-$deleted]($deleted_style) '
disabled = true

[git_branch]
format = "on [$symbol$branch ]($style)"
symbol = ""
style = " #DF0FE6"
#symbol = "🌱 "


[git_commit]
commit_hash_length = 8
style = "bold white"


[git_status]
format ='([\[$all_status$ahead_behind\] ]($style))'
conflicted = "⚔️ "
ahead = "🏎️💨×${count}"
behind = "🐢 ×${count}"
diverged = "🔱 🏎️ 💨 ×${ahead_count} 🐢 ×${behind_count}"
untracked = "🛤️×${count}"
stashed = "📦 "
modified = "📝×${count}"
staged = "🗃️×${count}"
renamed = "📛×${count}"
deleted = "🗑️×${count}"
disabled = true




[memory_usage]
format = "$symbol[${ram}( | ${swap})]($style) "
threshold = 75
style = "bold dimmed white"
disabled = false

[package]
format ="using [$symbol$version]($style) "
disabled = false

[directory.substitutions]
"~/Coding" = "🚧"
"~/Documents" = "📄"
"~" = "🏠"
disabled = true
@mylo17 mylo17 added the 🐛 bug Something isn't working as expected. label Jan 21, 2022
@chipbuster
Copy link
Contributor

Your error color is different in the screenshot you showed, it's just not red. From examining the GIF, I find that success is #54d995 while error is #56a5a4.

What color scheme are you using for Windows Terminal?

@mylo17
Copy link
Author

mylo17 commented Jan 22, 2022

i know it looks weird in the gif, i don't know why but i can assure you it does not change colour, i am using the dracula scheme.
This is using the homebrew scheme.

@Shan-Zhou
Copy link
Contributor

Shan-Zhou commented Feb 8, 2022

First I found a temporary workaround (see below for a permanent one): run any commands that explicitly return nonzero error code (e.g. cmd /c "exit -1" or just directly set it to be any nonzero value, like "$LASTCODE = 123123") when you notice the error_symbol fails to work. After that my PowerShell could produce error symbol correctly. It's only temporary because after running anything that set $LASTEXITCODE = 0 (e.g. quit from vim) you need to re-do the above process.

The behavior is kind of weird, so I checked the output of "starship init powershell --print-full-init" and it seems that starship uses a prompt function that tries to utilize $LASTEXITCODE when the last command didn't succeed and was an internal PowerShell command. However instead of $global:error[0] it checks $error[0].

It's easy to fix: modify Line 96 of src/init/starship.ps1, add "global:" before "error[0]", then rebuild and install starship (it's a hard-coded variable).

Shan-Zhou added a commit to Shan-Zhou/starship that referenced this issue Feb 8, 2022
The current version use $error[0], which is for the module instead of the global status and is always $null, so the $lastExitCodeForPrompot is always $origLastExitCode (see starship#3485 for a related bug).
It should be replaced with $global:error[0] 
Comments are also updated
davidkna pushed a commit that referenced this issue Feb 11, 2022
…3584)

* Use global:error[0] for most recent error

The current version use $error[0], which is for the module instead of the global status and is always $null, so the $lastExitCodeForPrompot is always $origLastExitCode (see #3485 for a related bug).
It should be replaced with $global:error[0] 
Comments are also updated

* fix(pwsh): make Semantic PR bot happy
Perniciosius pushed a commit to Perniciosius/starship that referenced this issue Feb 21, 2022
…tarship#3584)

* Use global:error[0] for most recent error

The current version use $error[0], which is for the module instead of the global status and is always $null, so the $lastExitCodeForPrompot is always $origLastExitCode (see starship#3485 for a related bug).
It should be replaced with $global:error[0] 
Comments are also updated

* fix(pwsh): make Semantic PR bot happy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working as expected.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants