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

detect terminal width and use it for pretty-printed output #3395

Merged
merged 19 commits into from
Sep 12, 2017

Conversation

kadoban
Copy link
Collaborator

@kadoban kadoban commented Aug 30, 2017

Related to #2650, detect the width of the terminal and use it for proper output.

  • Any changes that could be relevant to users have been recorded in the ChangeLog.md
  • The documentation has been updated
  • Test terminal detection more, ideally on several OSes
  • Use detected width when pretty-printing
  • Allow user configuration of widths (hardcode a width, set min and max?, disable detection?)
  • Make sure this doesn't screw up log files too badly
  • Figure out why hsc2hs isn't available on appveyor, or if that's just a CI problem

Note: this current implementation is only ever going to work on POSIX. I don't currently have ability to dev/test on windows, though it appears that there are APIs that could give this info if anyone else wants to sub that in.

Testing: It seems to work fine on all of the OSes I have. Unfortunately, that's a pretty unrepresentative set of OSes. I mostly have linux variants and one BSD I tried on and it worked fine. I don't have access to OSX or Windows really.

If anyone can, testing on other OSes would really be good. Windows won't do any terminal detection, but the command-line option should work.

Log output doesn't seem to be messed up by this. If anyone can verify that'd be nice though. I don't use logs really ever, so I'm hoping I looked the right places.

Docs: I couldn't find any places the docs actually need to be updated. The stack --help output is correct already obviously.

@kadoban
Copy link
Collaborator Author

kadoban commented Aug 30, 2017

So far I just have the raw terminal width detection in. It seems to work fine but needs more testing, and obviously I need to put in the parts that actually use it, and some configurability as well.

@kadoban
Copy link
Collaborator Author

kadoban commented Aug 30, 2017

Hmm, is that hsc2hs error on appveyor a CI problem or an actual problem, anyone know offhand? I think it's just saying that the executable doesn't exist, but I'm not sure the right way to fix that.

@mgsloan
Copy link
Contributor

mgsloan commented Aug 30, 2017

LGTM sofar, though I am not really all that experienced with FFI

@kadoban
Copy link
Collaborator Author

kadoban commented Aug 30, 2017

Thanks! Yeah, this is my first time doing C FFI (done a tad of JS FFI), so there's a lot of finger crossing going on. But it seems pretty painless so far surprisingly.

Edit: Heh, I say that and then the appveyor CI still fails :( Oh well, hopefully that's an easy fix later.

@kadoban
Copy link
Collaborator Author

kadoban commented Aug 31, 2017

This basically seems to be working, yay. Need to clean up and test a decent amount still though.

@@ -216,3 +218,9 @@ compilerOptionsCabalFlag Ghcjs = "--ghcjs-options"

ghcColorForceFlag :: String
ghcColorForceFlag = "-fdiagnostics-color=always"

minTerminalWidth :: Int
minTerminalWidth = 20
Copy link
Contributor

Choose a reason for hiding this comment

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

20 is really small. I think 40 might be a better minimum. Reasoning is that the user might resize their terminal.

I think having a max makes sense too, it's unpleasant to read a whole paragraph of text stretched on a line. Maybe 200 chars? Of course, an answer to that would be why doesn't the user resize their terminal. I use XMonad, though, so if I open up a terminal on a 4k display, I probably don't really want paragraphs to be single lines, though that does happen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I wasn't sure what to do for a min. 40 does look more reasonable. I'm indifferent to a maximum personally, but that reasoning seems to make sense, I'll throw it in.

Hm, I just noticed that I'm doing the checking all wrong too, it's only checking the user-supplied one, and it's just ignoring it completely if it's too small. Should probably just clip to the allowed range if it's outside it. I'll redo that part, heh.

stack.cabal Outdated
@@ -268,6 +268,7 @@ library
, store-core >= 0.4 && < 0.5
, annotated-wl-pprint
, file-embed >= 0.0.10
build-tools: hsc2hs >= 0.68
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this even correct? It doesn't seem to help the appveyor problem, but maybe it's supposed to be there anyway?

I've never really used build-tools before, and I also can't tell if hsc2hs is part of GHC and thus doesn't need to be listed here or what.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, could be that hsc2hs needs to be added to stackage. For now, adding stack install hsc2hs to the travis script should fix the issue. Adding hsc2hs to extra-deps might help, as it would specify a version to install, not 100% sure if that works, it used to not, but that may have been fixed.

Copy link
Collaborator Author

@kadoban kadoban Aug 31, 2017

Choose a reason for hiding this comment

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

Oh, nice catch, it isn't in stackage. Appveyor seems to be the only one that doesn't like it.

Huh, I'm getting other travis CI errors that look like actual code problems. Wacky that I'm not getting it locally though, I'll have to look into that. Edit: fixed travisCI

- implement a maximum
- clip to the range instead of just ignoring invalid values
- actually check the detected width too, not just a user-supplied one
Hopefully this will get it built automatically on appveyor when
we need it.
We're not actually using it on windows anyway, and it's causing
problems on appveyor.
@kadoban kadoban force-pushed the terminal-detection branch from 8fa2bc0 to c8c4f94 Compare August 31, 2017 21:19
@kadoban kadoban changed the title [WIP] detect terminal width and use it for pretty-printed output detect terminal width and use it for pretty-printed output Aug 31, 2017
@kadoban
Copy link
Collaborator Author

kadoban commented Aug 31, 2017

Once this goes in, I'll make an issue in the tracker for Windows not doing terminal detection, just as a reminder. I figure someone on windows will care enough eventually.

@decentral1se
Copy link
Member

Is this ready to merge then? Serious effort @kadoban!

@mgsloan
Copy link
Contributor

mgsloan commented Sep 12, 2017

This looks good to me, is it ready for merge @kadoban ?

@kadoban
Copy link
Collaborator Author

kadoban commented Sep 12, 2017

Thanks! Yep, as far as I know it's good to go.

I'm a bit uncertain about other OSes still, like OSX (no way to test that), but I'm as close to sure it should work as I can be.

@mgsloan
Copy link
Contributor

mgsloan commented Sep 12, 2017

I bet it will work fine on osx. Merging!

@mgsloan mgsloan merged commit f6bea15 into commercialhaskell:master Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants