jarun/ddgr

[macOS] Prompt escape sequences error

paxperscientiam opened this issue · 8 comments

Hey there @jarun , great project!

Small bug i've noticed is that, after conducting a search, the ddgr prompt is a bit funny due to possible syntax error.

On my machine I get this literal string for the prompt: [7mddgr (? for help)[0m

The code, should be something like this: '\e[7mddgr (? for help)\e[0m

$ echo -e '\e[7mddgr (? for help)\e[0m'
=> ddgr (? for help)
jarun commented

On my machine

Details please? OS, terminal, locale?

It's as per the color coding guidelines already so I am expecting your terminal has something in play here.

jarun commented

I believe this is the same as jarun/googler#203. We had a patch in and then we had to revert it back due to glaring side-effects. At this point we don't have any other graceful way to handle it. One way would be to disable readline but that would be telling on user experience.

jarun commented

What do you see if you run the following python3 snippet?

#!/usr/bin/env python3
import readline

message = 'ddgr (? for help)'
prompt = '\x1b[7m' + message + '\x1b[0m' + ' '
try:
    cmd = input(prompt)
except EOFError:
    sys.exit(0)
jarun commented

Given this is the second time this issue is reported, I am working on a way to handle this. I will add the support for an environment variable, which, if defined, will render a plain prompt. Even if the issue is not widespread, it can put-off several users... so it's better to have a way to avoid it.

Hey @jarun , I know I meant to response ... but obviously I forgot!

Running your snippet with python3 yield this:

7mddgr (? for help)[0m

EDIT: I just tried the dev release and the result is the same.

EDIT2: To be perfectly clear, it's definitely not the terminal emulator (iTerm2) nor the environment. The escape sequences are interpreted properly when used in bash.

message='ddgr (? for help)'
printf '\x1b[7m%s\x1b[0m' "${message}"

This gives the expected inverted colored face/background.

EDIT: @jarun solved! I did not have the proper python readline extension installed. So...maybe you just need to test for that?

jarun commented

We have introduced a new env var to disable the prompt color:

export DISABLE_PROMPT_COLOR=1

It should work in all cases whatever the readline version is.

With that said, one could set an alias like this:
alias ddgr='DISABLE_PROMPT_COLOR=1 ddgr'