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

Line wrapping for "Location" #400

Open
classabbyamp opened this issue Feb 6, 2020 · 9 comments
Open

Line wrapping for "Location" #400

classabbyamp opened this issue Feb 6, 2020 · 9 comments

Comments

@classabbyamp
Copy link

example: http://wttr.in/Paris_1pnF.png

for png generation, can the location line at the bottom be wrapped to the width of the other parts of the image? As it stands now it can lead to inconvenient image dimensions.

@chubin
Copy link
Owner

chubin commented Feb 17, 2020

Yes, it is not good indeed. Should we probably just cut it off?

@classabbyamp
Copy link
Author

Hmm that might remove useful data on occasion. A hard wrap would better I think, but I'm not sure.

@chubin
Copy link
Owner

chubin commented Feb 17, 2020

maybe, we should remove /([0-9]+;)*/from the full location name?
What do you think?

@classabbyamp
Copy link
Author

classabbyamp commented Feb 17, 2020

That could work, but there might still be very long locations just from the words

@chubin
Copy link
Owner

chubin commented Feb 17, 2020

At least for Paris :)

@chubin chubin pinned this issue Mar 22, 2020
@classabbyamp
Copy link
Author

Ok this issue is a bit old but I think I may have somewhat of a solution. Might not be fully complete but I think it's better than it was before. I was thinking it would fit somewhere around here

import textwrap
import re

def _wrap_buf(buf):
    # remove the last line (with the .)
    _buf = buf[:-1]
    # find the max length of everything but the last line (with the the location data)
    cols = max(len(x) for x in _buf[:-1])
    # remove the long string of numbers
    _buf[-1] = re.sub(r"([0-9]+;)+([0-9]+,)? ", "", _buf[-1])
    # use the built-in module textwrap to wrap too-long lines
    for x in _buf:
        if len(x) > cols:
            _buf[-1] = textwrap.fill(_buf[-1], width=cols, replace_whitespace=False, subsequent_indent="  ")
    # re-add that last line
    pbuf.append(" "*(cols+1) + ".")

    return _buf

@chubin
Copy link
Owner

chubin commented Oct 13, 2020

@classabbyamp it looks interesting;

let us test it with several real locations, what do you think?
We should test how it handles different languages,
especially RTL languages, and language with complex writing scripts,
like Devangari etc. If it will not work with them, we could use
this implementation at least for Latin/Cyrillic/Greek scripts

@leaot
Copy link

leaot commented Nov 7, 2021

Here is how it looks for Brasilia, DF, Brazil. I feel that there is a lot of secondary information which can be removed. All the lines "Região ... " could possible be removed. I think something like "place", "city", "state", "ZIP", "country", "coordinates" could minimize the amount of information and probably prevent the need for wrapping.
Regarding language it seems all good (Portuguese-Brazil).

Brasilia

@chubin
Copy link
Owner

chubin commented Nov 7, 2021

I think the location line must be cut by the width of the main view at some appropriate place for that (like a comma, for example). Also, it should be possible to switch the location line fully off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants