Patching input prompt flushing to redirect khard show
to a highlighter
#333
Labels
waiting
Waiting for more information
khard show
to a highlighter
#333
Introduction
Khard being console oriented is nice, but I miss some coloration, at least in
khard show
.For that purpose I use hl, it colorizes any output according to a simple configuration based on regular expressions.
But, when piping
khard show
tohl
there is an issue that I described in hl's repo, here.I did open it at hl first, because piping to
cat
did not show the same issue, but I later wrote a patch for Khard which I'd like to share and, I think, also enhance the output format.Issue
In short, the user input prompt string is not flushed before the user answer, but after, when redirected to hl, and without a newline.
See like the index number inputed is above the prompt, which appear later on the same line as the pretty vcard first line.
Solution
Normally python should flush every print with a newline. I suspected that piping to hl breaks this behaviour, so I tried to force it by using
flush=True
in different places ininteractive.select
, but it does not change the result.So I added manually a newline to the prompt string.
I also added more
print()
afterif index > 0:
to erase the input prompt after the answer, rewrite the selected index number and put a newline for clarityI find this result more pleasing, even without hl.
helpers/interactive.py
:Extra
For those interested, I use the combo
khard show
/hl
in a bash function:And my hl configuration for khard is currently this (
~/.config/hl/config.d/hl_khal.cfg
):You may need to export some path for the hl config files, like this:
export HL_CONF=$HOME/.config/hl/config.d:/etc/hl/config.d
The text was updated successfully, but these errors were encountered: