/usr/lib/python3/dist-packages/glances/outputs/glances_colorconsole.py is in glances 2.7.1.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | # -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2015 Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import threading
import time
import msvcrt
from glances.compat import queue
from glances.logger import logger
try:
import colorconsole
import colorconsole.terminal
except ImportError:
logger.critical("Colorconsole module not found. Glances cannot start in standalone mode.")
sys.exit(1)
class ListenGetch(threading.Thread):
def __init__(self, nom=''):
super(ListenGetch, self).__init__()
self.Terminated = False
self.q = queue.Queue()
def run(self):
while not self.Terminated:
char = msvcrt.getch()
self.q.put(char)
def stop(self):
self.Terminated = True
while not self.q.empty():
self.q.get()
def get(self, default=None):
try:
return ord(self.q.get_nowait())
except Exception:
return default
class Screen(object):
COLOR_DEFAULT_WIN = '0F' # 07'#'0F'
COLOR_BK_DEFAULT = colorconsole.terminal.colors["BLACK"]
COLOR_FG_DEFAULT = colorconsole.terminal.colors["WHITE"]
def __init__(self, nc):
self.nc = nc
self.term = colorconsole.terminal.get_terminal()
# os.system('color %s' % self.COLOR_DEFAULT_WIN)
self.listen = ListenGetch()
self.listen.start()
self.term.clear()
def subwin(self, x, y):
return self
def keypad(self, screen_id):
return None
def nodelay(self, screen_id):
return None
def getch(self):
return self.listen.get(27)
def erase(self):
self.reset()
return None
def addnstr(self, y, x, msg, ln, typo=0):
try:
fgs, bks = self.nc.colors[typo]
except Exception:
fgs, bks = self.COLOR_FG_DEFAULT, self.COLOR_BK_DEFAULT
self.term.set_color(fg=fgs, bk=bks)
self.term.print_at(x, y, msg.ljust(ln))
self.term.set_color(fg=self.COLOR_FG_DEFAULT, bk=self.COLOR_BK_DEFAULT)
def getmaxyx(self):
x = (self.term._Terminal__get_console_info().srWindow.Right -
self.term._Terminal__get_console_info().srWindow.Left + 1)
y = (self.term._Terminal__get_console_info().srWindow.Bottom -
self.term._Terminal__get_console_info().srWindow.Top + 1)
return [y, x]
def reset(self):
self.term.clear()
self.term.reset()
return None
def restore_buffered_mode(self):
self.term.restore_buffered_mode()
return None
class WCurseLight(object):
COLOR_WHITE = colorconsole.terminal.colors["WHITE"]
COLOR_RED = colorconsole.terminal.colors["RED"]
COLOR_GREEN = colorconsole.terminal.colors["GREEN"]
COLOR_BLUE = colorconsole.terminal.colors["LBLUE"]
COLOR_MAGENTA = colorconsole.terminal.colors["LPURPLE"]
COLOR_BLACK = colorconsole.terminal.colors["BLACK"]
A_UNDERLINE = 0
A_BOLD = 0
A_PROTECT = 0
COLOR_PAIRS = 9
colors = {}
def __init__(self):
self.term = Screen(self)
def initscr(self):
return self.term
def start_color(self):
return None
def use_default_colors(self):
return None
def noecho(self):
return None
def cbreak(self):
return None
def curs_set(self, y):
return None
def has_colors(self):
return True
def echo(self):
return None
def nocbreak(self):
return None
def endwin(self):
self.term.reset()
self.term.restore_buffered_mode()
self.term.listen.stop()
def napms(self, t):
time.sleep(t / 1000 if t > 1000 else 1)
def init_pair(self, color_id, fg, bk):
self.colors[color_id] = [max(fg, 0), max(bk, 0)]
def color_pair(self, color_id):
return color_id
|