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

K8s contexts breaks line wrapping in console #703

Open
natehouk opened this issue Apr 19, 2022 · 8 comments
Open

K8s contexts breaks line wrapping in console #703

natehouk opened this issue Apr 19, 2022 · 8 comments
Labels
bug needs information More information needed from the reporter

Comments

@natehouk
Copy link

K8s contexts breaks line wrapping in console. For example, if you have a long multi-line command in your history, and you press Up arrow to retrieve it, the multi-line will be written onto a single line that wraps back onto itself. This can be reproduced. It is probably due to the length of the prompt not being known by bash due to incorrectly escaped characters in the K8s context prompt text.

Disabling K8s context by setting LP_ENABLE_KUBECONTEXT=0 fixes the issue.

Shell:

[natehouk:~] $ echo $BASH_VERSION
5.1.16(1)-release

Operating system:

[natehouk:~] $ uname -a
Linux polar 5.17.3-arch1-1 #1 SMP PREEMPT Thu, 14 Apr 2022 01:18:36 +0000 x86_64 GNU/Linux

[natehouk:~] $ lsb_release -a
LSB Version: n/a
Distributor ID: Arch
Description: Arch Linux
Release: rolling
Codename: n/a

Liquidprompt version:

f6a841c

Steps to Reproduce

  1. Enable LP_ENABLE_KUBECONTEXT=1
  2. Set a ~/.kube/config such that you have a context loaded and the prompt shows the K8s context
  3. Enter a multi-line command, then use Up arrow to retrieve the command and note how the line wrapping is broken.

Expected Behavior

Line wrapping should not be broken. Multi-line command should be printed on multiple lines and not have unexpected behavior when moving through the command with the cursor.

Current Behavior

Multiple lines are printed incorrectly on a single line.

Possible Solution

Correct escaping in K8s context prompt text.

@natehouk natehouk added the bug label Apr 19, 2022
@Rycieos
Copy link
Collaborator

Rycieos commented Apr 20, 2022

This seems similar or even related to #511 and #547. Look specifically at 547, I have put a lot of effort into tracking that one down. I'd love to squash all these bugs at once.

I cannot reproduce this. Please provide some specific reproduction steps, like the actual command you use to break the prompt, and the output of printf '%q\n' "$PS1".

And what happens if you set LP_MARK_KUBECONTEXT=O, or any other ASCII character?

@Rycieos Rycieos added the needs information More information needed from the reporter label Apr 20, 2022
@natehouk
Copy link
Author

I am not sure why I would set LP_MARK_KUBECONTEXT= to any other ASCII character, but when I try setting it to "o" for example, then nothing works, presumably because the config doesn't compile.

I can reproduce this by simply enabling the kubernetes context and (and having a cluster configured) and then typing anything that is longer than the line.

Here is a screenshot:

liquidprompt

@Rycieos
Copy link
Collaborator

Rycieos commented Apr 21, 2022

I am not sure why I would set LP_MARK_KUBECONTEXT= to any other ASCII character

To test if the default character, (U+2388), is the problem. It's a multibyte character, which might be what Bash is having issues with.

but when I try setting it to "o" for example, then nothing works, presumably because the config doesn't compile.

That does not make any sense. You can set LP_MARK_KUBECONTEXT to literally any string, and Liquidprompt will just insert that string into PS1 in the right place.

A screenshot isn't very helpful, I understand what the issue is. But if I can not reproduce it and/or boil it down to the simplest reproduction steps, I can't fix it.

So again, please help provide some specific reproduction steps:

  • the actual command you use to break the prompt (ex: echo "this is my command").
  • the output of printf '%q\n' "$PS1".

@natehouk
Copy link
Author

Apologies, I confused LP_MARK_KUBECONTEXT with LP_ENABLE_KUBECONTEXT. I will try out the suggestion and report back.

@natehouk
Copy link
Author

You were correct. When setting LP_MARK_KUBECONTEXT="X" everything works correctly. It seems like the ⎈ is causing the problem.

liquidprompt-2

@Rycieos
Copy link
Collaborator

Rycieos commented Apr 24, 2022

I still can't reproduce this, even with the same Bash version.

I'm going to need more info:

  • Your terminal emulator and version.
  • Output of printf '%q\n' "$PS1".
  • The width of your terminal when it breaks (echo $COLUMNS).

@natehouk
Copy link
Author

natehouk commented Apr 24, 2022

This is using the terminal emulator Terminator v2.1.1

θ70° [natehouk:~] [⎈lke57809-ctx] $ printf '%q\n' "$PS1" 
$'\316\270\\[\E[31m\\]70\302\260\\[\E(B\E[m\\] [natehouk\\[\E(B\E[m\\]\\[\E[32m\\]:\\[\E(B\E[m\\]\\[\E(B\E[m\E[1m\\]~\\[\E(B\E[m\\]] [\342\216\210\\[\E[36m\\]lke57809-ctx\\[\E(B\E[m\\]] \\[\E[1m\\]$\\[\E(B\E[m\\] '
θ70° [natehouk:~] [⎈lke57809-ctx] $ echo $COLUMNS
80

@Rycieos
Copy link
Collaborator

Rycieos commented May 2, 2022

Was finally able to get Terminator to build (man that was a pain. The install docs are terrible, and the Python ecosystem is just the worst right now). So running on Terminator 2.1.1 and Bash 5.1.16, I am not able to reproduce this. I guess the next thing to try is an Arch Linux VM?

I am not sure that will help though. I'm guessing it is something environment specific, or maybe readline version based?

Try running Bash with nothing loaded with env -i /bin/bash --norc --noprofile. You will have to load Liquidprompt manually after that. Can you still reproduce it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs information More information needed from the reporter
Projects
None yet
Development

No branches or pull requests

2 participants