mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
Webconfig: Don't outright abort if curses can't be imported
We only need the curses module to look up sgr0, bold and underline sequences. Since those are going to be the xterm versions 90% of the time, we can simply use those if this fails. Fixes #8487.
This commit is contained in:
parent
6f7b80e5b4
commit
5a71d02d32
1 changed files with 28 additions and 16 deletions
|
@ -508,25 +508,37 @@ g_special_escapes_dict = None
|
|||
def get_special_ansi_escapes():
|
||||
global g_special_escapes_dict
|
||||
if g_special_escapes_dict is None:
|
||||
import curses
|
||||
try:
|
||||
import curses
|
||||
|
||||
g_special_escapes_dict = {}
|
||||
curses.setupterm()
|
||||
g_special_escapes_dict = {}
|
||||
curses.setupterm()
|
||||
|
||||
# Helper function to get a value for a tparm
|
||||
def get_tparm(key):
|
||||
val = None
|
||||
key = curses.tigetstr(key)
|
||||
if key:
|
||||
val = curses.tparm(key)
|
||||
if val:
|
||||
val = val.decode("utf-8")
|
||||
return val
|
||||
# Helper function to get a value for a tparm
|
||||
def get_tparm(key):
|
||||
val = None
|
||||
key = curses.tigetstr(key)
|
||||
if key:
|
||||
val = curses.tparm(key)
|
||||
if val:
|
||||
val = val.decode("utf-8")
|
||||
return val
|
||||
|
||||
# Just a few for now
|
||||
g_special_escapes_dict["exit_attribute_mode"] = get_tparm("sgr0")
|
||||
g_special_escapes_dict["bold"] = get_tparm("bold")
|
||||
g_special_escapes_dict["underline"] = get_tparm("smul")
|
||||
# Just a few for now
|
||||
g_special_escapes_dict["exit_attribute_mode"] = get_tparm("sgr0")
|
||||
g_special_escapes_dict["bold"] = get_tparm("bold")
|
||||
g_special_escapes_dict["underline"] = get_tparm("smul")
|
||||
except ImportError:
|
||||
print("WARNING: The python curses module is missing.")
|
||||
print("WARNING: Falling back to xterm-256color settings.")
|
||||
print("WARNING: Rebuild python with curses headers!")
|
||||
|
||||
g_special_escapes_dict = {
|
||||
'exit_attribute_mode': '\x1b(B\x1b[m',
|
||||
'bold': '\x1b[1m',
|
||||
'underline': '\x1b[4m'
|
||||
}
|
||||
pass
|
||||
|
||||
return g_special_escapes_dict
|
||||
|
||||
|
|
Loading…
Reference in a new issue