Skip to content

Commit

Permalink
fix: preserve kittyFlags and modifyOtherKeys when updating enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 13, 2025
1 parent e06652b commit 446de71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 4 additions & 2 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// translateInputEvent translates an input event into a Bubble Tea Msg.
func translateInputEvent(e input.Event) Msg {
func (p *Program) translateInputEvent(e input.Event) Msg {
switch e := e.(type) {
case input.ClipboardEvent:
switch e.Selection {
Expand Down Expand Up @@ -52,11 +52,13 @@ func translateInputEvent(e input.Event) Msg {
return TerminalVersionMsg(e)
case input.KittyEnhancementsEvent:
return KeyboardEnhancementsMsg{
kittyFlags: int(e),
kittyFlags: int(e),
modifyOtherKeys: p.activeEnhancements.modifyOtherKeys,
}
case input.ModifyOtherKeysEvent:
return KeyboardEnhancementsMsg{
modifyOtherKeys: int(e),
kittyFlags: p.activeEnhancements.kittyFlags,
}
}
return nil
Expand Down
15 changes: 7 additions & 8 deletions tty.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tea

import (
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -126,19 +125,19 @@ func (p *Program) initInputReader() error {
return nil
}

func readInputs(ctx context.Context, msgs chan<- Msg, reader *input.Reader) error {
func (p *Program) readInputs() error {
for {
events, err := reader.ReadEvents()
events, err := p.inputReader.ReadEvents()
if err != nil {
return err
}

for _, msg := range events {
if m := translateInputEvent(msg); m != nil {
if m := p.translateInputEvent(msg); m != nil {
select {
case msgs <- m:
case <-ctx.Done():
err := ctx.Err()
case p.msgs <- m:
case <-p.ctx.Done():
err := p.ctx.Err()
if err != nil {
err = fmt.Errorf("found context error while reading input: %w", err)
}
Expand All @@ -152,7 +151,7 @@ func readInputs(ctx context.Context, msgs chan<- Msg, reader *input.Reader) erro
func (p *Program) readLoop() {
defer close(p.readLoopDone)

err := readInputs(p.ctx, p.msgs, p.inputReader)
err := p.readInputs()
if !errors.Is(err, io.EOF) && !errors.Is(err, cancelreader.ErrCanceled) {
select {
case <-p.ctx.Done():
Expand Down

0 comments on commit 446de71

Please sign in to comment.