Skip to content

Commit

Permalink
fix(sanitychecks): Patch display issues depending on terminal using c…
Browse files Browse the repository at this point in the history
…urses
  • Loading branch information
lperdereau authored and lcaflc committed Dec 12, 2024
1 parent b83e6e7 commit b8d1b04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/pvecontrol/sanitycheck/checks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from abc import ABC, abstractmethod
from curses import has_colors as terminal_support_colors
from enum import Enum

from pvecontrol.utils import fonts, teminal_support_utf_8
from pvecontrol.utils import fonts, teminal_support_utf_8, terminal_support_colors

class CheckType(Enum):
HA = 'HIGH_AVAILABILITY'
Expand Down
19 changes: 18 additions & 1 deletion src/pvecontrol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
import sys
import re
import subprocess
import curses

from prettytable import PrettyTable
from collections import OrderedDict
Expand All @@ -18,6 +18,23 @@ class fonts:
UNDERLINE = '\033[4m'
END = '\033[0m'

def terminal_support_colors():
try:
_stdscr = curses.initscr()
curses.start_color()
if curses.has_colors():
_num_colors = curses.color_pair(1)
if curses.COLORS > 0:
return True
else:
return False
else:
return False
except Exception as e:
return False
finally:
curses.endwin()

def teminal_support_utf_8():
return sys.stdout.encoding.lower() == 'utf-8'

Expand Down

0 comments on commit b8d1b04

Please sign in to comment.