-
Notifications
You must be signed in to change notification settings - Fork 841
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
mgsloan
merged 19 commits into
commercialhaskell:master
from
kadoban:terminal-detection
Sep 12, 2017
Merged
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c111b33
create stub `System.Terminal` module
kadoban da253f2
prepare for protecting windows from POSIX-only term detection
kadoban 0cf7ba9
create type to store C's winsize struct
kadoban 2910f35
implement `getTerminalWidth`
kadoban 72de492
wrap more stuff in windows check
kadoban b2cb946
require hsc2hs build tool
kadoban 2855cbc
make low-level print funcs take terminal width as a param
kadoban 54ad0f3
add a command-line option to set/override the terminal width
kadoban 83a018e
add the term width stuff to LogOptions
kadoban d95758c
replace terminal width numbers with named constants
kadoban a200489
use the terminal width when pretty-printing
kadoban 9d10d34
improve terminal-width min/max behavior
kadoban cc94e9e
use a more reasonable minimum terminal width
kadoban 0f607b3
fix test compilations due to terminal width
kadoban baf9a6b
pin hsc2hs as an extra-dep
kadoban 1d5a7bc
manually force appveyor to install hsc2hs first
kadoban 43cd310
stop trying to use hsc2hs on windows
kadoban c8c4f94
document some constants
kadoban e4ba9d9
add term-width changes to the changelog
kadoban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{-# LANGUAGE CPP #-} | ||
#ifndef WINDOWS | ||
{-# LANGUAGE ForeignFunctionInterface #-} | ||
#endif | ||
|
||
module System.Terminal | ||
( getTerminalWidth | ||
) where | ||
|
||
#ifndef WINDOWS | ||
import Foreign | ||
import Foreign.C.Types | ||
|
||
#include <sys/ioctl.h> | ||
#include <unistd.h> | ||
|
||
newtype WindowWidth = WindowWidth CUShort | ||
deriving (Eq, Ord, Show) | ||
|
||
instance Storable WindowWidth where | ||
sizeOf _ = (#size struct winsize) | ||
alignment _ = (#alignment struct winsize) | ||
peek p = WindowWidth <$> (#peek struct winsize, ws_col) p | ||
poke p (WindowWidth w) = do | ||
(#poke struct winsize, ws_col) p w | ||
|
||
foreign import ccall "sys/ioctl.h ioctl" | ||
ioctl :: CInt -> CInt -> Ptr WindowWidth -> IO CInt | ||
#endif | ||
|
||
-- | Get the width, in columns, of the terminal if we can. | ||
getTerminalWidth :: IO (Maybe Int) | ||
#ifndef WINDOWS | ||
getTerminalWidth = | ||
alloca $ \p -> do | ||
errno <- ioctl (#const STDOUT_FILENO) (#const TIOCGWINSZ) p | ||
if errno < 0 | ||
then return Nothing | ||
else do | ||
WindowWidth w <- peek p | ||
return . Just . fromIntegral $ w | ||
#else | ||
getTerminalWidth = pure Nothing | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ifhsc2hs
is part of GHC and thus doesn't need to be listed here or what.There was a problem hiding this comment.
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.There was a problem hiding this comment.
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