Open tkapias opened 8 months ago
Thanks for your report. I can confirm what you describe but I think the underlying problem is thus:
print()
indeed prints a newline at the end (docs), the input()
function on the other hand
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.
input()
returns and then later on print()
s some stuff. That is when hl sees the next newline and starts to output stuff again.I do not really like the code changes you propose for these reasons:
ask()
function is not fixed. And if we refactor some output somewhere it might break again. So we need a decision first. Do we constraint khard to only output full lines so that we can do something with the output? (And what happens with khard edit
calling e.g. nvim?)builtins.input
like so def input(prompt): return builtins.input(prompt+"\n")
and only use that in khard
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