Merge pull request #1381 from ZyX-I/tmux-length-shrink
Add support for truncating tmux segments
This commit is contained in:
commit
2fa7c3cfc8
|
@ -8,5 +8,5 @@ set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR]$_POWERLINE_LEFT_HARD_DI
|
|||
set -g window-status-current-format "#[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#[$_POWERLINE_WINDOW_CURRENT_COLOR]#I $_POWERLINE_LEFT_SOFT_DIVIDER#[$_POWERLINE_WINDOW_NAME_COLOR]#W #[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER"
|
||||
|
||||
# Legacy status-left definition to be overwritten for tmux Versions 1.8+
|
||||
set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left)"
|
||||
set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left -R pane_id=`tmux display -p '#D'`)"
|
||||
# vim: ft=tmux
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id=`tmux display -p "#D"` --width=`tmux display -p "#{client_width}"` -R width_adjust=`tmux show-options -g status-left-length | cut -d" " -f 2`)'
|
||||
set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left --width=`tmux display -p '#{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=`tmux display -p '#D'`)"
|
||||
# vim: ft=tmux
|
|
@ -1,5 +1,5 @@
|
|||
# powerline_tmux_1.8_plus.conf
|
||||
# tmux Version 1.8 introduces the 'client_prefix' format variable, applicable
|
||||
# for versions 1.8+
|
||||
set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]$_POWERLINE_LEFT_HARD_DIVIDER#(env \$POWERLINE_COMMAND \$POWERLINE_COMMAND_ARGS tmux left)"
|
||||
set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]$_POWERLINE_LEFT_HARD_DIVIDER#(env \$POWERLINE_COMMAND \$POWERLINE_COMMAND_ARGS tmux left --width=`tmux display -p '#{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=`tmux display -p '#D'`)"
|
||||
# vim: ft=tmux
|
||||
|
|
|
@ -25,7 +25,7 @@ def parse_value(s):
|
|||
'''
|
||||
if not s:
|
||||
return REMOVE_THIS_KEY
|
||||
elif s[0] in '"{[0193456789-' or s in ('null', 'true', 'false'):
|
||||
elif s[0] in '"{[0123456789-' or s in ('null', 'true', 'false'):
|
||||
return json.loads(s)
|
||||
else:
|
||||
return s
|
||||
|
|
|
@ -31,6 +31,13 @@ class TmuxRenderer(Renderer):
|
|||
character_translations = Renderer.character_translations.copy()
|
||||
character_translations[ord('#')] = '##[]'
|
||||
|
||||
def render(self, width=None, segment_info={}, **kwargs):
|
||||
if width and segment_info:
|
||||
width -= segment_info.get('width_adjust', 0)
|
||||
if width < 10:
|
||||
width = 10
|
||||
return super(TmuxRenderer, self).render(width=width, segment_info=segment_info, **kwargs)
|
||||
|
||||
def hlstyle(self, fg=None, bg=None, attrs=None):
|
||||
'''Highlight a segment.'''
|
||||
# We don’t need to explicitly reset attributes, so skip those calls
|
||||
|
|
|
@ -28,6 +28,7 @@ class ExpectProcess(threading.Thread):
|
|||
child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd, env=self.env)
|
||||
sleep(0.5)
|
||||
child.setwinsize(self.rows, self.cols)
|
||||
sleep(0.5)
|
||||
self.child = child
|
||||
status = None
|
||||
while status is None:
|
||||
|
@ -44,6 +45,13 @@ class ExpectProcess(threading.Thread):
|
|||
self.vterm.push(s)
|
||||
self.buffer.append(s)
|
||||
|
||||
def resize(self, rows, cols):
|
||||
with self.child_lock:
|
||||
self.rows = rows
|
||||
self.cols = cols
|
||||
self.child.setwinsize(rows, cols)
|
||||
self.vterm.resize(rows, cols)
|
||||
|
||||
def __getitem__(self, position):
|
||||
with self.lock:
|
||||
return self.vterm.vtscreen[position]
|
||||
|
|
|
@ -91,6 +91,11 @@ def get_functions(lib):
|
|||
('cols', ctypes.c_int)
|
||||
)),
|
||||
vterm_obtain_screen=(VTermScreen_p, (('vt', VTerm_p),)),
|
||||
vterm_set_size=(None, (
|
||||
('vt', VTerm_p),
|
||||
('rows', ctypes.c_int),
|
||||
('cols', ctypes.c_int)
|
||||
)),
|
||||
vterm_screen_reset=(None, (
|
||||
('screen', VTermScreen_p),
|
||||
('hard', ctypes.c_int)
|
||||
|
@ -171,6 +176,9 @@ class VTerm(object):
|
|||
data = data.encode('utf-8')
|
||||
return self.functions.vterm_input_write(self.vt, data, len(data))
|
||||
|
||||
def resize(self, rows, cols):
|
||||
self.functions.vterm_set_size(self.vt, rows, cols)
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
self.functions.vterm_free(self.vt)
|
||||
|
|
|
@ -11,6 +11,7 @@ mkdir tests/vterm/path
|
|||
ln -s "$(which "${PYTHON}")" tests/vterm/path/python
|
||||
ln -s "$(which bash)" tests/vterm/path
|
||||
ln -s "$(which env)" tests/vterm/path
|
||||
ln -s "$(which cut)" tests/vterm/path
|
||||
ln -s "$PWD/scripts/powerline-render" tests/vterm/path
|
||||
ln -s "$PWD/scripts/powerline-config" tests/vterm/path
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ def test_expected_result(p, expected_result, cols, rows, print_logs):
|
|||
for key, text in result
|
||||
))
|
||||
print(shesc_result)
|
||||
print(result)
|
||||
print('Expected:')
|
||||
shesc_expected_result = ''.join((
|
||||
'{0}{1}\x1b[m'.format(cell_properties_key_to_shell_escape(key), text)
|
||||
|
@ -95,6 +96,17 @@ def test_expected_result(p, expected_result, cols, rows, print_logs):
|
|||
return False
|
||||
|
||||
|
||||
def get_expected_result(tmux_version, expected_result_old, expected_result_1_7=None, expected_result_new=None, expected_result_2_0=None):
|
||||
if tmux_version >= (2, 0) and expected_result_2_0:
|
||||
return expected_result_2_0
|
||||
elif tmux_version >= (1, 8) and expected_result_new:
|
||||
return expected_result_new
|
||||
elif tmux_version >= (1, 7) and expected_result_1_7:
|
||||
return expected_result_1_7
|
||||
else:
|
||||
return expected_result_old
|
||||
|
||||
|
||||
def main(attempts=3):
|
||||
vterm_path = os.path.join(VTERM_TEST_DIR, 'path')
|
||||
socket_path = 'tmux-socket'
|
||||
|
@ -165,8 +177,8 @@ def main(attempts=3):
|
|||
'POWERLINE_CONFIG_PATHS': os.path.abspath('powerline/config_files'),
|
||||
'POWERLINE_COMMAND': 'powerline-render',
|
||||
'POWERLINE_THEME_OVERRIDES': (
|
||||
'default.segments.right=[{"type":"string","name":"s1","highlight_groups":["cwd"]}];'
|
||||
'default.segments.left=[{"type":"string","name":"s2","highlight_groups":["background"]}];'
|
||||
'default.segments.right=[{"type":"string","name":"s1","highlight_groups":["cwd"],"priority":50}];'
|
||||
'default.segments.left=[{"type":"string","name":"s2","highlight_groups":["background"],"priority":20}];'
|
||||
'default.segment_data.s1.contents=S1 string here;'
|
||||
'default.segment_data.s2.contents=S2 string here;'
|
||||
),
|
||||
|
@ -175,8 +187,47 @@ def main(attempts=3):
|
|||
},
|
||||
)
|
||||
p.start()
|
||||
sleep(2)
|
||||
expected_result_2_0 = (
|
||||
sleep(5)
|
||||
tmux_version = get_tmux_version(get_fallback_logger())
|
||||
expected_result = get_expected_result(tmux_version, expected_result_old=(
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '),
|
||||
(((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '),
|
||||
(((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 127),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '),
|
||||
), expected_result_new=(
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '),
|
||||
(((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '),
|
||||
(((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 127),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '),
|
||||
), expected_result_2_0=(
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '),
|
||||
|
@ -195,62 +246,69 @@ def main(attempts=3):
|
|||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 128),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '),
|
||||
)
|
||||
expected_result_new = (
|
||||
))
|
||||
ret = None
|
||||
if not test_expected_result(p, expected_result, cols, rows, not attempts):
|
||||
if attempts:
|
||||
pass
|
||||
# Will rerun main later.
|
||||
else:
|
||||
ret = False
|
||||
elif ret is not False:
|
||||
ret = True
|
||||
cols = 40
|
||||
p.resize(rows, cols)
|
||||
sleep(5)
|
||||
expected_result = get_expected_result(tmux_version, (
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * cols),
|
||||
), expected_result_1_7=(
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' <'),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'sh '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '),
|
||||
(((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '),
|
||||
(((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here ')
|
||||
), expected_result_new=(
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' <'),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), 'sh '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '),
|
||||
(((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '),
|
||||
(((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here ')
|
||||
), expected_result_2_0=(
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), '<'),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '),
|
||||
(((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '),
|
||||
(((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 127),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '),
|
||||
)
|
||||
expected_result_old = (
|
||||
(((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '),
|
||||
(((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '),
|
||||
(((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '),
|
||||
(((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '),
|
||||
(((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '),
|
||||
(((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 127),
|
||||
(((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '),
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '),
|
||||
)
|
||||
tmux_version = get_tmux_version(get_fallback_logger())
|
||||
if tmux_version >= (2, 0):
|
||||
expected_result = expected_result_2_0
|
||||
elif tmux_version >= (1, 8):
|
||||
expected_result = expected_result_new
|
||||
else:
|
||||
expected_result = expected_result_old
|
||||
(((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here ')
|
||||
))
|
||||
if not test_expected_result(p, expected_result, cols, rows, not attempts):
|
||||
if attempts:
|
||||
pass
|
||||
# Will rerun main later.
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
ret = False
|
||||
elif ret is not False:
|
||||
ret = True
|
||||
if ret is not None:
|
||||
return ret
|
||||
finally:
|
||||
check_call([tmux_exe, '-S', socket_path, 'kill-server'], env={
|
||||
'PATH': vterm_path,
|
||||
|
|
Loading…
Reference in New Issue