-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render ASCII-only spinner and icons on conhost.exe
Fixes #338
- Loading branch information
1 parent
952ef93
commit 3c32ab3
Showing
11 changed files
with
107 additions
and
21 deletions.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cmd | ||
|
||
// IsConhost returns true if the current terminal is conhost. This indicates | ||
// that it can't deal with multi-byte characters and requires special treatment. | ||
// See https://github.com/overmindtech/cli/issues/388 for detailed analysis. | ||
func IsConhost() bool { | ||
return false | ||
} |
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,51 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"sync" | ||
) | ||
|
||
var isWslCache int // 0 = unset; 1 = WSL; 2 = not WSL | ||
var isWslCacheMu sync.RWMutex | ||
|
||
// IsConhost returns true if the current terminal is conhost. This indicates | ||
// that it can't deal with multi-byte characters and requires special treatment. | ||
// See https://github.com/overmindtech/cli/issues/388 for detailed analysis. | ||
func IsConhost() bool { | ||
// shortcut this if we (probably) run in Windows Terminal (through WSL) or | ||
// on something that smells like a regular Linux terminal | ||
if os.Getenv("WT_SESSION") != "" { | ||
return false | ||
} | ||
|
||
isWslCacheMu.RLock() | ||
w := isWslCache | ||
isWslCacheMu.RUnlock() | ||
|
||
if w == 1 { | ||
return true | ||
} else if w == 2 { | ||
return false | ||
} | ||
|
||
// isWslCache has not yet been initialised, so we need to check if we are in WSL | ||
// since we don't know if we are in WSL, we need to check now | ||
isWslCacheMu.Lock() | ||
defer isWslCacheMu.Unlock() | ||
if w != 0 { | ||
// someone else raced the lock and has already decided | ||
return isWslCache == 1 | ||
} | ||
|
||
// check if we run in WSL | ||
ver, err := os.ReadFile("/proc/version") | ||
if err == nil && bytes.Contains(ver, []byte("Microsoft")) { | ||
isWslCache = 1 | ||
return true | ||
} | ||
|
||
// we can't access /proc/version or it does not contain Microsoft, we are _probably_ not in WSL | ||
isWslCache = 2 | ||
return false | ||
} |
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,10 @@ | ||
package cmd | ||
|
||
import "os" | ||
|
||
// IsConhost returns true if the current terminal is conhost. This indicates | ||
// that it can't deal with multi-byte characters and requires special treatment. | ||
// See https://github.com/overmindtech/cli/issues/388 for detailed analysis. | ||
func IsConhost() bool { | ||
return os.Getenv("WT_SESSION") == "" | ||
} |