lookatme.widgets.codeblock module

This module defines an urwid Widget that renders a codeblock

class lookatme.widgets.codeblock.CodeBlock(source: str, lang: str = 'text', style_name: str = 'monokai', line_numbers: bool = False, start_line_number: int = 1, hl_lines: Optional[List[range]] = None, default_fg: Optional[str] = None, bg_override: Optional[str] = None)[source]

Bases: urwid.container.Pile

class lookatme.widgets.codeblock.StyleCache(default_fg: Optional[str] = None, bg_override: Optional[str] = None)[source]

Bases: object

Caches the highlight styles for loaded pygments syntax highlighting styles.

get_style(style_name: str) → lookatme.widgets.codeblock.SyntaxHlStyle[source]

Return the highlight style for the specified pygments style name. If the style name isn’t found, the “text” style will be used instead.

is_valid_style(style_name: str) → bool[source]

Return whether the style name is a valid pygments style

load_style(style_name: str) → lookatme.widgets.codeblock.SyntaxHlStyle[source]
class lookatme.widgets.codeblock.SyntaxHlStyle(name: str, styles: Dict[str, lookatme.widgets.smart_attr_spec.SmartAttrSpec], pygments_style: pygments.style.StyleMeta, default_fg: str, bg_override: Optional[str] = None)[source]

Bases: object

Stores urwid styles for each token type for a specific pygments syntax highlighting style.

get_line_number_spec(do_hl: bool = False) → lookatme.widgets.smart_attr_spec.SmartAttrSpec[source]
get_style_spec(token_type: str, highlight: bool) → lookatme.widgets.smart_attr_spec.SmartAttrSpec[source]

Attempt to find the closest matching style for the provided token type.

lookatme.widgets.codeblock.clear_cache()[source]
lookatme.widgets.codeblock.get_lexer(lang, default='text') → pygments.lexer.Lexer[source]
lookatme.widgets.codeblock.get_style_cache(default_fg: Optional[str] = None, bg_override: Optional[str] = None) → lookatme.widgets.codeblock.StyleCache[source]
lookatme.widgets.codeblock.guess_lang(content: str) → str[source]
lookatme.widgets.codeblock.supported_langs() → Set[str][source]
lookatme.widgets.codeblock.supported_styles() → Mapping[str, str][source]
lookatme.widgets.codeblock.tokens_to_lines(tokens) → List[List[Tuple[str, str]]][source]
lookatme.widgets.codeblock.tokens_to_markup(line: List[Tuple[str, str]], style: lookatme.widgets.codeblock.SyntaxHlStyle, do_hl: bool = False) → List[Tuple[lookatme.widgets.smart_attr_spec.SmartAttrSpec, str]][source]