Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab not displayed properly #556

Closed
woile opened this issue Oct 7, 2017 · 4 comments
Closed

Tab not displayed properly #556

woile opened this issue Oct 7, 2017 · 4 comments

Comments

@woile
Copy link

woile commented Oct 7, 2017

Hi guys, I'm trying to add a tab \t to the prompt but it doesn't seem to work. I might be missing something here, is there a way to solve this?

In [3]: prompt('foo\t\tbar')
foo^I^Ibar

I've also tried the unicode representation:

In [13]: prompt('foo\u0009bar')
foo^Ibar

On the other hand \n works fine

In [11]: prompt('foo\nbar')
foo
bar

Sorry if it's something silly, I've been searching in google and reading the docs and I cannot find anything.

Thanks a lot!

@jonathanslenders
Copy link
Member

Hi @woile,

Excuse me for the late reply. I just got married, and I've been offline for a while.

This is not really supported yet. For the input itself, it works, because the TabsProcessor is handling that:
https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/layout/processors.py#L489
For the prompt, there is no such thing (yet). Right now, it's best to calculate the amount of spaces and replace the tabs in the prompt. I hope that works.

@woile
Copy link
Author

woile commented Oct 21, 2017

Congratulations @jonathanslenders !

I'll try calculating tabs, let's see if it's possible.
Regards!

@jonathanslenders
Copy link
Member

Closing this, assuming it's possible by replacing the tabs with spaces. Let me know if that doesn't work.

@asmeurer
Copy link
Contributor

Worth noting that correctly replacing a tab with spaces isn't entirely trivial. Maybe there's a clever regex that can do it. It also wouldn't be the same when the text is copied from the terminal.

The ^I comes from the char mapping in screen.py. If you comment it out, tabs can be inserted into the prompt, but breaks everything because prompt_toolkit doesn't know to calculate the width of the tab character correctly.

(just my observations, I personally don't care if prompt-toolkit can handle literal tab characters or not)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants