,=Q      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPSafeQRQRQRSafeN STUVWXYZ[\]+^_`abcdefghijklmnopqrstuvwxyz{|}STUVWXYZ[\] STUVWXYZ[\]Safe ~ ~ ~2015 Joey Hess <id@joeyh.name> BSD-2-clauseNone35F Buffered output.Values that can be output..A shared global variable for the OutputHandle.Holds a lock while performing an action. This allows the action to perform its own output to the console, without using functions from this module.VWhile this is running, other threads that try to lockOutput will block. Any calls to % and )^ will not block, but the output will be buffered and displayed only once the action is done.%Blocks until we have the output lock.0Tries to take the output lock, without blocking."/Only safe to call after taking the output lock.#%Use this around any actions that use % or )nThis is necessary to ensure that buffered concurrent output actually gets displayed before the program exits.$&Blocks until any processes started by )7 have finished, and any buffered output is displayed. #J calls this at the end; you can call it anytime you want to flush output.%Displays a value to stdout._No newline is appended to the value, so if you want a newline, be sure to include it yourself.{Uses locking to ensure that the whole output occurs atomically even when other threads are concurrently generating output.When something else is writing to the console at the same time, this does not block. It buffers the value, so it will be displayed once the other writer is done.'.Use this to wait for processes started with ) and *, and get their exit status.Note that such processes are actually automatically waited for internally, so not calling this explicitly will not result in zombie processes. This behavior differs from )Wrapper around r that prevents multiple processes that are running concurrently from writing to stdout/stderr at the same time.If the process does not output to stdout or stderr, it's run by createProcess entirely as usual. Only processes that can generate output are handled specially:xA process is allowed to write to stdout and stderr in the usual way, assuming it can successfully take the output lock.MWhen the output lock is held (ie, by another concurrent process, or because % is being called at the same time), the process is instead run with its stdout and stderr redirected to a buffer. The buffered output will be displayed as soon as the output lock becomes free.*Wrapper around  that makes sure a process is run in the foreground, with direct access to stdout and stderr. Useful when eg, running an interactive process.64Adds a value to the output buffer for later display.xNote that buffering large quantities of data this way will keep it resident in memory until it can be displayed. While %N uses temp files if the buffer gets too big, this STM function cannot do so.8VA STM action that waits for some buffered output to become available, and returns it.The function can select a subset of output when only some is desired; the fst part is returned and the snd is left in the buffer.SThis will prevent it from being displayed in the usual way, so you'll need to use < to display it yourself.: Use with 8~ to make it only return buffered output that ends with a newline. Anything buffered without a newline is left in the buffer.<3Emits the content of the OutputBuffer to the Handle If you use this, you should use : to ensure you're the only thread writing to the console.?  !"#$%&'()*+,-./0123456789:;<=>=  !"#$%&'()*+,-./0123456789:;=%&'()*+,- ./0123456789:;<,    !"#$%&'()*+,-./0123456789:;<=> 2015 Joey Hess <id@joeyh.name> BSD-2-clauseNone #$%')*689:<#%)'*$ 689:<2015 Joey Hess <id@joeyh.name> BSD-2-clauseNoneF@1Controls how a region is laid out in the console.<Here's an annotated example of how the console layout works. scrolling...... scrolling...... scrolling...... aaaaaa......... -- Linear bbbbbbbbbbbbbbb -- Linear bbb............ (expanded to multiple lines) ccccccccc...... -- Linear ddd eee fffffff -- [InLine] ffff ggggg..... (expanded to multiple lines)  A shared global list of regions.A shared global console width.CUpdates the list of regions. The list is ordered from the bottom of the screen up. Reordering it will change the order in which regions are displayed. It's also fine to remove, duplicate, or add new regions to the list.(The RegionList TMVar is left empty when N is not running.D2Sets the value to display within a console region.YIt's fine for the value to be longer than the terminal is wide, or to include newlines ('\n'2). Regions expand to multiple lines as necessary.hThe value can include ANSI SGR escape sequences for changing the colors etc of all or part of a region.yOther ANSI escape sequences, especially those doing cursor movement, will mess up the layouts of regions. Caveat emptor.FNAppends the value to whatever was already on display within a console region.HhRuns the action with a new console region, closing the region when the action finishes or on exception.I&Opens a new console region for output.JSTM version of Il. Allows atomically opening multiple regions at the same time, which guarantees they are on adjacent lines. I [r1, r2, r3] <- atomically $ replicateM 3 (openConsoleRegionSTM Linear)KNCloses a console region. Once closed, the region is removed from the display.MpCloses the console region and displays the passed value in the scrolling area above the active console regions.N;Handles all display for the other functions in this module.Note that this uses , so it takes over all output to the console while the passed IO action is running. As well as displaying the console regions, this handles display of anything buffered by % and ).YWhen standard output is not an ANSI capable terminal, console regions are not displayed.Splits a Text into the lines it would display using when output onto a console with a given width, starting from the first column.ANSI SGR sequences are handled specially, so that color, etc settings work despite the lines being split up, and the lines can be output indepedently. For example, "foooREDbar bazRESET" when split into lines becomes ["fooREDbarRESET", "RED bazRESET"]Finds the least expensive output to make a console that was displaying the old line display the new line. Cursor starts at far left.Basically, loop through and find spans where the old and new line are the same. Generate cursorForwardCode ANSI sequences to skip over those spans, unless such a sequence would be longer than the span it's skipping.Since ANSI sequences can be present in the line, need to take them into account. Generally, each of the sequences in new has to be included, even if old contained the same sequence: told: GREENfoofoofooREDbarbarbarRESETbaz new: GREENfoofoofooREDxarbarbaxRESETbaz ret: GREEN-------->REDx------>yRESETG(The first GREEN does not effect any output text, so it can be elided.)Also, despite old having the same second span as new, in the same location, that span has to be re-emitted because its color changed: kold: GREENfoofooREDbarbarbarbarbar new: GREENfoofoofooTANbarbarbar ret: GREEN----->fooTANbarbarbarCLEARRESTqAlso note above that the sequence has to clear the rest of the line, since the new line is shorter than the old.I?@ABCDEFGHIJKLMN?@ABCDEFGHIJKLMNN?@ABHIKDFMJLEGC9?@ABCDEFGHIJKLMN2015 Joey Hess <id@joeyh.name> BSD-2-clauseNoneOCalls )You should use the waitForProcess in this module on the resulting ProcessHandle. Using System.Process.waitForProcess instead can have mildly unexpected results.PCalls 'You should only use this on a ProcessHandle obtained by calling createProcess from this module. Using this with a ProcessHandle obtained from System.Process.createProcess etc will have extremely unexpected results; it can wait a very long time before returning.OPOPOPOP       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdbcebcfbcgbchbcdijkijlijmijnijoijpijqijrijsijtijuijvijwijxijyijzij{ij|ij}ij~ijijijijijijTDconcu_LZUbgu34EnBDfDqe1MucpD"System.Console.Concurrent.InternalSystem.Console.RegionsSystem.Process.Concurrent Utility.DataUtility.Exception Utility.MonadSystem.Process createProcessSystem.Console.ConcurrentBufSigAtEndOutputBufferedActivityOutput InTempFiletempFile endsInNewLine StdHandleStdOutStdErr OutputBufferConcurrentProcessHandle OutputabletoOutputLockLocked OutputHandle outputLock outputBuffer errorBuffer outputThreadsprocessWaiterswaitForProcessLockglobalOutputHandle lockOutputtakeOutputLocktryTakeOutputLockwithLocktakeOutputLock'dropOutputLockwithConcurrentOutputflushConcurrentOutputoutputConcurrenttoConcurrentProcessHandlewaitForProcessConcurrentasyncProcessWaitercreateProcessConcurrentcreateProcessForeground fgProcess bgProcess willOutputtoHandle bufferForsetupOutputBuffer outputDrainerregisterOutputThreadunregisterOutputThread bufferWriteraddOutputBufferbufferOutputSTMbufferOutputSTM'outputBufferWaiterSTM waitAnyBufferwaitCompleteLines endsNewLineemitOutputBuffer$fOutputable[]$fOutputableTextConsoleRegionHandle RegionLayoutLinearInLineupdateRegionListSTMsetConsoleRegionsetConsoleRegionSTMappendConsoleRegionappendConsoleRegionSTMwithConsoleRegionopenConsoleRegionopenConsoleRegionSTMcloseConsoleRegioncloseConsoleRegionSTMfinishConsoleRegiondisplayConsoleRegionswaitForProcess firstJust eitherToMaybe catchBoolIO catchMaybeIOcatchDefaultIO catchMsgIOcatchIOtryIO bracketIO catchNonAsync tryNonAsync tryWhenExistscatchHardwareFaultbase GHC.Exception SomeExceptiondisplayException fromException toException Exceptionexcep_8GsEeHgaIks3pVGk6GaELJControl.Monad.CatchbracketOnErrorfinallybracket_bracket onExceptioncatchestryJusttry handleJusthandleIf handleAll handleIOErrorhandle catchJustcatchIf catchIOErrorcatchAlluninterruptibleMask_mask_throwM MonadThrowcatch MonadCatchuninterruptibleMaskmask MonadMaskfirstMgetManyMallM untilTrueifM<||><&&>observeafternoopproce_FLTz0SLwyG6LJUpZ52HjkU regionList consoleWidthregionDisplayEnabledcalcRegionLinescalcLineUpdate LineUpdateDisplaySkipSGR ClearToEndInvisPastRegionSnapshot DisplayChange BufferChange RegionChangeTerminalResize EndSignalWidth RegionListRegion regionContent regionLines regionLayoutregionChildren modifyRegion resizeRegionfinishConsoleRegionSTM removeChildaddChild refreshParenttrackConsoleWidth displayThread readRegionsregionListWaiter regionWaiter changedLines diffUpdate changeOffsets updateLines inAreaAbove displayLinesinstallResizeHandlercalcRegionLines'resetSGRendCSIendOSCendSGR advanceLineisSGR genLineUpdateoptimiseLineUpdate combineSGRcombineSGRCodes $fEqRegion