Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/console.py: 58%

38 statements  

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

1""" 

2 pygments.console 

3 ~~~~~~~~~~~~~~~~ 

4 

5 Format colored console output. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11esc = "\x1b[" 

12 

13codes = {} 

14codes[""] = "" 

15codes["reset"] = esc + "39;49;00m" 

16 

17codes["bold"] = esc + "01m" 

18codes["faint"] = esc + "02m" 

19codes["standout"] = esc + "03m" 

20codes["underline"] = esc + "04m" 

21codes["blink"] = esc + "05m" 

22codes["overline"] = esc + "06m" 

23 

24dark_colors = ["black", "red", "green", "yellow", "blue", 

25 "magenta", "cyan", "gray"] 

26light_colors = ["brightblack", "brightred", "brightgreen", "brightyellow", "brightblue", 

27 "brightmagenta", "brightcyan", "white"] 

28 

29x = 30 

30for d, l in zip(dark_colors, light_colors): 

31 codes[d] = esc + "%im" % x 

32 codes[l] = esc + "%im" % (60 + x) 

33 x += 1 

34 

35del d, l, x 

36 

37codes["white"] = codes["bold"] 

38 

39 

40def reset_color(): 

41 return codes["reset"] 

42 

43 

44def colorize(color_key, text): 

45 return codes[color_key] + text + codes["reset"] 

46 

47 

48def ansiformat(attr, text): 

49 """ 

50 Format ``text`` with a color and/or some attributes:: 

51 

52 color normal color 

53 *color* bold color 

54 _color_ underlined color 

55 +color+ blinking color 

56 """ 

57 result = [] 

58 if attr[:1] == attr[-1:] == '+': 

59 result.append(codes['blink']) 

60 attr = attr[1:-1] 

61 if attr[:1] == attr[-1:] == '*': 

62 result.append(codes['bold']) 

63 attr = attr[1:-1] 

64 if attr[:1] == attr[-1:] == '_': 

65 result.append(codes['underline']) 

66 attr = attr[1:-1] 

67 result.append(codes[attr]) 

68 result.append(text) 

69 result.append(codes['reset']) 

70 return ''.join(result)