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

MAGEFILE_ENABLE_COLOR breaks mage-select #4

Closed
sheldonhull opened this issue Feb 28, 2022 · 7 comments
Closed

MAGEFILE_ENABLE_COLOR breaks mage-select #4

sheldonhull opened this issue Feb 28, 2022 · 7 comments

Comments

@sheldonhull
Copy link
Collaborator

I know there's not a lot of activity on this, but want to capture this issue as it caused me to stop using it for a while.

If MAGEFILE_ENABLE_COLOR=1 mage-select is used, when the command is passed through it incorrectly escapes and won't work. When color is disabled it works fine.

2022-02-28-12 42 41-Code - Insiders-Pulumi dev yaml — ras  Dev Container Kubernetes - Minikube-in-Docker

2022-02-28-12 43 02-Code - Insiders-Pulumi dev yaml — ras  Dev Container Kubernetes - Minikube-in-Docker

The end target for something like mage go:doctor ends up being "\x1b[36mgo:doctor\x1b[0m".

@sheldonhull
Copy link
Collaborator Author

The current solution in my shell is to simply create a function to use instead like this:

if command -v mage &>/dev/null; then
  # Color breaks this tool, so disable for execution
  unalias mages  # Just in case this is already registered, make sure to unregister it
  function mages() { MAGEFILE_ENABLE_COLOR=0 mage-select }
  echo -e "➕ alias: mages";
fi

@iwittkau
Copy link
Owner

Thank you for reporting this. You're right, it's quiet here because I'm currently not using mage.

But I think this is quite easy to fix. I have to reproduce this first ... hope to get back to you soon 🤞🏻

@iwittkau
Copy link
Owner

Should be fixed in https://github.com/iwittkau/mage-select/releases/tag/v1.1.0

Happy maging 🧙‍♀️

If you still encounter problems, please re-open.

@sheldonhull
Copy link
Collaborator Author

My hero!

@sheldonhull
Copy link
Collaborator Author

Would love to hear what you are using if not mage now, back to bash scripts? I don't know if I could do that since I love Go so much ;-) Feel free to ping me on twitter for off-topic discussion if you like. It's linked on my profile page. cheers!

sheldonhull added a commit that referenced this issue Sep 30, 2022
- fixes #4 as promptui still was picking up the incorrect color escape sequences before attempting to pass to mage invocation
@mloskot
Copy link

mloskot commented Dec 11, 2023

@iwittkau Thanks for the fix!

Since the fix f1a5309 resets MAGEFILE_ENABLE_COLOR=0 instead of, perhaps, stripping colouring codes, mage-select may still fail for those who force MAGEFILE_ENABLE_COLOR=1 in init function of their Magefiles.

Here is example how to correct the init function to make your Magefiles well-behaving for mage-select:

func init() {
	var err error

	// Reset coloring only if not already enabled/disabled e.g. by mage-select
	disableColor := strings.TrimSpace(os.Getenv("MAGEFILE_ENABLE_COLOR"))
	if disableColor == "" {
		err = os.Setenv("MAGEFILE_ENABLE_COLOR", "1")
		if err != nil {
			panic(err)
		}
	}
...
}

@sheldonhull

Would love to hear what you are using if not mage now, back to bash scripts? I don't know if I could do that since I love Go so much ;-)

I'd love to hear that too, for the same reasons. I have been using Mage as a general-purpose replacement for Bash scripting and I can't imagine myself going back to Bash. Sad to read @sheldonhull 's magefile/mage#289 (comment)

@sheldonhull
Copy link
Collaborator Author

Still using. It's stable and well featured so best option right now for me in Go. That said I hope to see maintenance pick back up someday.
No reason not to use it!

I don't have any issues with color right now with the current fixes in place.

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