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

colored error messages for "larch -r -c" #65

Open
bruceravel opened this issue Nov 24, 2013 · 6 comments
Open

colored error messages for "larch -r -c" #65

bruceravel opened this issue Nov 24, 2013 · 6 comments

Comments

@bruceravel
Copy link
Contributor

I am leaving an issue rather than making a pull request because I am pretty sure the hack I made is not the best way to implement what I am looking for. It is very handy that the larch server can be made to echo with the -c flag. However, finding the error among a mountain of text is rather difficult. So I modified lib/larchlib.py in two ways. First, at the top, I did

  from termcolor import colored

then, as the return for get_error, I did

  return (exc_name, colored('\n'.join(out), 'red'))

Very helpful for troubleshooting Athena!

I have no idea whether that'll work on Windows. And you may want to use a command line flag or some other configuration to turn the coloring on and off. Also, it seems that termcolor is not part of a standard python installation, so it would have to be a recommended dependency. In short, I'm just not sure the best way to implement this.

It may be a more broadly useful dependency, though. Some color in the REPL may be quite nice.

I should say that I used termcolor because it was the first suggestion in an article on Stack Overflow

@newville
Copy link
Member

I'm completely willing to add that as a "use if available" option, and add termcolor as a recommended option.
Will work on it.

@maurov
Copy link
Member

maurov commented Nov 25, 2013

For a simple string color print without any dependence, here my two cents:

https://github.com/maurov/larch_plugins/blob/master/std/cprint.py

I simply translated in Python what we do here at ESRF under SPEC. Maybe it is not elegant, but it works under Linux, no idea under Windows.

@newville
Copy link
Member

Hi Mauro, Bruce,

On Mon, Nov 25, 2013 at 2:20 AM, Mauro Rovezzi notifications@github.comwrote:

For a simple string color print without any dependence, here my two cents:

https://github.com/maurov/larch_plugins/blob/master/std/cprint.py

I simply translated in Python what we do here at ESRF under SPEC. Maybe it
is not elegant, but it works under Linux, no idea under Windows.

Thanks. I think termcolor does (mostly?) the same sort of thing, inserting
the same kind of color-codes. Do you know how they differ.... I'm open to
either approach.

The termcolor module does not work with a plain MS Windows shell (cmd.exe),
or even with Powershell (which can colorize text, but I have no idea how).
It may work with cygwin.

Anyway, getting this to work on Windows would be a bit of work, but that
doesn't mean it shouldn't be a "use if available" option. I added
user-level options, so that one can set
_sys.errortext_color ('red', 'grey', 'green', 'yellow', 'blue',
'magenta', 'cyan')
_sys.errortext_bold True/False
_sys.errortext_dark True/False
_sys.errortext_underline True/False
_sys.errortext_blink True/False
_sys.errortext_reverse True/False

at any time to alter the results. it seems that not all of these options
actually work for all terminals/systems.

@bruceravel
Copy link
Contributor Author

This claims to work on Windows:

https://pypi.python.org/pypi/colorama

@bruceravel
Copy link
Contributor Author

Matt, thanks for implementing this so quickly. I really wish I had thought to ask for this ages ago. So much easier to debug Athena!

@newville
Copy link
Member

Hmm, I just downloaded and tried this and it totally put Python in an
infinite loop, needing to be killed from TaskManager.... I haven't
investigated further, but this looks to be not ready for prime time.

Those of us who sometimes develop on Windows are doomed. I myself often
have a linux shell opened to the windows folder I'm testing in. But
having all the devel tools for Windows is better. Then again, using a
better shell would be helpful too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants