Пример #1
0
// MakeRaw puts the terminal connected to the given file descriptor into raw
// mode and returns the previous state of the terminal so that it can be
// restored.
func MakeRaw(fd uintptr) (*State, error) {
	var state *State
	state, err := SaveState(fd)
	if err != nil {
		return nil, err
	}

	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
	// All three input modes, along with processed output mode, are designed to work together.
	// It is best to either enable or disable all of these modes as a group.
	// When all are enabled, the application is said to be in "cooked" mode, which means that most of the processing is handled for the application.
	// When all are disabled, the application is in "raw" mode, which means that input is unfiltered and any processing is left to the application.
	state.mode = 0
	err = winconsole.SetConsoleMode(fd, state.mode)
	if err != nil {
		return nil, err
	}
	return state, nil
}
Пример #2
0
// DisableEcho disbales the echo for given file descriptor and returns previous state
// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx for these flag settings
func DisableEcho(fd uintptr, state *State) error {
	state.mode &^= (winconsole.ENABLE_ECHO_INPUT)
	state.mode |= (winconsole.ENABLE_PROCESSED_INPUT | winconsole.ENABLE_LINE_INPUT)
	return winconsole.SetConsoleMode(fd, state.mode)
}
Пример #3
0
// RestoreTerminal restores the terminal connected to the given file descriptor to a
// previous state.
func RestoreTerminal(fd uintptr, state *State) error {
	return winconsole.SetConsoleMode(fd, state.mode)
}