Support for transparent terminals in curses mode

This commit is contained in:
bssb 2014-09-23 22:35:18 -07:00
parent 13db5fe00c
commit dc307be40b
2 changed files with 28 additions and 17 deletions

View File

@ -961,7 +961,7 @@ def loadBlackWhiteList():
blacklist.append([label, address, enabled]) blacklist.append([label, address, enabled])
blacklist.reverse() blacklist.reverse()
def runwrapper(): def runwrapper(transparent):
sys.stdout = printlog sys.stdout = printlog
#sys.stderr = errlog #sys.stderr = errlog
@ -981,30 +981,37 @@ def runwrapper():
curses.curs_set(0) curses.curs_set(0)
stdscr.timeout(1000) stdscr.timeout(1000)
curses.wrapper(run) if (transparent):
curses.wrapper(run_transparent)
else:
curses.wrapper(run)
shutdown() shutdown()
def run(stdscr): def run_transparent(stdscr):
curses.use_default_colors()
run(stdscr, -1)
def run(stdscr,bgcolor=curses.COLOR_BLACK):
# Schedule inventory lookup data # Schedule inventory lookup data
resetlookups() resetlookups()
# Init color pairs # Init color pairs
if curses.has_colors(): if curses.has_colors():
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) # red curses.init_pair(1, curses.COLOR_RED, bgcolor) # red
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) # green curses.init_pair(2, curses.COLOR_GREEN, bgcolor) # green
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) # yellow curses.init_pair(3, curses.COLOR_YELLOW, bgcolor) # yellow
curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK) # blue curses.init_pair(4, curses.COLOR_BLUE, bgcolor) # blue
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) # magenta curses.init_pair(5, curses.COLOR_MAGENTA, bgcolor) # magenta
curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK) # cyan curses.init_pair(6, curses.COLOR_CYAN, bgcolor) # cyan
curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK) # white curses.init_pair(7, curses.COLOR_WHITE, bgcolor) # white
if curses.can_change_color(): if curses.can_change_color():
curses.init_color(8, 500, 500, 500) # gray curses.init_color(8, 500, 500, 500) # gray
curses.init_pair(8, 8, 0) curses.init_pair(8, 8, bgcolor)
curses.init_color(9, 844, 465, 0) # orange curses.init_color(9, 844, 465, 0) # orange
curses.init_pair(9, 9, 0) curses.init_pair(9, 9, bgcolor)
else: else:
curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK) # grayish curses.init_pair(8, curses.COLOR_WHITE, bgcolor) # grayish
curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_BLACK) # orangish curses.init_pair(9, curses.COLOR_YELLOW, bgcolor) # orangish
# Init list of address in 'Your Identities' tab # Init list of address in 'Your Identities' tab
configSections = shared.config.sections() configSections = shared.config.sections()

View File

@ -168,7 +168,11 @@ class Main:
# get curses flag # get curses flag
curses = False curses = False
if '-c' in sys.argv: transparent = False
if '-ct' in sys.argv:
curses = True
transparent = True
elif '-c' in sys.argv:
curses = True curses = True
signal.signal(signal.SIGINT, helper_generic.signal_handler) signal.signal(signal.SIGINT, helper_generic.signal_handler)
@ -232,7 +236,7 @@ class Main:
except Exception as err: except Exception as err:
print('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon') print('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon')
print('Error message:', err) print('Error message:', err)
print('You can also run PyBitmessage with the new curses interface by providing \'-c\' as a commandline argument.') print('You can also run PyBitmessage with the new curses interface by providing \'-c\' as a commandline argument. For transparent curses mode, \'-ct\' may be used.')
os._exit(0) os._exit(0)
import bitmessageqt import bitmessageqt
@ -240,7 +244,7 @@ class Main:
else: else:
print('Running with curses') print('Running with curses')
import bitmessagecurses import bitmessagecurses
bitmessagecurses.runwrapper() bitmessagecurses.runwrapper(transparent)
else: else:
shared.config.remove_option('bitmessagesettings', 'dontconnect') shared.config.remove_option('bitmessagesettings', 'dontconnect')