attributeControl: explicitly enable a required mode flag (see #187)

Prior to this change, Vty would initialize the terminal by clearing the
flags it needed to clear. That is good, but it means that some flags
that were assumed to be enabled but not *explicitly* enabled by Vty
would cause trouble if they were not, in fact, enabled prior to Vty
initialization.

This comes up in (pathological?) cases where the terminal state prior to
Vty initialization is not what Vty assumes it will be, i.e., cases in
which some flags which are assumed to be set are not. We found this to
be true when an application (in this case vim) was terminated uncleanly,
leaving the terminal mode flags in a state that Vty did not anticipate.

To resolve this problem, this change explicitly sets one flag which we
now know to be required for Vty to function properly (the ICRNL flag).
This commit is contained in:
Jonathan Daugherty 2020-07-09 13:57:33 -07:00
parent f7eef975de
commit c572ad1ac7

View File

@ -174,9 +174,13 @@ runInputProcessorLoop classifyTable input = do
attributeControl :: Fd -> IO (IO (), IO ())
attributeControl fd = do
original <- getTerminalAttributes fd
let vtyMode = foldl withoutMode original [ StartStopOutput, KeyboardInterrupts
, EnableEcho, ProcessInput, ExtendedFunctions
]
let vtyMode = foldl withMode clearedFlags flagsToSet
clearedFlags = foldl withoutMode original flagsToUnset
flagsToSet = [ MapCRtoLF
]
flagsToUnset = [ StartStopOutput, KeyboardInterrupts
, EnableEcho, ProcessInput, ExtendedFunctions
]
let setAttrs = setTerminalAttributes fd vtyMode Immediately
unsetAttrs = setTerminalAttributes fd original Immediately
return (setAttrs,unsetAttrs)