Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: retaina and restore terminal mode on Windows (fixes #4251)
- Loading branch information
1 parent
cbb045a
commit 80a14ff
Showing
4 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package caddycmd | ||
|
||
func cleanup() error { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package caddycmd | ||
|
||
import "golang.org/x/sys/windows" | ||
|
||
// Retain the original mode of the console to restore later. | ||
// See: https://github.com/caddyserver/caddy/issues/4251 | ||
// The evaluation of this takes place before calling init() | ||
// ref: https://golang.org/ref/spec#Order_of_evaluation | ||
var inMode, outMode uint32 | ||
var _ = windows.GetConsoleMode(windows.Stdin, &inMode) | ||
var _ = windows.GetConsoleMode(windows.Stdout, &outMode) | ||
|
||
func cleanup() error { | ||
if err := windows.SetConsoleMode(windows.Stdin, inMode); err != nil { | ||
return err | ||
} | ||
if err := windows.SetConsoleMode(windows.Stdout, outMode); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters