summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-18 23:21:06 +0100
committerhut <hut@lavabit.com>2010-03-18 23:21:06 +0100
commit6a40e8e08296097a56269447c1bbbf3cb2c0e77e (patch)
treea698c66eb9e98318a2ad1f7b9bdd8d0b65cbebbf
parent373031316ee733901a4b092e6554b7470746f004 (diff)
downloadranger-6a40e8e08296097a56269447c1bbbf3cb2c0e77e.tar.gz
ui: Guess if terminal supports title (by looking at $TERM)
Thanks to JohannesSM64
-rw-r--r--ranger/defaults/options.py5
-rw-r--r--ranger/gui/ui.py20
2 files changed, 13 insertions, 12 deletions
diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py
index df755b51..00be15d1 100644
--- a/ranger/defaults/options.py
+++ b/ranger/defaults/options.py
@@ -49,9 +49,8 @@ preview_files = True
 max_filesize_for_preview = 300 * 1024  # 300kb
 collapse_preview = True
 
-# Specify a title for the window? Some terminals don't support this,
-# so it's turned off by default.
-update_title = False
+# Set a title for the window?
+update_title = True
 
 # How many directory-changes or console-commands should be kept in history?
 max_history_size = 20
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 77cde51d..b073c2e0 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -22,19 +22,25 @@ from .displayable import DisplayableContainer
 from .mouse_event import MouseEvent
 from ranger.container import CommandList
 
+TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt",
+		"rxvt-256color", "rxvt-unicode", "aterm", "Eterm",
+		"screen", "screen-256color")
+
 class UI(DisplayableContainer):
 	is_set_up = False
 	mousemask = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION
 	load_mode = False
 	def __init__(self, commandlist=None, env=None, fm=None):
-		import os
-		os.environ['ESCDELAY'] = '25'   # don't know a cleaner way
+		from os import environ
+		self._draw_title = environ["TERM"] in TERMINALS_WITH_TITLE
+		environ['ESCDELAY'] = '25'   # don't know a cleaner way
 
 		if env is not None:
 			self.env = env
 		if fm is not None:
 			self.fm = fm
 
+
 		if commandlist is None:
 			self.commandlist = CommandList()
 			self.settings.keys.initialize_commands(self.commandlist)
@@ -194,13 +200,9 @@ class UI(DisplayableContainer):
 		"""Erase the window, then draw all objects in the container"""
 		self.win.touchwin()
 		DisplayableContainer.draw(self)
-		if self.settings.update_title:
-			hostname = str(socket.gethostname())
-			try:
-				cwd = self.fm.env.cwd.path
-			except:
-				cwd = ' - ranger'
-			sys.stdout.write("\033]2;" + hostname + cwd + "\007")
+		if self._draw_title and self.settings.update_title:
+			cwd = self.fm.env.cwd.path
+			sys.stdout.write("\033]2;ranger:" + cwd + "\007")
 		self.win.refresh()
 
 	def finalize(self):