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

15 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 06:09 +0000

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