Beispiel #1
0
def test():
    """
    Verify we can build escape sequences correctly
    """
    # get the modules
    from journal.CSI import CSI
    from journal.ASCII import ASCII

    # get the escape character
    esc = ASCII.ESC

    # verify the escape sequence generation routines build the correct strings
    assert CSI.reset() == f"{esc}[0m"
    assert CSI.csi3(code=35) == f"{esc}[0;35m"
    assert CSI.csi8(red=4, green=2, blue=3) == f"{esc}[38;5;175m"
    assert CSI.csi8_gray(gray=16) == f"{esc}[38;5;248m"
    assert CSI.csi24(red=0xff, green=0xbf,
                     blue=0x00) == f"{esc}[38;2;255;191;0m"

    # all done
    return
Beispiel #2
0
def test():
    """
    Check a few of the canonical ANSI color names
    """
    # access the color map
    from journal.ANSI import ANSI
    # and the control sequence generator
    from journal.CSI import CSI

    # verify the contents of the {ansi} color table
    # the reset sequence
    assert ANSI.ansi("normal") == CSI.reset()

    # regular colors
    assert ANSI.ansi("black") == CSI.csi3(code=30)
    assert ANSI.ansi("red") == CSI.csi3(code=31)
    assert ANSI.ansi("green") == CSI.csi3(code=32)
    assert ANSI.ansi("brown") == CSI.csi3(code=33)
    assert ANSI.ansi("blue") == CSI.csi3(code=34)
    assert ANSI.ansi("purple") == CSI.csi3(code=35)
    assert ANSI.ansi("cyan") == CSI.csi3(code=36)
    assert ANSI.ansi("light-gray") == CSI.csi3(code=37)

    # bright colors
    assert ANSI.ansi("dark-gray") == CSI.csi3(code=30, bright=True)
    assert ANSI.ansi("light-red") == CSI.csi3(code=31, bright=True)
    assert ANSI.ansi("light-green") == CSI.csi3(code=32, bright=True)
    assert ANSI.ansi("yellow") == CSI.csi3(code=33, bright=True)
    assert ANSI.ansi("light-blue") == CSI.csi3(code=34, bright=True)
    assert ANSI.ansi("light-purple") == CSI.csi3(code=35, bright=True)
    assert ANSI.ansi("light-cyan") == CSI.csi3(code=36, bright=True)
    assert ANSI.ansi("white") == CSI.csi3(code=37, bright=True)

    # all done
    return