summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/bar.py27
-rw-r--r--ranger/gui/widgets/statusbar.py2
-rw-r--r--ranger/gui/widgets/titlebar.py4
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()
leting mount points ( ) #57 10/01/30 warn before deleting unseen marked files (X) #58 10/02/04 change the title of the terminal (X) #61 10/02/09 show sum of size of marked files ( ) #63 10/02/15 limit filesize in previews Bugs (X) #17 10/01/01 why do bookmarks disappear sometimes? (X) #18 10/01/01 fix notify widget (by adding a LogView?) (X) #19 10/01/01 resizing after pressing g (X) #23 10/01/04 stop dir loading with ^C -> wont load anymore (X) #25 10/01/06 directories sometimes dont reload correctly (X) #26 10/01/06 :delete on symlinks of directories fails (X) #31 10/01/06 ^C breaks cd-after-exit by stopping sourced shell script ( ) #40 10/01/17 freeze with unavailable sshfs (X) #41 10/01/17 capital file extensions are not recognized (X) #46 10/01/19 old username displayed after using su (X) #49 10/01/19 fix unit tests :'( ( ) #52 10/01/23 special characters in tab completion (X) #54 10/01/23 max_dirsize_for_autopreview not working ( ) #60 10/02/05 utf support improvable (X) #62 10/02/15 curs_set can raise an exception (X) #64 10/02/16 "source ranger ranger some/file.txt" shouldn't cd after exit Ideas ( ) #20 10/01/01 use inotify to monitor filesystem changes ( ) #24 10/01/06 progress bar (X) #27 10/01/06 hide bookmarks in list which contain hidden dir (X) #28 10/01/06 use regexp instead of string for searching ( ) #33 10/01/08 accelerate mousewheel speed ( ) #45 10/01/18 hooks for events like setting changes ( ) #53 10/01/23 merge fm and environment