cleaner if and avoid exception

This commit is contained in:
Guillaume Leclerc 2016-05-12 19:12:05 +02:00
parent 89bb5c4e39
commit e0866df6bb

View file

@ -2,7 +2,7 @@
"""Completer implementation to use with prompt_toolkit."""
import os
import builtins
import prompt_toolkit
import xonsh
from prompt_toolkit.layout.dimension import LayoutDimension
from prompt_toolkit.completion import Completer, Completion
@ -42,6 +42,10 @@ class PromptToolkitCompleter(Completer):
def reserve_space(self):
cli = builtins.__xonsh_shell__.shell.prompter.cli
if xonsh.shell.prompt_toolkit_version().startswith("1.0"):
# This is the layout for ptk 1.0
window = cli.application.layout.children[0].content.children[1]
else:
#TODO remove after next prompt_toolkit release
try:
#old layout to be removed at next ptk release
@ -50,10 +54,6 @@ class PromptToolkitCompleter(Completer):
#new layout to become default
window = cli.application.layout.children[1].content
# This is the layout for ptk 1.0
if prompt_toolkit.__version__.startswith("1."):
window = cli.application.layout.children[0].content.children[1]
if window and window.render_info:
h = window.render_info.content_height
r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')