-
Notifications
You must be signed in to change notification settings - Fork 119
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
RFC: UI fixes for --compact mode #693
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
module Development.Shake.Internal.Progress( | ||
progress, | ||
progressSimple, progressDisplay, progressTitlebar, progressProgram, | ||
ProgressEntry(..), progressReplay, writeProgressReport -- INTERNAL USE ONLY | ||
ProgressEntry(..), RawProgress(..), progressReplay, writeProgressReport, progressRaw -- INTERNAL USE ONLY | ||
) where | ||
|
||
import Control.Applicative | ||
|
@@ -205,12 +205,26 @@ message input = liftA3 (,,) time perc debug | |
-- while time left is calculated by scaling @remaining@ by the observed work rate in this build, | ||
-- roughly @done / time_elapsed@. | ||
progressDisplay :: Double -> (String -> IO ()) -> IO Progress -> IO () | ||
progressDisplay sample disp prog = do | ||
disp "Starting..." -- no useful info at this stage | ||
progressDisplay sample disp prog = progressRaw sample (disp . format) prog | ||
where format Starting = "Starting..." | ||
format (Finished t) = "Finished in " ++ showDuration t | ||
format (Executing p t secs perc done todo predicted) = | ||
"Running for " ++ showDurationSecs t ++ " [" ++ show done ++ "/" ++ show todo ++ "]" ++ | ||
", predicted " ++ predicted ++ | ||
maybe "" (", Failure! " ++) (isFailure p) | ||
|
||
data RawProgress | ||
= Starting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need a special |
||
| Finished Double | ||
| Executing Progress Double Double Double Int Int String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running or Executing? I tend to think of executing as more "calling exec". I'm happy with whatever you prefer though. |
||
|
||
progressRaw :: Double -> (RawProgress -> IO ()) -> IO Progress -> IO () | ||
progressRaw sample disp prog = do | ||
disp Starting -- no useful info at this stage | ||
time <- offsetTime | ||
catchJust (\x -> if x == ThreadKilled then Just () else Nothing) | ||
(loop time $ message echoMealy) | ||
(const $ do t <- time; disp $ "Finished in " ++ showDuration t) | ||
(const $ do t <- time; disp $ Finished t) | ||
where | ||
loop :: IO Double -> Mealy (Double, Progress) (Double, Double, String) -> IO () | ||
loop time mealy = do | ||
|
@@ -221,10 +235,7 @@ progressDisplay sample disp prog = do | |
-- putStrLn _debug | ||
let done = countSkipped p + countBuilt p | ||
let todo = done + countUnknown p + countTodo p | ||
disp $ | ||
"Running for " ++ showDurationSecs t ++ " [" ++ show done ++ "/" ++ show todo ++ "]" ++ | ||
", predicted " ++ formatMessage secs perc ++ | ||
maybe "" (", Failure! " ++) (isFailure p) | ||
disp $ Executing p t secs perc done todo (formatMessage secs perc) | ||
loop time mealy | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
-- | Get terminal size with @ioctl@ | ||
module Development.Shake.Internal.TermSize ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use https://hackage.haskell.org/package/terminal-size? |
||
getTermSize | ||
) where | ||
|
||
#ifdef WIN32 | ||
getTermSize :: IO (Int, Int) | ||
getTermSize = return (25,80) | ||
#else | ||
|
||
import Foreign | ||
import Foreign.C.Error | ||
import Foreign.C.Types | ||
|
||
#include <sys/ioctl.h> | ||
#include <unistd.h> | ||
|
||
-- Trick for calculating alignment of a type, taken from | ||
-- http://www.haskell.org/haskellwiki/FFICookBook#Working_with_structs | ||
#let our_alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__) | ||
|
||
-- The ws_xpixel and ws_ypixel fields are unused, so I've omitted them here. | ||
data WinSize = WinSize { wsRow, wsCol :: CUShort } | ||
|
||
instance Storable WinSize where | ||
sizeOf _ = (#size struct winsize) | ||
alignment _ = (#our_alignment struct winsize) | ||
peek ptr = do | ||
row <- (#peek struct winsize, ws_row) ptr | ||
col <- (#peek struct winsize, ws_col) ptr | ||
return $ WinSize row col | ||
poke ptr (WinSize row col) = do | ||
(#poke struct winsize, ws_row) ptr row | ||
(#poke struct winsize, ws_col) ptr col | ||
|
||
foreign import ccall "sys/ioctl.h ioctl" | ||
ioctl :: CInt -> CInt -> Ptr WinSize -> IO CInt | ||
|
||
-- | Return current number of (rows, columns) of the terminal. | ||
getTermSize :: IO (Int, Int) | ||
getTermSize = | ||
with (WinSize 0 0) $ \ws -> do | ||
throwErrnoIfMinus1 "ioctl" $ | ||
ioctl (#const STDOUT_FILENO) (#const TIOCGWINSZ) ws | ||
WinSize row col <- peek ws | ||
return (fromIntegral row, fromIntegral col) | ||
#endif |
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.
Why is this part in there? Unrelated change that sneaked in?