| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d251064 commit a5e541b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,7 @@ | |||
| 72 | 72 | from bpython import importcompletion | |
| 73 | 73 | ||
| 74 | 74 | # This for config | |
| 75 | - from bpython.config import Struct | ||
| 75 | + from bpython.config import Struct, getpreferredencoding | ||
| 76 | 76 | ||
| 77 | 77 | # This for keys | |
| 78 | 78 | from bpython.keys import cli_key_dispatch as key_dispatch | |
@@ -98,9 +98,6 @@ | |||
| 98 | 98 | # --- | |
| 99 | 99 | ||
| 100 | 100 | ||
| 101 | - def getpreferredencoding(): | ||
| 102 | - return locale.getpreferredencoding() or sys.getdefaultencoding() | ||
| 103 | - | ||
| 104 | 101 | def calculate_screen_lines(tokens, width, cursor=0): | |
| 105 | 102 | """Given a stream of tokens and a screen width plus an optional | |
| 106 | 103 | initial cursor position, return the amount of needed lines on the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,11 +3,11 @@ | |||
| 3 | 3 | from __future__ import with_statement | |
| 4 | 4 | import os | |
| 5 | 5 | import sys | |
| 6 | + import locale | ||
| 6 | 7 | from ConfigParser import ConfigParser | |
| 7 | 8 | from itertools import chain | |
| 8 | 9 | from bpython.keys import cli_key_dispatch as key_dispatch | |
| 9 | 10 | from bpython.autocomplete import SIMPLE as default_completion | |
| 10 | - | ||
| 11 | 11 | import bpython.autocomplete | |
| 12 | 12 | ||
| 13 | 13 | ||
@@ -16,6 +16,21 @@ class Struct(object): | |||
| 16 | 16 | to and use for various arbitrary things.""" | |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + def getpreferredencoding(): | ||
| 20 | + """Get the user's preferred encoding.""" | ||
| 21 | + return locale.getpreferredencoding() or sys.getdefaultencoding() | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + def supports_box_chars(): | ||
| 25 | + """Check if the encoding suppors Unicode box characters.""" | ||
| 26 | + try: | ||
| 27 | + for c in (u'│', u'│', u'─', u'─', u'└', u'┘', u'┌', u'┐'): | ||
| 28 | + c.encode(getpreferredencoding()) | ||
| 29 | + return True | ||
| 30 | + except UnicodeEncodeError: | ||
| 31 | + return False | ||
| 32 | + | ||
| 33 | + | ||
| 19 | 34 | def get_config_home(): | |
| 20 | 35 | """Returns the base directory for bpython's configuration files.""" | |
| 21 | 36 | xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '~/.config') | |
@@ -256,7 +271,7 @@ def get_key_no_doublebind(command): | |||
| 256 | 271 | struct.autocomplete_mode = default_completion | |
| 257 | 272 | ||
| 258 | 273 | # set box drawing characters | |
| 259 | - if config.getboolean('general', 'unicode_box'): | ||
| 274 | + if config.getboolean('general', 'unicode_box') and supports_box_chars(): | ||
| 260 | 275 | struct.left_border = u'│' | |
| 261 | 276 | struct.right_border = u'│' | |
| 262 | 277 | struct.top_border = u'─' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | # The MIT License | |
| 2 | 2 | # | |
| 3 | - # Copyright (c) 2009-2011 the bpython authors. | ||
| 3 | + # Copyright (c) 2009-2015 the bpython authors. | ||
| 4 | 4 | # | |
| 5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 6 | 6 | # of this software and associated documentation files (the "Software"), to deal | |
| Back | FazBrowse Home | New Git URL |
0 commit comments