curses fixes

This commit is contained in:
lakshyacis 2019-12-27 19:42:57 +05:30
parent d9ef4a8e8d
commit 21ae6cb9b0
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB

View File

@ -1,8 +1,6 @@
"""
src/bitmessagecurses/__init__.py
================================
Bitmessage commandline interface
"""
# Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com>
# This file adds a alternative commandline interface, feel free to critique and fork
#
@ -20,21 +18,22 @@ import time
from textwrap import fill
from threading import Timer
from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser
from dialog import Dialog
from helper_ackPayload import genAckPayload
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
import l10n
import network.stats
from pyelliptic.openssl import OpenSSL
import queues
import shared
import shutdown
from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
# pylint: disable=global-statement
quit = False # pylint: disable=redefined-builtin
quit_ = False
menutab = 1
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
naptime = 100
@ -61,26 +60,31 @@ bwtype = "black"
BROADCAST_STR = "[Broadcast subscribers]"
class printLog: # pylint: disable=no-self-use, no-init, old-style-class
class printLog(object):
"""Printing logs"""
# pylint: disable=no-self-use
def write(self, output):
# pylint: disable=global-statement
"""Write logs"""
global log
log += output
def flush(self):
"""Flush logs"""
pass
class errLog: # pylint: disable=no-self-use, no-init, old-style-class
class errLog(object):
"""Error logs"""
# pylint: disable=no-self-use
def write(self, output):
# pylint: disable=global-statement
"""Write error logs"""
global log
log += "!" + output
def flush(self):
"""Flush error logs"""
pass
@ -138,14 +142,15 @@ def scrollbox(d, text, height=None, width=None):
def resetlookups():
"""Reset the Inventory Lookups"""
global inventorydata # pylint: disable=global-statement
global inventorydata
inventorydata = Inventory().numberOfInventoryLookupsPerformed
Inventory().numberOfInventoryLookupsPerformed = 0
Timer(1, resetlookups, ()).start()
def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statements
def drawtab(stdscr):
"""Method for drawing different tabs"""
# pylint: disable=too-many-branches, too-many-statements
if menutab in range(1, len(menu) + 1):
if menutab == 1: # Inbox
stdscr.addstr(3, 5, "To", curses.A_BOLD)
@ -282,12 +287,12 @@ def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statem
stdscr.addstr(13, 6, "Log", curses.A_BOLD)
n = log.count('\n')
if n > 0:
l = log.split('\n')
lg = log.split('\n')
if n > 512:
del l[:(n - 256)]
del lg[:(n - 256)]
logpad.erase()
n = len(l)
for i, item in enumerate(l):
n = len(lg)
for i, item in enumerate(lg):
a = 0
if item and item[0] == '!':
a = curses.color_pair(1)
@ -314,7 +319,8 @@ def dialogreset(stdscr):
# pylint: disable=too-many-branches, too-many-statements
def handlech(c, stdscr):
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals, global-statement
"""Handle character given on the command-line interface"""
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals
if c != curses.ERR:
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
if c in range(256):
@ -322,8 +328,8 @@ def handlech(c, stdscr):
global menutab
menutab = int(chr(c))
elif chr(c) == 'q':
global quit
quit = True
global quit_
quit_ = True
elif chr(c) == '\n':
curses.curs_set(1)
d = Dialog(dialog="dialog")
@ -877,7 +883,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
10,
60)
if r != d.DIALOG_OK:
global menutab # pylint: disable=global-statement
global menutab
menutab = 6
return
recv = t
@ -906,7 +912,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if not broadcast:
recvlist = []
for i, item in enumerate(recv.replace(",", ";").split(";")):
for _, item in enumerate(recv.replace(",", ";").split(";")):
recvlist.append(item.strip())
list(set(recvlist)) # Remove exact duplicates
for addr in recvlist:
@ -1170,7 +1176,7 @@ def loadSubscriptions():
def loadBlackWhiteList():
"""load black/white list"""
global bwtype # pylint: disable=global-statement
global bwtype
bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist")
if bwtype == "black":
ret = sqlQuery("SELECT label, address, enabled FROM blacklist")
@ -1183,10 +1189,10 @@ def loadBlackWhiteList():
def runwrapper():
"""Main method"""
sys.stdout = printlog
# sys.stderr = errlog
# Load messages from database
loadInbox()
loadSent()
loadAddrBook()
@ -1195,7 +1201,7 @@ def runwrapper():
stdscr = curses.initscr()
global logpad # pylint: disable=global-statement
global logpad
logpad = curses.newpad(1024, curses.COLS)
stdscr.nodelay(0)
@ -1207,6 +1213,7 @@ def runwrapper():
def run(stdscr):
"""Main loop"""
# Schedule inventory lookup data
resetlookups()
@ -1246,7 +1253,7 @@ def run(stdscr):
stdscr.clear()
redraw(stdscr)
while quit is False:
while quit_ is False:
drawtab(stdscr)
handlech(stdscr.getch(), stdscr)
@ -1259,5 +1266,4 @@ def doShutdown():
shutdown.doCleanShutdown()
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
os._exit(0) # pylint: disable=protected-access