Fixed colors in lxterminal. (raspbian and lubuntu)
lxterminal in lubuntu and raspbian is only taking 256 colors. So when $TERM is "xterm" only 256 colors are used.
This commit is contained in:
parent
a12fa48c2c
commit
3711a0b293
5 changed files with 26 additions and 33 deletions
3
BUGS
3
BUGS
|
|
@ -244,14 +244,13 @@ Fixed
|
|||
workers.
|
||||
- gcc is not working inside the sandbox.
|
||||
<- Let /dev/null through the sandbox.
|
||||
- There is no color in lxterminal, only shades of grey.
|
||||
|
||||
|
||||
Won't fix
|
||||
- If the summary window is narrower then max_path_length the paths are never
|
||||
visible.
|
||||
<- Only a problem for very narrow windows.
|
||||
- There is no color in lxterminal, only shades of grey.
|
||||
<- Only testing gnome-terminal & stterm at the moment.
|
||||
- Sometimes a lot (or all?) of the results are "?" even with correct statuses.
|
||||
<- Happens when the cache is deleted from underneath a running vigil.
|
||||
- In stterm the previous console title isn't being restored.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ up to date as the codebase changes.
|
|||
|
||||
### Installation
|
||||
|
||||
To run vigil: (Tested in Ubuntu 16.10 in gnome-terminal and stterm)
|
||||
To run vigil: (Tested in Ubuntu 16.10 in gnome-terminal, lxterminal and stterm)
|
||||
|
||||
# git clone https://github.com/ahamilton/vigil
|
||||
# cd vigil
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ up to date as the codebase changes.
|
|||
|
||||
### Installation
|
||||
|
||||
To run vigil: (Tested in Ubuntu 16.10 in gnome-terminal and stterm)
|
||||
To run vigil: (Tested in Ubuntu 16.10 in gnome-terminal, lxterminal and stterm)
|
||||
|
||||
# git clone https://github.com/ahamilton/vigil
|
||||
# cd vigil
|
||||
|
|
|
|||
26
terminal.py
26
terminal.py
|
|
@ -24,30 +24,12 @@ save = ESC + "7" # sc
|
|||
restore = ESC + "8" # rc
|
||||
|
||||
|
||||
_FG_CODES = ["30", "31", "32", "33", "34", "35", "36", "37",
|
||||
"90", "91", "92", "93", "94", "95", "96", "97"]
|
||||
def color(color_number, is_foreground):
|
||||
return "\x1b[%s;5;%im" % ("38" if is_foreground else "48", color_number)
|
||||
|
||||
|
||||
def fg_color(color_number): # setaf
|
||||
return ("\x1b[38;5;%im" % color_number if color_number > 15
|
||||
else "\x1b[%sm" % _FG_CODES[color_number])
|
||||
|
||||
|
||||
_BG_CODES = ["40", "41", "42", "43", "44", "45", "46", "47",
|
||||
"100", "101", "102", "103", "104", "105", "106", "107"]
|
||||
|
||||
|
||||
def bg_color(color_number): # setab
|
||||
return ("\x1b[48;5;%im" % color_number if color_number > 15
|
||||
else "\x1b[%sm" % _BG_CODES[color_number])
|
||||
|
||||
|
||||
def fg_rgb_color(rgb):
|
||||
return "\x1b[38;2;%i;%i;%im" % rgb
|
||||
|
||||
|
||||
def bg_rgb_color(rgb):
|
||||
return "\x1b[48;2;%i;%i;%im" % rgb
|
||||
def rgb_color(rgb, is_foreground):
|
||||
return "\x1b[%s;2;" % ("38" if is_foreground else "48") + "%i;%i;%im" % rgb
|
||||
|
||||
|
||||
def move(x, y): # cup
|
||||
|
|
|
|||
26
termstr.py
26
termstr.py
|
|
@ -3,8 +3,11 @@
|
|||
# Licensed under the Artistic License 2.0.
|
||||
|
||||
import collections
|
||||
import os
|
||||
import weakref
|
||||
|
||||
import pygments.formatters.terminal256
|
||||
|
||||
import terminal
|
||||
|
||||
|
||||
|
|
@ -35,6 +38,7 @@ class Color:
|
|||
class CharStyle:
|
||||
|
||||
_POOL = weakref.WeakValueDictionary()
|
||||
_TERMINAL256_FORMATTER = pygments.formatters.terminal256.Terminal256Formatter()
|
||||
|
||||
def __new__(cls, fg_color=None, bg_color=None, is_bold=False,
|
||||
is_italic=False, is_underlined=False):
|
||||
|
|
@ -66,18 +70,26 @@ class CharStyle:
|
|||
return ("<CharStyle: fg:%s bg:%s attr:%s>" %
|
||||
(self.fg_color, self.bg_color, ",".join(attributes)))
|
||||
|
||||
def termcode_of_color(self, color, is_foreground):
|
||||
if isinstance(color, int):
|
||||
return terminal.color(color, is_foreground)
|
||||
else: # true color
|
||||
if os.environ["TERM"] == "xterm":
|
||||
closest_color = self._TERMINAL256_FORMATTER._closest_color(
|
||||
*color)
|
||||
return terminal.color(closest_color, is_foreground)
|
||||
else:
|
||||
return terminal.rgb_color(color, is_foreground)
|
||||
|
||||
@_cache_first_result
|
||||
def code_for_term(self):
|
||||
fg_func = (terminal.fg_color if isinstance(self.fg_color, int)
|
||||
else terminal.fg_rgb_color)
|
||||
bg_func = (terminal.bg_color if isinstance(self.bg_color, int)
|
||||
else terminal.bg_rgb_color)
|
||||
fg_termcode = self.termcode_of_color(self.fg_color, True)
|
||||
bg_termcode = self.termcode_of_color(self.bg_color, False)
|
||||
bold_code = terminal.bold if self.is_bold else ""
|
||||
italic_code = terminal.italic if self.is_italic else ""
|
||||
underline_code = terminal.underline if self.is_underlined else ""
|
||||
return "".join([terminal.normal, fg_func(self.fg_color),
|
||||
bg_func(self.bg_color), bold_code, italic_code,
|
||||
underline_code])
|
||||
return "".join([terminal.normal, fg_termcode, bg_termcode, bold_code,
|
||||
italic_code, underline_code])
|
||||
|
||||
|
||||
def _join_lists(lists):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue