MCPcopy Index your code
hub / github.com/python/mypy / initialize_unix_colors

Method initialize_unix_colors

mypy/util.py:683–719  ·  view source on GitHub ↗

Return True if initialization was successful and we can use colors, False otherwise

(self)

Source from the content-addressed store, hash-verified

681 assert False, "Running not on Windows"
682
683 def initialize_unix_colors(self) -> bool:
684 """Return True if initialization was successful and we can use colors, False otherwise"""
685 is_win = sys.platform == "win32"
686 if is_win or not CURSES_ENABLED:
687 return False
688 try:
689 # setupterm wants a fd to potentially write an "initialization sequence".
690 # We override sys.stdout for the daemon API so if stdout doesn't have an fd,
691 # just give it /dev/null.
692 try:
693 fd = sys.stdout.fileno()
694 except io.UnsupportedOperation:
695 with open("/dev/null", "rb") as f:
696 curses.setupterm(fd=f.fileno())
697 else:
698 curses.setupterm(fd=fd)
699 except curses.error:
700 # Most likely terminfo not found.
701 return False
702 bold = curses.tigetstr("bold")
703 under = curses.tigetstr("smul")
704 set_color = curses.tigetstr("setaf")
705 set_eseq = curses.tigetstr("cup")
706 normal = curses.tigetstr("sgr0")
707
708 if not (bold and under and set_color and set_eseq and normal):
709 return False
710
711 self.NORMAL = normal.decode()
712 self.BOLD = bold.decode()
713 self.UNDER = under.decode()
714 self.DIM = parse_gray_color(set_eseq)
715 self.BLUE = curses.tparm(set_color, curses.COLOR_BLUE).decode()
716 self.GREEN = curses.tparm(set_color, curses.COLOR_GREEN).decode()
717 self.RED = curses.tparm(set_color, curses.COLOR_RED).decode()
718 self.YELLOW = curses.tparm(set_color, curses.COLOR_YELLOW).decode()
719 return True
720
721 def style(
722 self,

Callers 1

__init__Method · 0.95

Calls 3

parse_gray_colorFunction · 0.85
filenoMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected