[Haskell-cafe] gracefully invoking `less` using System.Process (and ignoring ctrl-c)

Guillaume Hoffmann guillaumh at gmail.com
Fri Dec 12 17:19:31 UTC 2014


I'm looking at a bug that we should fix for the 2.10 release of darcs.
I'd like to make the invocation of the pager (most of the time `less`)
as identical to git as possible.

Currently darcs has a workaround for the "resource vanished (broken
pipe)" problem (that happens when you leave `less` before all of the
text has been read by it). The workaround involves creating a
temporary file and then passing it to less [1]. This works but it's
slow (for big inputs) and ugly IMO.

I have a fix proposal [2] that is made of two changes:

* use System.Process.createProcess (just to update the code), and
* in the "ortryrunning" function (that chains attempts at calling
various pagers until one works), ignoring IOError's of the kind
ResourceVanished (otherwise we would invoke every pager in the chain
if we quit them before they read all their input)

The problem is that pressing CTRL-C in `less` now kills everything (darcs+less).

Is there a way to fix this?

Note that the darcs executable runs inside of the function
withSignalHandled [3], which defines its behaviour with respect to
various signals.


[1] http://hub.darcs.net/darcs/darcs-reviewed/browse/src/Darcs/UI/External.hs#464
[2] http://hub.darcs.net/gh/darcs-screened_1/patch/20141210002305-5ef8f
[3] http://hub.darcs.net/darcs/darcs-reviewed/browse/src/Darcs/Util/SignalHandler.hs#55

More information about the Haskell-Cafe mailing list