mirror of
https://github.com/BigJk/crt.git
synced 2026-02-06 10:47:25 +00:00
Fix double key emitting
This commit is contained in:
parent
e7dd7bbee9
commit
79c738c1e5
@ -120,22 +120,20 @@ func (b *Adapter) HandleKeyPress() {
|
||||
keys = inpututil.AppendJustReleasedKeys(keys)
|
||||
|
||||
for _, k := range keys {
|
||||
runes := []rune(strings.ToLower(k.String()))
|
||||
if val, ok := ebitenToTeaRunes[k]; ok {
|
||||
runes = val
|
||||
}
|
||||
b.prog.Send(tea.KeyMsg{
|
||||
Type: tea.KeyRunes,
|
||||
Runes: runes,
|
||||
Alt: ebiten.IsKeyPressed(ebiten.KeyAlt),
|
||||
})
|
||||
}
|
||||
|
||||
for k, v := range ebitenToTeaKeys {
|
||||
if inpututil.IsKeyJustReleased(k) {
|
||||
if val, ok := ebitenToTeaKeys[k]; ok {
|
||||
runes := []rune(strings.ToLower(k.String()))
|
||||
b.prog.Send(tea.KeyMsg{
|
||||
Type: v,
|
||||
Type: val,
|
||||
Runes: runes,
|
||||
Alt: ebiten.IsKeyPressed(ebiten.KeyAlt),
|
||||
})
|
||||
} else {
|
||||
runes := []rune(strings.ToLower(k.String()))
|
||||
if val, ok := ebitenToTeaRunes[k]; ok {
|
||||
runes = val
|
||||
}
|
||||
b.prog.Send(tea.KeyMsg{
|
||||
Type: tea.KeyRunes,
|
||||
Runes: runes,
|
||||
Alt: ebiten.IsKeyPressed(ebiten.KeyAlt),
|
||||
})
|
||||
|
||||
54
examples/keys/main.go
Normal file
54
examples/keys/main.go
Normal file
@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BigJk/crt"
|
||||
bubbleadapter "github.com/BigJk/crt/bubbletea"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
const (
|
||||
Width = 1000
|
||||
Height = 600
|
||||
)
|
||||
|
||||
type model struct {
|
||||
keys []tea.KeyMsg
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
m.keys = append(m.keys, msg)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
view := ""
|
||||
for _, key := range m.keys {
|
||||
view += " " + key.String() + fmt.Sprintf(" | %v %v", key.Runes, key.Alt) + "\n"
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
func main() {
|
||||
fonts, err := crt.LoadFaces("./fonts/IosevkaTermNerdFontMono-Regular.ttf", "./fonts/IosevkaTermNerdFontMono-Bold.ttf", "./fonts/IosevkaTermNerdFontMono-Italic.ttf", 72.0, 16.0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
win, err := bubbleadapter.Window(Width, Height, fonts, model{}, color.Black)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := win.Run("Simple"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user