Fix displaying non-ascii strings in the console ui -- patch from Ian Martin
This commit is contained in:
parent
6d2d3c0fd0
commit
7c2a2af1f0
|
@ -201,7 +201,7 @@ class Command(BaseCommand):
|
||||||
s += peer["country"] + "\t"
|
s += peer["country"] + "\t"
|
||||||
s += peer["ip"]
|
s += peer["ip"]
|
||||||
|
|
||||||
c = peer["client"].encode(sys.getdefaultencoding(), "replace")
|
c = peer["client"]
|
||||||
s += "\t" + c
|
s += "\t" + c
|
||||||
|
|
||||||
if len(c) < 16:
|
if len(c) < 16:
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
import os, sys
|
import os, sys
|
||||||
import optparse
|
import optparse
|
||||||
import shlex
|
import shlex
|
||||||
|
import locale
|
||||||
|
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
|
|
||||||
|
@ -137,6 +138,14 @@ def load_commands(command_dir, exclude=[]):
|
||||||
class ConsoleUI(component.Component):
|
class ConsoleUI(component.Component):
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
component.Component.__init__(self, "ConsoleUI", 2)
|
component.Component.__init__(self, "ConsoleUI", 2)
|
||||||
|
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
self.encoding = locale.getpreferredencoding()
|
||||||
|
except:
|
||||||
|
self.encoding = sys.getdefaultencoding()
|
||||||
|
|
||||||
|
log.debug("Using encoding: %s", self.encoding)
|
||||||
# Load all the commands
|
# Load all the commands
|
||||||
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
|
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
|
||||||
|
|
||||||
|
@ -191,7 +200,7 @@ class ConsoleUI(component.Component):
|
||||||
# We want to do an interactive session, so start up the curses screen and
|
# We want to do an interactive session, so start up the curses screen and
|
||||||
# pass it the function that handles commands
|
# pass it the function that handles commands
|
||||||
colors.init_colors()
|
colors.init_colors()
|
||||||
self.screen = screen.Screen(stdscr, self.do_command, self.tab_completer)
|
self.screen = screen.Screen(stdscr, self.do_command, self.tab_completer, self.encoding)
|
||||||
self.statusbars = StatusBars()
|
self.statusbars = StatusBars()
|
||||||
self.eventlog = EventLog()
|
self.eventlog = EventLog()
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import sys
|
||||||
import curses
|
import curses
|
||||||
import colors
|
import colors
|
||||||
try:
|
try:
|
||||||
|
@ -63,7 +64,7 @@ LINES_BUFFER_SIZE = 5000
|
||||||
INPUT_HISTORY_SIZE = 500
|
INPUT_HISTORY_SIZE = 500
|
||||||
|
|
||||||
class Screen(CursesStdIO):
|
class Screen(CursesStdIO):
|
||||||
def __init__(self, stdscr, command_parser, tab_completer=None):
|
def __init__(self, stdscr, command_parser, tab_completer=None, encoding=None):
|
||||||
"""
|
"""
|
||||||
A curses screen designed to run as a reader in a twisted reactor.
|
A curses screen designed to run as a reader in a twisted reactor.
|
||||||
|
|
||||||
|
@ -110,6 +111,11 @@ class Screen(CursesStdIO):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Unable to catch SIGWINCH signal!")
|
log.debug("Unable to catch SIGWINCH signal!")
|
||||||
|
|
||||||
|
if not encoding:
|
||||||
|
self.encoding = sys.getdefaultencoding()
|
||||||
|
else:
|
||||||
|
self.encoding = encoding
|
||||||
|
|
||||||
# Do a refresh right away to draw the screen
|
# Do a refresh right away to draw the screen
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
@ -233,6 +239,9 @@ class Screen(CursesStdIO):
|
||||||
if index + 1 == len(parsed):
|
if index + 1 == len(parsed):
|
||||||
# This is the last string so lets append some " " to it
|
# This is the last string so lets append some " " to it
|
||||||
s += " " * (self.cols - (col + len(s)) - 1)
|
s += " " * (self.cols - (col + len(s)) - 1)
|
||||||
|
if isinstance(s, unicode):
|
||||||
|
#Have to use replace as character counting has already been done
|
||||||
|
s = s.encode(self.encoding, 'replace')
|
||||||
self.stdscr.addstr(row, col, s, color)
|
self.stdscr.addstr(row, col, s, color)
|
||||||
col += len(s)
|
col += len(s)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue