Skip to content

Commit

Permalink
feat: make KeyboardEnhancementsMsg helpers always return true on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Sep 17, 2024
1 parent 0e88b9d commit f6e468f
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion keyboard.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package tea

import "github.com/charmbracelet/x/ansi"
import (
"runtime"

"github.com/charmbracelet/x/ansi"
)

// keyboardEnhancements is a type that represents a set of keyboard
// enhancements.
Expand Down Expand Up @@ -56,3 +60,45 @@ func withDisambiguousKeys(k *keyboardEnhancements) {
k.modifyOtherKeys = 1
}
}

type enableKeyboardEnhancementsMsg []KeyboardEnhancement

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (macos-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

enableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 64 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

enableKeyboardEnhancementsMsg redeclared in this block

// EnableKeyboardEnhancements is a command that enables keyboard enhancements
// in the terminal.
func EnableKeyboardEnhancements(enhancements ...KeyboardEnhancement) Cmd {

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (macos-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

EnableKeyboardEnhancements redeclared in this block

Check failure on line 68 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

EnableKeyboardEnhancements redeclared in this block
return func() Msg {
return enableKeyboardEnhancementsMsg(append(enhancements, withDisambiguousKeys))
}
}

type disableKeyboardEnhancementsMsg struct{}

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (macos-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

disableKeyboardEnhancementsMsg redeclared in this block

Check failure on line 74 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

disableKeyboardEnhancementsMsg redeclared in this block

// DisableKeyboardEnhancements is a command that disables keyboard enhancements
// in the terminal.
func DisableKeyboardEnhancements() Msg {

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (macos-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

DisableKeyboardEnhancements redeclared in this block

Check failure on line 78 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

DisableKeyboardEnhancements redeclared in this block
return disableKeyboardEnhancementsMsg{}
}

// KeyboardEnhancementsMsg is a message that gets sent when the terminal
// supports keyboard enhancements.
type KeyboardEnhancementsMsg keyboardEnhancements

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / build (macos-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / build (ubuntu-latest)

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / lint-soft

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-go-mod / govulncheck

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

KeyboardEnhancementsMsg redeclared in this block

Check failure on line 84 in keyboard.go

View workflow job for this annotation

GitHub Actions / build-examples / govulncheck

KeyboardEnhancementsMsg redeclared in this block

// SupportsDisambiguousKeys returns whether the terminal supports reporting
// disambiguous keys as escape codes.
func (k KeyboardEnhancementsMsg) SupportsDisambiguousKeys() bool {
if runtime.GOOS == "windows" {
// We use Windows Console API which supports reporting disambiguous keys.
return true
}
return k.kittyFlags&ansi.KittyDisambiguateEscapeCodes != 0 || k.modifyOtherKeys >= 1
}

// SupportsReleaseKeys returns whether the terminal supports key release
// events.
func (k KeyboardEnhancementsMsg) SupportsReleaseKeys() bool {
if runtime.GOOS == "windows" {
// We use Windows Console API which supports key release events.
return true
}
return k.kittyFlags&ansi.KittyReportEventTypes != 0
}

0 comments on commit f6e468f

Please sign in to comment.