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

Make structure of Cmd more obvious in printing #21619

Merged
merged 1 commit into from
May 19, 2017
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Apr 28, 2017

Cmds behave as an array of strings, but for most new users the mental
model they start with is that Cmds are essentially strings. As a result,
people can get easily confused by the interpolation rules around Cmds.
They are quite intuitive when one thinks of them as arrays of strings
(e.g. arrays get expanded, strings get inserted as is), but less so
when thinking of a Cmd as a single string. It seems possible to make
it clearer in printing that there is an underlying structure to the
Cmd by adjusting the way it prints. This one attempt at doing so by
underlining each separate part of the array. Some advantages:

  • The underlining makes it clear that there is something going on
    beyong being a regular string
  • The underlining gets dropped when copying out from a terminal, so
    there's no trouble with pasting it back into a REPL.
  • The underlying structure of clearly visible (each contiguous underline
    is one of the elements of the array of strings).

Examples:
screen shot 2017-04-28 at 2 53 32 pm
screen shot 2017-04-28 at 2 55 37 pm
screen shot 2017-04-28 at 3 21 16 pm

Cmds behave as an array of strings, but for most new users the mental
model they start with is that Cmds are essentially strings. As a result,
people can get easily confused by the interpolation rules around Cmds.
They are quite intuitive when one thinks of them as arrays of strings
(e.g. arrays get expanded, strings get inserted as is), but less so
when thinking of a Cmd as a single string. It seems possible to make
it clearer in printing that there is an underlying structure to the
Cmd by adjusting the way it prints. This one attempt at doing so by
underlining each separate part of the array. Some advantages:
- The underlining makes it clear that there is something going on
  beyong being a regular string
- The underlining gets dropped when copying out from a terminal, so
  there's no trouble with pasting it back into a REPL.
- The underlying structure of clearly visible (each contiguous underline
  is one of the elements of the array of strings).
@ararslan ararslan added the display and printing Aesthetics and correctness of printed representations of objects. label Apr 28, 2017
@tkelman
Copy link
Contributor

tkelman commented Apr 28, 2017

One thing that's persistently annoyed me about the way they print is that the quoting is posix-centric. If you copy-paste the printed output of these into a Windows shell it almost never works as-is.

@@ -104,14 +104,14 @@ function show(io::IO, cmd::Cmd)
print_env = cmd.env !== nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be better to only do this for show(io::IO, ::MIME"text/plain", cmd::Cmd), so as not to affect repr.

Copy link
Contributor

@tkelman tkelman May 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this didn't get addressed, did it?

#22142

@StefanKarpinski
Copy link
Member

One thing that's persistently annoyed me about the way they print is that the quoting is posix-centric. If you copy-paste the printed output of these into a Windows shell it almost never works as-is.

We have to pick some shell standard to emulate and POSIX and Windows CMD are mutually incompatible, so I don't know what you could possibly want here. Only use the intersection of POSIX and CMD features? Everyone seems to agree that CMD is pretty unusable, so doing this seems like an poor idea.

@tkelman
Copy link
Contributor

tkelman commented Apr 29, 2017

No, but at least display things differently on windows so that the output is moderately useful - right now it is not, at all.

@StefanKarpinski
Copy link
Member

StefanKarpinski commented May 1, 2017

If we display commands differently on Windows do we then a) print in a different format than we accept input, or b) change cmd syntax so it's platform-dependent? Both are bad choices – worse than what we do now. If someone wants a usable shell on Windows, they should install a POSIX shell.

@tkelman
Copy link
Contributor

tkelman commented May 1, 2017

We wouldn't print anything we don't accept. But changing the way we normalize the displayed output would make it much more useful without forcing users to install anything extra. Cygwin has been around and done its job for decades, and yet people still don't like using it for whatever reason. Julia isn't a posix-dependent application.

@StefanKarpinski
Copy link
Member

StefanKarpinski commented May 1, 2017

So you're arguing for system-dependent backtick syntax and printing? I.e. on Windows we accept one syntax inside of backticks while on other systems we accept a different, incompatible syntax?

@tkelman
Copy link
Contributor

tkelman commented May 1, 2017

Not system dependent syntax in what we accept, but system dependent output in how we print things so people can copy paste commands from error messages without needing to manually reformat the whole thing.

@StefanKarpinski
Copy link
Member

StefanKarpinski commented May 1, 2017

So you're saying that the output should be system-dependent and we should print Cmd objects in a way that cannot always be pasted back into the REPL to get an equal Cmd object?

@tkelman
Copy link
Contributor

tkelman commented May 2, 2017

So you're saying that the output should be system-dependent

yes

we should print Cmd objects in a way that cannot always be pasted back into the REPL to get an equal Cmd object?

Did not say that. The main change that would get things fairly useful for windows users (who make up a plurality of downloads, remember) would be not using single quotes in how we display Cmd objects on windows, instead escaping any nested double quotes. Implementing totally compatible windows cmd semantics isn't worth doing, but a small tweak to the way these display would be.

Windows does come with a thoroughly usable non-posix shell, but very few people use powershell or even know it's there.

@StefanKarpinski
Copy link
Member

I'm not sure why I had to play a game of 20 questions to get that straightforward answer on what you think we should do. How about making a PR that implements it?

tkelman added a commit that referenced this pull request May 2, 2017
ref #21619 (comment), Windows cmd
doesn't understand single quotes so Julia Cmd objects do not get displayed in a way that
can be copy-pasted on the default command line.
@KristofferC
Copy link
Member

No test = this is now broken. sprint probably needs to grab the context from the input IO.

@vtjnash
Copy link
Member

vtjnash commented Feb 27, 2018

Ironically, I think the commit that made it possible to test this (adding :color to the IO context), is what broke it :)

@KristofferC
Copy link
Member

KristofferC commented Feb 27, 2018

Testing was always possible with the good ol'

old_have_color = Base.have_color
@eval Base have_color = true
try
     # ....
finally
    @eval Base hascolor = $old_have_color
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants