Exemplo n.º 1
0
 def from_screen(
     cls,
     stdscr: 'curses._CursesWindow',
     color_manager: ColorManager,
 ) -> 'Syntax':
     grammars = Grammars(prefix_data('grammar_v1'), xdg_data('grammar_v1'))
     theme = Theme.from_filename(xdg_config('theme.json'))
     ret = cls(grammars, theme, color_manager)
     ret._init_screen(stdscr)
     return ret
Exemplo n.º 2
0
def test_theme_default_settings_from_no_scope():
    theme = Theme.from_dct({
        'tokenColors': [
            {
                'settings': {
                    'foreground': '#cccccc',
                    'background': '#333333'
                }
            },
        ],
    })
    assert theme.default.fg == Color.parse('#cccccc')
    assert theme.default.bg == Color.parse('#333333')
Exemplo n.º 3
0
def _highlight_output(theme: Theme, compiler: Compiler, filename: str) -> int:
    state = compiler.root_state

    if theme.default.bg is not None:
        print('\x1b[48;2;{r};{g};{b}m'.format(**theme.default.bg._asdict()))
    with open(filename, encoding='UTF-8') as f:
        for line_idx, line in enumerate(f):
            first_line = line_idx == 0
            state, regions = highlight_line(compiler, state, line, first_line)
            for start, end, scope in regions:
                print_styled(line[start:end], theme.select(scope))
    print('\x1b[m', end='')
    return 0
Exemplo n.º 4
0
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument('--theme', default=xdg_config('theme.json'))
    parser.add_argument('--grammar-dir', default=prefix_data('grammar_v1'))
    parser.add_argument('filename')
    args = parser.parse_args(argv)

    with open(args.filename, encoding='UTF-8') as f:
        first_line = next(f, '')

    theme = Theme.from_filename(args.theme)

    grammars = Grammars(args.grammar_dir)
    compiler = grammars.compiler_for_file(args.filename, first_line)

    return _highlight_output(theme, compiler, args.filename)
Exemplo n.º 5
0
def test_theme_scope_comma_at_beginning_and_end():
    theme = Theme.from_dct({
        'colors': {
            'foreground': '#cccccc',
            'background': '#333333'
        },
        'tokenColors': [
            {
                'scope': '\n,a,b,\n',
                'settings': {
                    'fontStyle': 'italic'
                }
            },
        ],
    })
    assert theme.select(('d', )).i is False
    assert theme.select(('a', )).i is True
    assert theme.select(('b', )).i is True
Exemplo n.º 6
0
def test_theme_scope_split_by_commas():
    theme = Theme.from_dct({
        'colors': {
            'foreground': '#cccccc',
            'background': '#333333'
        },
        'tokenColors': [
            {
                'scope': 'a, b, c',
                'settings': {
                    'fontStyle': 'italic'
                }
            },
        ],
    })
    assert theme.select(('d', )).i is False
    assert theme.select(('a', )).i is True
    assert theme.select(('b', )).i is True
    assert theme.select(('c', )).i is True
Exemplo n.º 7
0
def test_theme_scope_as_A_list():
    theme = Theme.from_dct({
        'colors': {
            'foreground': '#cccccc',
            'background': '#333333'
        },
        'tokenColors': [
            {
                'scope': ['a', 'b', 'c'],
                'settings': {
                    'fontStyle': 'underline'
                }
            },
        ],
    })
    assert theme.select(('d', )).u is False
    assert theme.select(('a', )).u is True
    assert theme.select(('b', )).u is True
    assert theme.select(('c', )).u is True
Exemplo n.º 8
0
def test_theme_scope_internal_newline_commas():
    # this is arguably malformed, but `cobalt2` in the wild has this issue
    theme = Theme.from_dct({
        'colors': {
            'foreground': '#cccccc',
            'background': '#333333'
        },
        'tokenColors': [
            {
                'scope': '\n,a,\n,b,\n',
                'settings': {
                    'fontStyle': 'italic'
                }
            },
        ],
    })
    assert theme.select(('d', )).i is False
    assert theme.select(('a', )).i is True
    assert theme.select(('b', )).i is True
Exemplo n.º 9
0
from babi.color import Color
from babi.theme import Theme

THEME = Theme.from_dct({
    'colors': {
        'foreground': '#100000',
        'background': '#aaaaaa'
    },
    'tokenColors': [
        {
            'scope': 'foo.bar',
            'settings': {
                'foreground': '#200000'
            }
        },
        {
            'scope': 'foo',
            'settings': {
                'foreground': '#300000'
            }
        },
        {
            'scope': 'parent foo.bar',
            'settings': {
                'foreground': '#400000'
            }
        },
    ],
})


def unhex(color):