Skip to content

Fix issue in returning cursor after print_above()#59

Open
davidavdav wants to merge 2 commits intomeshcore-dev:mainfrom
davidavdav:fix-cursor-mac
Open

Fix issue in returning cursor after print_above()#59
davidavdav wants to merge 2 commits intomeshcore-dev:mainfrom
davidavdav:fix-cursor-mac

Conversation

@davidavdav
Copy link
Copy Markdown

In my terminal (standard macos text terminal) the print_above() does not return to the original place (just after the prompt). The problem is related to a mix of PromptSession and plain print(), the DEC terminal escape sequences move the cursor without prompt_toolkit knowing about this. For me this results in a garbled terminal.

This PR fixes it for me, but I don't have all the use cases, so I don't know what the effect will be in other terminals or OSs.

Full disclosure: the code and analysis was done by cursor (pun not intended). If this is not compliant with your coding policy, feel free to ignore this PR.

@fdlamotte
Copy link
Copy Markdown
Collaborator

Hi, thanks very much for your PR, indeed print_above was written before using prompt toolkit and as I had not seen any bad behaviour I had not changed it.

I have just a little annoyement when using it, channel echoes does not handle emojis correctly. Some of those characters are larger and to accomodate with that I force the position from where path and signal strength are printed.

It should look like :

image

but with your PR it looks like

image

cursor moving is done here :

txt = f"{ANSI_LIGHT_GRAY}{chan_name} {ANSI_DGREEN}{dispmsg+(cars-len(dispmsg))*' '} {ANSI_START}{width-11-len(event.payload['path'])}G{ANSI_YELLOW}[{event.payload['path']}]{ANSI_LIGHT_GRAY}{event.payload['snr']:6,.2f}{event.payload['rssi']:4}{ANSI_END}"

using this part of the formated string : {ANSI_START}{width-11-len(event.payload['path'])}G

If you get this working again, I'll merge the PR ;)

@davidavdav
Copy link
Copy Markdown
Author

OK, great, on my terminal I don't get the [5f] 14.00 -80 right-aligned, in fact, I might not see it at all, is there an option you use to show this, or should it be standard?

I'll see if I can fix the problem. Originally the code split long lines into multiple, but I didn't bother with that, maybe this is causing that behavior

@fdlamotte
Copy link
Copy Markdown
Collaborator

set channel_echoes on activates the channel echoes features, which displays all channel messages received from rx_log with path, snr and rssi

this is handy to follow repeats from the repeaters

@davidavdav
Copy link
Copy Markdown
Author

I tried to fix the right-aligned texts now. You might find incidental over-compensation in the case of wide-characters in node names, but that is probably better than characters spilling over into the next line.

BTW I do see the benefit of the channel echoes, although in my case incoming traffic usually are a few echoes between the same few repeaters in my area --- but I can see that my repeater picks up the most messages

@fdlamotte
Copy link
Copy Markdown
Collaborator

Hi, I'd suggest you to calculate the position of the cursor by calculating the size of the right aligned text (which only depends on the path length and should not contain emojis) and substracting this from the width of the terminal, this has proven more robust for me

Sadly I don't have much time right now :(

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

Successfully merging this pull request may close these issues.

2 participants