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

Text bleeds from one widget to another #100

Closed
Laanan opened this issue Mar 16, 2021 · 6 comments
Closed

Text bleeds from one widget to another #100

Laanan opened this issue Mar 16, 2021 · 6 comments
Labels
Bug Something isn't working Core Add for issues having to do with core functions Renderer Issue has to do with Renderer
Milestone

Comments

@Laanan
Copy link

Laanan commented Mar 16, 2021

Describe the bug
I am making a simple IMAP client. I have two widgets, one for listing mailboxes, and one for listing messages in the mailboxes.
When the messages are displayed, parts of the messages bleed over into the mailboxes widget to the left. When I change focus back to the mailboxes widget, the bled over messages vanish, and when I refocus to the messages widget, they return.

Expected behavior
I expect the text in the widget to stay within the bounds of the widget.

Environment:

  • OS: Debian 10
  • Terminal: xfce4-terminal 0.8.7.4

** Sidebar/newbie question**
Would someone kindly explain how I can see the output of a print(variable) or the response from the IMAP server in a separate buffer/screen than the one displaying the CUI? I tend to use Screen and flip flop back and forth between my editor (Kaa Edit) and a venv shell from which I execute the script. Any advice would be greatly appreciated, and sorry for the stupid question. Just trying to be better able to assess what is going on inside my script when it is "working."

@Laanan Laanan added the Bug Something isn't working label Mar 16, 2021
@jwlodek
Copy link
Owner

jwlodek commented Mar 16, 2021

Do you have your code on github or somewhere where I could take a look? It shouldn't be bleeding over like that obviously, so I'm wondering what could be causing it.

As for your other question, I've been working on a feature where you can display logging utilities as an overlay over the UI. But for now, the way you could do it is to write to a file, and have another window that simply watches the file and prints any new messages.

Edit: For future reference the overlay logging message printing is tracked here

@Laanan
Copy link
Author

Laanan commented Mar 16, 2021

Hello,

The UI overlay sounds awesome; in the meantime, I’ll try to implement your workaround.

Yes, here’s the repository: https://github.com/Laanan/Slither/tree/master

if you use your Gmail account, you’ll need an app password. Thanks very much for the response and any help you can provide 👍🏼!

@Laanan
Copy link
Author

Laanan commented Mar 22, 2021

Hi, any chance you were able to take a look at my code?

@jwlodek
Copy link
Owner

jwlodek commented Mar 22, 2021

Yes, sorry, I forgot to follow up on this. Basically, the issue is that for some reason the subjects of certain emails seem to have carriage returns embedded in them, which causes a line break to happen. I added the following to the end of the __init__ method for your TUI wrapper class:

self.master.run_on_exit(lambda : print(str(self.Messages.get_item_list())))

and then, after opening my message box and exiting the TUI, I got the list of subjects, and a few of them (the ones that displayed the issue) had the carriage return in them: \r\n. My guess is this has something to do with the conversion from raw bytes. I'd try the same for you, and if you see them, just having an extra step that purges these carriage returns or newlines that should fix it.

As for why this goes away when the mailbox widget is in focus - the in-focus widget is always drawn last to make sure that any changes made are reflected in it, so likely the overlap is always there, but the widget is drawn over it.

@Laanan
Copy link
Author

Laanan commented Mar 24, 2021

Hi, thank you so much!

Yes, getting rid of those carriage returns did the trick. My next step is to decode any messages coming in as UTF8.
Here's the code (I haven't pushed the commit, yet, because I am still working out the unicode thing):
`for uid, message_data in self.client.fetch(messages, "RFC822").items():
email_message = email.message_from_bytes(message_data[b"RFC822"])
message_list.append(email_message.get("Subject"))

    message_list.reverse()
    message_list_clean = []
    for message in message_list:
        if '\r\n' in message:
            message = message.replace('\r\n', ' ')
        elif '=?UTF-8?' in message:
            message = convert_unicode(message)
    `

@jwlodek jwlodek added this to the v0.1.4 milestone Apr 4, 2021
@jwlodek jwlodek added Core Add for issues having to do with core functions Renderer Issue has to do with Renderer labels Apr 4, 2021
@jwlodek jwlodek mentioned this issue May 29, 2021
3 tasks
@jwlodek
Copy link
Owner

jwlodek commented Oct 2, 2021

At some point this should be revisited to not allow carriage returns by default, but for now I think we can consider this issue closed.

@jwlodek jwlodek closed this as completed Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Add for issues having to do with core functions Renderer Issue has to do with Renderer
Projects
None yet
Development

No branches or pull requests

2 participants