On Wed, Mar 25, 2020 at 9:37 AM DL Neil via Python-list
<python-list@python.org> wrote:
>
> As you observe, the problem with terminal emulators is the extent of
> their emulation and the degree of adoption of their 'extended features'!
>
> My concern grows because of the need (I assume) for the URL to be
> 'clickable', not merely 'complete' and 'unadorned' (no added hyphen
> rendering it useless).

A complete URL is clickable. If I print out the string
"https://example.com/"; then it can be right-clicked and copied, or
sent to a browser, or whatever. (Technically I don't need it to be
"clickable", but the terminal emulator has to recognize it as a link.)
FTR I'm using XFCE and xfce4-terminal, although I think everything
applies to most of the popular terminal emulators.

The problem is that a long URL will wrap. So my options are:

1) Let it wrap, violating the indentation
2) Break it, which stops it from being clickable
3) Get help from the terminal emulator

> Despite the almost-irresistible urge to prove that I'm a class-y guy
> [albeit with a warped sense of humor], I'm warming to the 'partition'
> suggestion:
> - the output from textwrap.wrap() is a list of strings,
> - we are talking about fixed-length lines denominated in characters,
> - locating a[ll] URI (from a sub-set of schemes, eg "http", "https",
> ...) is a well-worn path.

I'm not bothered too much by specific schemes. If a word matches the
regex ^[a-z]+:// then I'll call it a URL.

> Thus (simplified to assume the presence of exactly one URI!!!):
> - textwrap the first partition
> - len( URI )
> - it becomes trivial to ascertain if the URL might append the last line
> (of the first 'wrapped' partition)
> - failing that, the URI must start a new line (by defn)
> - if it is 'too long', ie would be wrapped by textwrap, treat it separately,
> - conversely, prepend the URI to the third partition,
> - text-wrap the third partition,
> - assemble the tweet-display.
>

Hmm. So, basically, manual reimplementation of parts of textwrap. I'll
hold that thought for later... if it's possible to just change the
regex and keep the code unchanged, I'll prefer that, but this is a
possibility. Thanks.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to