From e0866df6bb70069395a4bb72546e4f3e431a5401 Mon Sep 17 00:00:00 2001 From: Guillaume Leclerc Date: Thu, 12 May 2016 19:12:05 +0200 Subject: [PATCH] cleaner if and avoid exception --- xonsh/ptk/completer.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/xonsh/ptk/completer.py b/xonsh/ptk/completer.py index b4086f509..de7ad704c 100644 --- a/xonsh/ptk/completer.py +++ b/xonsh/ptk/completer.py @@ -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,17 +42,17 @@ class PromptToolkitCompleter(Completer): def reserve_space(self): cli = builtins.__xonsh_shell__.shell.prompter.cli - #TODO remove after next prompt_toolkit release - try: - #old layout to be removed at next ptk release - window = cli.application.layout.children[1].children[1].content - except AttributeError: - #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."): + 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 + window = cli.application.layout.children[1].children[1].content + except AttributeError: + #new layout to become default + window = cli.application.layout.children[1].content if window and window.render_info: h = window.render_info.content_height