A few various changes
- Fixed the '-local' flag to accept host and port - Added a '-debug' flag to accept a file to write debug log messages - Added some logic which will force the dark background flag on if MacOS is in dark mode
This commit is contained in:
parent
47e404aff7
commit
41af399215
18 changed files with 191 additions and 68 deletions
|
|
@ -31,6 +31,15 @@ func PromptForInput(prompt string, onDone func(value string) tea.Cmd) tea.Cmd {
|
|||
}
|
||||
}
|
||||
|
||||
func Confirm(prompt string, onYes func() tea.Cmd) tea.Cmd {
|
||||
return PromptForInput(prompt, func(value string) tea.Cmd {
|
||||
if value == "y" {
|
||||
return onYes()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
type MessageWithStatus interface {
|
||||
StatusMessage() string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,18 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
func EnableLogging() (closeFn func()) {
|
||||
tempFile, err := os.CreateTemp("", "debug.log")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
func EnableLogging(logFile string) (closeFn func()) {
|
||||
if logFile == "" {
|
||||
tempFile, err := os.CreateTemp("", "debug.log")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tempFile.Close()
|
||||
logFile = tempFile.Name()
|
||||
}
|
||||
tempFile.Close()
|
||||
|
||||
f, err := tea.LogToFile(tempFile.Name(), "debug")
|
||||
f, err := tea.LogToFile(logFile, "debug")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
18
internal/common/ui/osstyle/osstyle.go
Normal file
18
internal/common/ui/osstyle/osstyle.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package osstyle
|
||||
|
||||
type ColorScheme int
|
||||
|
||||
const (
|
||||
ColorSchemeUnknown ColorScheme = iota
|
||||
ColorSchemeLightMode
|
||||
ColorSchemeDarkMode
|
||||
)
|
||||
|
||||
var getOSColorScheme func() ColorScheme = nil
|
||||
|
||||
func CurrentColorScheme() ColorScheme {
|
||||
if getOSColorScheme == nil {
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
return getOSColorScheme()
|
||||
}
|
||||
27
internal/common/ui/osstyle/osstyle_darwin.go
Normal file
27
internal/common/ui/osstyle/osstyle_darwin.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package osstyle
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// 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)
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
|
||||
switch string(d) {
|
||||
case "Dark\n":
|
||||
return ColorSchemeDarkMode
|
||||
case "Light\n":
|
||||
return ColorSchemeLightMode
|
||||
}
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
|
||||
func init() {
|
||||
getOSColorScheme = darwinGetOSColorScheme
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue