A few bug-fixes and maintenance tasks (#30)
- Fixed a bug which was not properly detecting whether MacOS was in light mode. - Fixed a bug which was breaking filtering with the table-selection mode. - Upgraded bubble-tea.
This commit is contained in:
parent
efdc7f9e25
commit
f373a3313a
7 changed files with 90 additions and 33 deletions
24
internal/common/ui/osstyle/detect.go
Normal file
24
internal/common/ui/osstyle/detect.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package osstyle
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"log"
|
||||
)
|
||||
|
||||
func DetectCurrentScheme() {
|
||||
if lipgloss.HasDarkBackground() {
|
||||
if colorScheme := CurrentColorScheme(); colorScheme == ColorSchemeLightMode {
|
||||
log.Printf("terminal reads dark but really in light mode")
|
||||
lipgloss.SetHasDarkBackground(true)
|
||||
} else {
|
||||
log.Printf("in dark background")
|
||||
}
|
||||
} else {
|
||||
if colorScheme := CurrentColorScheme(); colorScheme == ColorSchemeDarkMode {
|
||||
log.Printf("terminal reads light but really in dark mode")
|
||||
lipgloss.SetHasDarkBackground(true)
|
||||
} else {
|
||||
log.Printf("cannot detect system darkmode")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,34 @@
|
|||
package osstyle
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
errorMessageIndicatingInLightMode = `The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist`
|
||||
)
|
||||
|
||||
// Usage: https://stefan.sofa-rockers.org/2018/10/23/macos-dark-mode-terminal-vim/
|
||||
func darwinGetOSColorScheme() ColorScheme {
|
||||
d, err := exec.Command("defaults", "read", "-g", "AppleInterfaceStyle").Output()
|
||||
if err != nil {
|
||||
log.Printf("cannot get current OS color scheme: %v", err)
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
stdErr := string(exitErr.Stderr)
|
||||
|
||||
if strings.Contains(stdErr, errorMessageIndicatingInLightMode) {
|
||||
log.Printf("error message indicates that macOS is in light mode")
|
||||
return ColorSchemeLightMode
|
||||
}
|
||||
|
||||
log.Printf("cannot get current OS color scheme: %v - stderr: [%v]", err, stdErr)
|
||||
} else {
|
||||
log.Printf("cannot get current OS color scheme: %v", err)
|
||||
}
|
||||
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue