On Sun, Feb 25, 2018 at 01:06:15PM -0500, Antoine Beaupré wrote:
> On 2018-02-25 02:29:28, Adam Borowski wrote:
> >> undertime prints terminal escape sequences to pipes and files.
> >
> > There are two types of escape sequences here:
> >
> > • SGR.  These make sense, as undertime uses color to convey its output.
> > A plain text interface would be a reasonable request but is probably a 
> > feature
> > (anarcat: you can detect non-terminals by !isatty(1) ).
> 
> What's SGR? Do you mean:
> 
> https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters

Yeah -- "\e[…m", in your case bold and colors.

> If so, could you expand on what you would expect this would look like?
> keep in mind that undertime doesn't generate those escape sequences on
> its own: it passes a list of rows to the terminaltables library and lets
> it handle that on its own.

I guess that skipping colors would work then.

> undertime is written in python, so:
> 
> no Python documentation found for 'isatty'
> 
> There is, of course, os.isatty():
> 
> https://docs.python.org/3/library/os.html#os.isatty

Yeah, using Python is merely a penance rather than a crime (unlike, say,
node.js), so usual POSIX interfaces are obvious to find.

> ..and sys.stdout.isatty(). But isn't this something that should be
> handled by the underlying terminaltables library?

I think most low- and mid-level libraries assume that the program does such
logic rather than relying on the library.  In your case, I'd recommend
defaulting to --colors/--no-colors based on isatty(1) -- this is what the
vast majority of programs that use colors for highlighting do.

The difference in doing this yourself is, if you decide to convey
information that you currently give via colors by some other means (such as
a '*') in plain-text output, you don't need to rely on an interface the
library might or might not provide.

And, it takes a single line of code to default --colors/--no-colors to
isatty.  Which is less than what we already spent on this discussion. :)

> > • VT100 line drawing.  These codes shouldn't be used these days: there's a
> > debate whether they're allowed within an UTF-8 locale, as the relevant
> > standard seems to say no.
> >
> > Also, tools like "less -R", which support colors well, don't handle such
> > line drawing.  This includes my ansi2txt and ansi2html

> So this sounds like a total nightmare that makes timezones and GUI
> toolkits look like an awesome time at the beach. In fact, this makes me
> want to rewrite the whole thing to *not* output on the terminal and
> instead use Kivy or some other gaming engine to output a beautiful
> interface like http://worldchatclock.com/ instead.

That's nowhere near the worst quirk of Unix terminals -- we're talking about
something that has evolved with direct ancestry of 19th century design.

On the other hand, a terminal interface is massively more useful for our
kind of folks than some pretty but fragile web stuff.

> Again: I didn't write those escape sequences, I just use terminaltables
> blindly because it supports colors neatly. I have found other
> alternatives, documented in the source here:

> Let me know when you're done. :p More seriously, underline is
> (deliberately) a small program: 200 lines, and half of that is usage
> instructions, comments and metadata.

> I forwarded this upstream, and, for what it's worth, there are *three*
> pull requests to implement unicode tables in terminaltables
> already. Someone(tm) needs to review those and patch terminaltables in
> Debian to include the right fix.

Yeah, it's reasonable to punt this logic there.  Unlike colors/no-colors,
such implementation details have no place in a program like yours, it's the
library what's supposed to know such things.

> I'm tempted to just reassign this bug and #891378 to the
> python-terminaltables project, because it's not really a bug in
> undertime itself...

Exactly.  We have two issues here, though, so I'd recommend doing the
--no-colors part yourself (resulting in no SGR), and reassign line drawing
(VT100/Unicode).


Meow!
-- 
⢀⣴⠾⠻⢶⣦⠀ 
⣾⠁⢠⠒⠀⣿⡁ A dumb species has no way to open a tuna can.
⢿⡄⠘⠷⠚⠋⠀ A smart species invents a can opener.
⠈⠳⣄⠀⠀⠀⠀ A master species delegates.

Reply via email to