On Mon, Mar 22, 2010 at 5:45 AM, Eric Kow <bugs@darcs.net> wrote:
>
> Our conclusion was that before we need to research the problem more, and
> determine if there was a portable way to reliably detect if we were on a
> terminal or not. Windows may be an issue here.
>
> If there is one, we can re-open the discussion about how apply -i should
> behave.
>
> Judah: any chance you'd be able to look into this?
Sure. There's a Windows equivalent to /dev/tty ("CONIN$" and
"CONOUT$"); Haskeline already uses the latter but not yet the former.
I did some tests, and trying to open CONIN looks like a reliable way
to check whether we're in a console session.*
So I believe there's no technical barriers to a robust
terminal-checking in the backend of Haskeline. The best approach
seems to me to add a function to Haskeline's API. For example:
runInputTInTerm :: Settings m -> InputT m a -> m (Maybe a)
which tries to run the given action(s) using the terminal, even if
it's not stdin; and returns Nothing if it couldn't connect to
[/dev/tty,CONIN$]. This should give Darcs some flexibility in
deciding the exact semantics of apply -i.
*The one caveat: in a Cygwin X shell, we can't connect to CONIN. But
Haskeline doesn't provide any interactive editing in that setting
anyway, so this seems OK to me. (There's little I can do about that
unless GHC improves its Cygwin support.)
|