-
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 0676d04
Showing
10 changed files
with
96 additions
and
20 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,49 @@ | ||
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") != "" || os.Getenv("TERM") != "" { | ||
return false | ||
} | ||
|
||
isWslCacheMu.RLock() | ||
w := isWslCache | ||
isWslCacheMu.RUnlock() | ||
|
||
if w == 0 { | ||
// 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 { | ||
// if we can't access /proc/version, we are _probably_ not in WSL | ||
isWslCache = 2 | ||
return false | ||
} | ||
if bytes.Contains(ver, []byte("Microsoft")) { | ||
isWslCache = 1 | ||
return true | ||
} | ||
} | ||
|
||
return w == 1 | ||
} |
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") == "" | ||
} |