Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/prompt_toolkit/formatted_text/pygments.py: 60%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING 

4 

5from prompt_toolkit.styles.pygments import pygments_token_to_classname 

6 

7from .base import StyleAndTextTuples 

8 

9if TYPE_CHECKING: 

10 from pygments.token import Token 

11 

12__all__ = [ 

13 "PygmentsTokens", 

14] 

15 

16 

17class PygmentsTokens: 

18 """ 

19 Turn a pygments token list into a list of prompt_toolkit text fragments 

20 (``(style_str, text)`` tuples). 

21 """ 

22 

23 def __init__(self, token_list: list[tuple[Token, str]]) -> None: 

24 self.token_list = token_list 

25 

26 def __pt_formatted_text__(self) -> StyleAndTextTuples: 

27 result: StyleAndTextTuples = [] 

28 

29 for token, text in self.token_list: 

30 result.append(("class:" + pygments_token_to_classname(token), text)) 

31 

32 return result