diff options
author | hut <hut@lavabit.com> | 2011-10-01 17:57:09 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-10-01 17:57:09 +0200 |
commit | 7247fa714f1c39e6996f844261d57dca252f638d (patch) | |
tree | 1ba42cc8911d5fbbd3d571dd911eac5971f23eb7 /ranger | |
parent | 964308467831d5e1bf93b29533d2cbe89102fd8c (diff) | |
download | ranger-7247fa714f1c39e6996f844261d57dca252f638d.tar.gz |
gui.bar: fixing unicode in bars...
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/gui/bar.py | 27 | ||||
-rw-r--r-- | ranger/gui/widgets/statusbar.py | 2 | ||||
-rw-r--r-- | ranger/gui/widgets/titlebar.py | 4 |
3 files changed, 22 insertions, 11 deletions
diff --git a/ranger/gui/bar.py b/ranger/gui/bar.py index ef769ca5..0f2d8cd8 100644 --- a/ranger/gui/bar.py +++ b/ranger/gui/bar.py @@ -13,7 +13,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from ranger.ext.widestring import uwid +from ranger.ext.widestring import WideString, utf_char_width +import sys +PY3 = sys.version > '3' class Bar(object): left = None @@ -45,7 +47,7 @@ class Bar(object): # remove elemets from the left until it fits if sumsize > wid: while len(self.left) > 0: - leftsize -= len(self.left.pop(-1).string) + leftsize -= len(self.left.pop(-1)) if leftsize + rightsize <= wid: break sumsize = leftsize + rightsize @@ -53,7 +55,7 @@ class Bar(object): # remove elemets from the right until it fits if sumsize > wid: while len(self.right) > 0: - rightsize -= len(self.right.pop(0).string) + rightsize -= len(self.right.pop(0)) if leftsize + rightsize <= wid: break sumsize = leftsize + rightsize @@ -117,7 +119,7 @@ class BarSide(list): if item.fixed: n += len(item) else: - n += 1 + n += item.width_of_first_letter return n def nonfixed_items(self): @@ -126,19 +128,28 @@ class BarSide(list): class ColoredString(object): def __init__(self, string, *lst): - self.string = string + self.string = WideString(string) self.lst = lst self.fixed = False + if not len(string): + self.width_of_first_letter = 0 + elif PY3: + self.width_of_first_letter = utf_char_width(string[0]) + else: + self.width_of_first_letter = utf_char_width(self.string.chars[0].decode('utf-8')) def cut_off(self, n): if n >= 1: self.string = self.string[:-n] def cut_off_to(self, n): - self.string = self.string[:n] + if n < self.width_of_first_letter: + self.string = self.string[:self.width_of_first_letter] + elif n < len(self.string): + self.string = self.string[:n] def __len__(self): - return uwid(self.string) + return len(self.string) def __str__(self): - return self.string + return str(self.string) diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index b7ab123c..d8704af3 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -267,7 +267,7 @@ class StatusBar(Widget): self.win.move(0, 0) for part in result: self.color(*part.lst) - self.addstr(part.string) + self.addstr(str(part)) self.color_reset() class Message(object): diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index d87a0803..c1994b5b 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -77,7 +77,7 @@ class TitleBar(Widget): pos = 0 for i, part in enumerate(self.result): - pos += len(part.string) + pos += len(part) if event.x < pos: if i < 2: self.fm.enter_dir("~") @@ -159,5 +159,5 @@ class TitleBar(Widget): self.win.move(0, 0) for part in result: self.color(*part.lst) - self.addstr(part.string) + self.addstr(str(part)) self.color_reset() |