{"action":"created","issue":{"url":"https://api.github.com/repos/scopatz/xonsh/issues/687","repository_url":"https://api.github.com/repos/scopatz/xonsh","labels_url":"https://api.github.com/repos/scopatz/xonsh/issues/687/labels{/name}","comments_url":"https://api.github.com/repos/scopatz/xonsh/issues/687/comments","events_url":"https://api.github.com/repos/scopatz/xonsh/issues/687/events","html_url":"https://github.com/scopatz/xonsh/pull/687","id":134494259,"number":687,"title":"Color Refactor","user":{"login":"scopatz","id":320553,"avatar_url":"https://avatars.githubusercontent.com/u/320553?v=3","gravatar_id":"","url":"https://api.github.com/users/scopatz","html_url":"https://github.com/scopatz","followers_url":"https://api.github.com/users/scopatz/followers","following_url":"https://api.github.com/users/scopatz/following{/other_user}","gists_url":"https://api.github.com/users/scopatz/gists{/gist_id}","starred_url":"https://api.github.com/users/scopatz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scopatz/subscriptions","organizations_url":"https://api.github.com/users/scopatz/orgs","repos_url":"https://api.github.com/users/scopatz/repos","events_url":"https://api.github.com/users/scopatz/events{/privacy}","received_events_url":"https://api.github.com/users/scopatz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/scopatz/xonsh/labels/feature","name":"feature","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/scopatz/xonsh/milestones/2","html_url":"https://github.com/scopatz/xonsh/milestones/v0.3","labels_url":"https://api.github.com/repos/scopatz/xonsh/milestones/2/labels","id":1302567,"number":2,"title":"v0.3","description":"","creator":{"login":"scopatz","id":320553,"avatar_url":"https://avatars.githubusercontent.com/u/320553?v=3","gravatar_id":"","url":"https://api.github.com/users/scopatz","html_url":"https://github.com/scopatz","followers_url":"https://api.github.com/users/scopatz/followers","following_url":"https://api.github.com/users/scopatz/following{/other_user}","gists_url":"https://api.github.com/users/scopatz/gists{/gist_id}","starred_url":"https://api.github.com/users/scopatz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scopatz/subscriptions","organizations_url":"https://api.github.com/users/scopatz/orgs","repos_url":"https://api.github.com/users/scopatz/repos","events_url":"https://api.github.com/users/scopatz/events{/privacy}","received_events_url":"https://api.github.com/users/scopatz/received_events","type":"User","site_admin":false},"open_issues":94,"closed_issues":226,"state":"open","created_at":"2015-09-12T18:28:59Z","updated_at":"2016-02-18T06:52:46Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-02-18T06:37:14Z","updated_at":"2016-02-18T08:51:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/scopatz/xonsh/pulls/687","html_url":"https://github.com/scopatz/xonsh/pull/687","diff_url":"https://github.com/scopatz/xonsh/pull/687.diff","patch_url":"https://github.com/scopatz/xonsh/pull/687.patch"},"body":"First off, I apologize for putting in another giant PR right after the parser refactors. However, like ths parser refactor, this one is totally worth it. At least with this one, most of it has been autogenerated :)\r\n\r\nThis fundamentally changes how colors are handled though out xonsh. Currently, for historical reasons, colors are all handled via ANSI color codes that were wrapped in hidden escape sequences `\\001` and `\\002`. The *only* thing that this is convenient for was readline prompts. It a pain for everything else because:\r\n\r\n* In the readline shell, you have to strip the `\\001` and `\\002` off the sides of all color codes when printing colors that are not in a prompt, such as with the history differ, tracer, and the xonfig wizard.\r\n* A genius, if mechanical, system of regexes had evolved to convert a subset of ANSI color codes to a  list of Pygment `(Token, str)` tuples as used by prompt-toolkit.This led to an excessive number of string transformations.\r\n\r\nThis PR changes all of that by making each Shell class responsible for printing and formatting colors in the way that is most natural to that shell.  This provides some more primitive tools to help reduce that burden. \r\n\r\nThis abstraction enables a lot of cool features.  The primary one of which is the ability to dynamically set a color map or style.  This is done through the `$XONSH_COLOR_STYLE`, which simply takes a string style name.  Currently supported string names are those that were present in pygments on my machine. Note that these styles are implemented for ANSI colors even when pygments is not installed! \r\n\r\nThese styles had to be autogenerated, which was done via some code that you can find here: https://github.com/scopatz/xolors  I am not convinced that my algorithm there produces the most representative colors for a given style and palette.  However, hopefully this can evolve in time, or someone can come up with something better.\r\n\r\nAdditionally, because it is easy implement colors, I added coloring back to the `?` and `??` operator output. I even extended this to optionally include syntax highlighting for the source code in ``??``\r\n\r\nFurthermore, I had been eyeing the print displayhook for color for some time.  So now, if pygments is installed, the output of Python mode objects will also be syntax highlighted, in addition to being pretty printed.\r\n\r\nThis, of course, has a cost.  While this won't break people's xonshrc files (I don't believe), it does render prior coloring and style handling basically moot.\r\n\r\nI think that this needs to be hammered on.  I also think that along with the and/or subproc operators this makes a nice candidate for v0.3.0. The minor version bump will help imply that something serious is going on :)\r\n\r\nIn any event, I am looking forward to hearing folks thoughts!"},"comment":{"url":"https://api.github.com/repos/scopatz/xonsh/issues/comments/185604450","html_url":"https://github.com/scopatz/xonsh/pull/687#issuecomment-185604450","issue_url":"https://api.github.com/repos/scopatz/xonsh/issues/687","id":185604450,"user":{"login":"BYK","id":126780,"avatar_url":"https://avatars.githubusercontent.com/u/126780?v=3","gravatar_id":"","url":"https://api.github.com/users/BYK","html_url":"https://github.com/BYK","followers_url":"https://api.github.com/users/BYK/followers","following_url":"https://api.github.com/users/BYK/following{/other_user}","gists_url":"https://api.github.com/users/BYK/gists{/gist_id}","starred_url":"https://api.github.com/users/BYK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BYK/subscriptions","organizations_url":"https://api.github.com/users/BYK/orgs","repos_url":"https://api.github.com/users/BYK/repos","events_url":"https://api.github.com/users/BYK/events{/privacy}","received_events_url":"https://api.github.com/users/BYK/received_events","type":"User","site_admin":false},"created_at":"2016-02-18T08:51:04Z","updated_at":"2016-02-18T08:51:04Z","body":"So basically, this diff piggy backs on the terminal emulator to display ANSI codes, which is what was happening at the end anyways when we converted color codes to ANSI escape sequences and then them to Pygments tokens and then back to ANSI escape sequences, right?\r\n\r\nI think this is a great way forward. The \"crazy\" idea I had for colors was, with prompt-toolkit, since we had tokenization, was to tokenize the actual prompt parts like `user`, `cwd`, `branch_name` etc so people can color/style them way easier. What do you think?"}}