Change ansi color names to more saying names

#777 Merged at 4db9209
Repository
mortenlund
Branch
default
Repository
birkenfeld
Branch
default
Author
  1. Morten E. Lund
Reviewers
Description

Fixes #1463

This PR changes the ansi-color names to make them easier to understand and align with color names of other projects ( for example https://github.com/jonathanslenders/python-prompt-toolkit) and terminals. (e.g. from #ansifuchsia to ansibrightmagenta)

This also drops the # prefix to the color names. The hashtag is used to indicate hex colors in all other contexts and the names are already prefixed with ansi anyway. Furthermore, it allows the new and old set of names to be exclusive.

  • Issues #1463: ANSI color names not correct. new

Comments (17)

  1. jonathanslenders

    This looks good to me, great that it’s backwards compatible. Thanks @mortenlund for taking the time!

  2. Morten E. Lund author

    @birkenfeld I was a bit sad to see that this PR didn’t enter 2.3…

    Is there anything we can do to help it? It would be nice that pygments could follow prompt_toolkit on the ansi color naming.

  3. Anteru

    I’ll look into this. Please bear with me 🙂 The goal for the 2.3 release was to flush out the process, I’m preparing a 2.3.1 point release at the moment.

  4. Anteru

    Ok, so I just pushed 2.3.1 without this, mostly because it does change behavior and I had a dozen lexer fixes to push out. Merged now for 2.4, which should be due in early January. I hope that still works for you!

  5. Georg Brandl repo owner

    It seems that merging this has broken the test suite:

    ======================================================================
    ERROR: test_basic_api.test_formatter_public_api(<class 'pygments.formatters.terminal.TerminalFormatter'>,)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/site-packages/nose/case.py", line 197, in runTest
        self.test(*self.arg)
      File "/home/gbr/devel/pygments/tests/test_basic_api.py", line 174, in verify
        inst.format(ts, string_out)
      File "../pygments/formatters/terminal.py", line 101, in format
        return Formatter.format(self, tokensource, outfile)
      File "../pygments/formatter.py", line 95, in format
        return self.format_unencoded(tokensource, outfile)
      File "../pygments/formatters/terminal.py", line 126, in format_unencoded
        outfile.write(ansiformat(color, line.rstrip('\n')))
      File "../pygments/console.py", line 68, in ansiformat
        result.append(codes[attr])
    KeyError: 'darkblue'
    
    ======================================================================
    ERROR: test_basic_api.test_formatter_unicode_handling(<class 'pygments.formatters.terminal.TerminalFormatter'>,)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/site-packages/nose/case.py", line 197, in runTest
        self.test(*self.arg)
      File "/home/gbr/devel/pygments/tests/test_basic_api.py", line 217, in verify
        out = format(tokens, inst)
      File "../pygments/__init__.py", line 64, in format
        formatter.format(tokens, realoutfile)
      File "../pygments/formatters/terminal.py", line 101, in format
        return Formatter.format(self, tokensource, outfile)
      File "../pygments/formatter.py", line 95, in format
        return self.format_unencoded(tokensource, outfile)
      File "../pygments/formatters/terminal.py", line 126, in format_unencoded
        outfile.write(ansiformat(color, line.rstrip('\n')))
      File "../pygments/console.py", line 68, in ansiformat
        result.append(codes[attr])
    KeyError: 'darkblue'
    
    ======================================================================
    ERROR: test_reasonable_output (test_terminal_formatter.TerminalFormatterTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/gbr/devel/pygments/tests/test_terminal_formatter.py", line 43, in test_reasonable_output
        TerminalFormatter().format(DEMO_TOKENS, out)
      File "../pygments/formatters/terminal.py", line 101, in format
        return Formatter.format(self, tokensource, outfile)
      File "../pygments/formatter.py", line 95, in format
        return self.format_unencoded(tokensource, outfile)
      File "../pygments/formatters/terminal.py", line 126, in format_unencoded
        outfile.write(ansiformat(color, line.rstrip('\n')))
      File "../pygments/console.py", line 68, in ansiformat
        result.append(codes[attr])
    KeyError: 'lightgray'
    
    ======================================================================
    ERROR: test_reasonable_output_lineno (test_terminal_formatter.TerminalFormatterTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/gbr/devel/pygments/tests/test_terminal_formatter.py", line 53, in test_reasonable_output_lineno
        TerminalFormatter(linenos=True).format(DEMO_TOKENS, out)
      File "../pygments/formatters/terminal.py", line 101, in format
        return Formatter.format(self, tokensource, outfile)
      File "../pygments/formatter.py", line 95, in format
        return self.format_unencoded(tokensource, outfile)
      File "../pygments/formatters/terminal.py", line 126, in format_unencoded
        outfile.write(ansiformat(color, line.rstrip('\n')))
      File "../pygments/console.py", line 68, in ansiformat
        result.append(codes[attr])
    KeyError: 'lightgray'
    
    ======================================================================
    FAIL: test_stream_opt (test_cmdline.CmdLineTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/gbr/devel/pygments/tests/test_cmdline.py", line 140, in test_stream_opt
        o = self.check_success('-lpython', '-s', '-fterminal', stdin=TESTCODE)
      File "/home/gbr/devel/pygments/tests/test_cmdline.py", line 65, in check_success
        self.assertEqual(code, 0)
    AssertionError: 1 != 0
        '1 != 0' = '%s != %s' % (safe_repr(1), safe_repr(0))
        '1 != 0' = self._formatMessage('1 != 0', '1 != 0')
    >>  raise self.failureException('1 != 0')
    
    
    ----------------------------------------------------------------------
    Ran 2048 tests in 16.151s
    
    FAILED (SKIP=8, errors=4, failures=1)
    
  6. Morten E. Lund author

    @Georg Brandl Sorry about this. I am probably too used to automatic continuous testing. It looks like there are still a few color names in “terminal.py” that needs to be updated.

    I will look at this ASAP.

    1. Georg Brandl repo owner

      Don’t worry, we’re just heating up Pygments development again and I hope we’ll have proper automatic testing of pull requests at some point.

  7. Anteru

    I’ll port it manually, given I somehow managed to merge this and not notice right away it broke the test suite 😕 Sorry the for the inconvienience, and thanks for the fix!

  8. Morten E. Lund author

    BTW. I was originally thinking this would go into 2.3, so you may also want to change that to say “2.4” instead. This is needed in both “styles.rst” and in “terminal256.py”

    e.g.

    +
    +.. _NewAnsiColorNames:
    +
    +.. versionchanged:: 2.3
    +
    
  9. Jason Parham

    For those who find this thread and wish to have a mapping of all the 2.2 color names to new 2.4 color names, see below:

    pygments_color_name_mapping = {
        'darkred'    : 'red',
        'darkgreen'  : 'green',
        'brown'      : 'yellow',
        'darkblue'   : 'blue',
        'purple'     : 'magenta',
        'teal'       : 'cyan',
        'lightgray'  : 'gray',
        'darkgray'   : 'brightblack',
        'red'        : 'brightred',
        'green'      : 'brightgreen',
        'yellow'     : 'brightyellow',
        'blue'       : 'brightblue',
        'fuchsia'    : 'brightmagenta',
        'turquoise'  : 'brightcyan',
        'darkyellow' : 'yellow',
        'darkteal'   : 'brightcyan',
        'fuscia'     : 'brightmagenta',
    }