summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarkedos <dennis.marbaise@mailbox.org>2019-10-27 10:20:53 +0100
committertoonn <toonn@toonn.io>2019-12-31 12:49:30 +0100
commit280f459046cbc276b523301b68b4ae5dcc95d9f5 (patch)
tree8bbf25d599d151c6fbdd5773add14c0684ecea77
parent5acd73831ebdd409dcfac63b75ef462f81173d42 (diff)
refactoring of redundant code
squashing commits for cleaner history. whitespace final fixes refactor of redundant code
-rw-r--r--doc/ranger.pod4
-rw-r--r--ranger/config/rc.conf4
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/gui/ui.py84
4 files changed, 70 insertions, 23 deletions
diff --git a/doc/ranger.pod b/doc/ranger.pod
index bae332e9..a7f07ffc 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -1268,6 +1268,10 @@ Set a window title? Updates both the I<WM_NAME> and I<WM_ICON_NAME> properties.
Set the tmux I<window-name> to "ranger"?
+=item update_screen_title [bool]
+
+Set the title to "ranger" in the screen program?
+
=item use_preview_script [bool] <zv>
Use the preview script defined in the setting I<preview_script>?
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 66a5fbbc..c7af4962 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -188,6 +188,10 @@ set update_title false
# Set the tmux window-name to "ranger"?
set update_tmux_title true
+# Set the title to "ranger" in the screen program?
+
+set update_screen_title true
+
# Shorten the title if it gets long? The number defines how many
# directories are displayed at once, 0 turns off this feature.
set shorten_title 3
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 7549325a..348a8761 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -88,6 +88,7 @@ ALLOWED_SETTINGS = {
'unicode_ellipsis': bool,
'update_title': bool,
'update_tmux_title': bool,
+ 'update_screen_title': bool,
'use_preview_script': bool,
'vcs_aware': bool,
'vcs_backend_bzr': str,
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 83c63e57..3cb219f1 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -70,8 +70,11 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method
self.status = None
self.console = None
self.pager = None
+ self.multiplexer = None
self._draw_title = None
self._tmux_automatic_rename = None
+ self._tmux_allow_rename = None
+ self._screen_title = None
self.browser = None
if fm is not None:
@@ -93,7 +96,6 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method
self.win.leaveok(0)
self.win.keypad(1)
self.load_mode = False
-
curses.cbreak()
curses.noecho()
curses.halfdelay(20)
@@ -118,24 +120,16 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method
self.win.refresh()
self._draw_title = curses.tigetflag('hs') # has_status_line
- # Save tmux setting `automatic-rename`
- if self.settings.update_tmux_title and 'TMUX' in os.environ:
- try:
- self._tmux_automatic_rename = check_output(
- ['tmux', 'show-window-option', '-v', 'automatic-rename']).strip()
- if self._tmux_automatic_rename == 'off':
- self._tmux_automatic_rename = 'on'
- except CalledProcessError:
- self._tmux_automatic_rename = None
+ if 'TMUX' in os.environ:
+ self.multiplexer = 'TMUX'
+ elif os.environ['TERM'] == 'screen':
+ self.multiplexer = 'screen'
+
+ self.handle_multiplexer(self.multiplexer)
self.update_size()
self.is_on = True
- if self.settings.update_tmux_title and 'TMUX' in os.environ:
- check_output(['tmux', 'rename-window', 'Ranger'])
- sys.stdout.write("\033kranger\033\\")
- sys.stdout.flush()
-
if 'vcsthread' in self.__dict__:
self.vcsthread.unpause()
@@ -183,14 +177,8 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method
del self.__dict__['vcsthread']
DisplayableContainer.destroy(self)
- # Restore tmux setting `automatic-rename`
- if self.settings.update_tmux_title and 'TMUX' in os.environ:
- if self._tmux_automatic_rename:
- try:
- check_output(['tmux', 'set-window-option',
- 'automatic-rename', self._tmux_automatic_rename])
- except CalledProcessError:
- pass
+ if self.multiplexer is not None:
+ self.handle_multiplexer(self.multiplexer, restore_required=True)
self.suspend()
@@ -483,6 +471,56 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method
else:
self.titlebar.throbber = string
+ # Handles window renaming behaviour of the terminal multiplexers GNU Screen and Tmux
+ def handle_multiplexer(self, multiplexer=None, restore_required=False):
+ # helper function
+ def execute_rename(multiplexer):
+ try:
+ if multiplexer == 'TMUX':
+ check_output(['tmux', 'set-window-option',
+ 'automatic-rename', self._tmux_automatic_rename])
+ elif multiplexer == 'screen':
+ check_output(['screen', '-X', 'title', self._screen_title])
+ except CalledProcessError:
+ pass
+
+ # Stores the screen window name before renaming it
+ # gives out a warning if $TERM is not "screen"
+
+ if multiplexer == 'screen' and not restore_required:
+ if os.environ['TERM'] != 'screen' and 'TMUX' not in os.environ:
+ self.fm.notify(
+ '$TERM not set to "screen". Automatic window title not applied.', bad=True)
+ try:
+ self._screen_title = check_output(['screen', '-Q', 'title']).strip()
+ except CalledProcessError:
+ self._screen_title = None
+
+ # Stores the automatic-rename setting
+ # prints out a warning if the allow-rename in tmux is not set
+ if multiplexer == 'TMUX' and not restore_required:
+ if self.settings.update_tmux_title:
+ self._tmux_allow_rename = check_output(
+ ['tmux', 'show-window-option', '-v', 'allow-rename']).strip()
+ if self._tmux_allow_rename == 'off':
+ self.fm.notify('Warning: allow-rename not set in Tmux!', bad=True)
+ else:
+ try:
+ self._tmux_automatic_rename = check_output(
+ ['tmux', 'show-window-option', '-v', 'automatic-rename']).strip()
+ if self._tmux_automatic_rename == 'off':
+ self._tmux_automatic_rename = 'on'
+ except CalledProcessError:
+ self._tmux_automatic_rename = None
+
+ if multiplexer is not None and not restore_required:
+ sys.stdout.write("\033kranger\033\\")
+ sys.stdout.flush()
+
+ # Restore window name
+ if multiplexer and restore_required:
+ execute_rename(multiplexer)
+
def hint(self, text=None):
self.status.hint = text