Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/fyne-io/terminal
go 1.19

require (
fyne.io/fyne/v2 v2.7.0
fyne.io/fyne/v2 v2.7.1-0.20251030181611-4bc1d5fd5b88
github.com/ActiveState/termtest/conpty v0.5.0
github.com/creack/pty v1.1.21
github.com/fyshos/fancyfs v0.0.0-20250930151016-696fe12cefc6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fyne.io/fyne/v2 v2.7.0 h1:GvZSpE3X0liU/fqstInVvRsaboIVpIWQ4/sfjDGIGGQ=
fyne.io/fyne/v2 v2.7.0/go.mod h1:xClVlrhxl7D+LT+BWYmcrW4Nf+dJTvkhnPgji7spAwE=
fyne.io/fyne/v2 v2.7.1-0.20251030181611-4bc1d5fd5b88 h1:z/Egg/TPFUoTyB/peOdaEmgjcwQOqPy3Aju2UQvzwpA=
fyne.io/fyne/v2 v2.7.1-0.20251030181611-4bc1d5fd5b88/go.mod h1:xClVlrhxl7D+LT+BWYmcrW4Nf+dJTvkhnPgji7spAwE=
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58 h1:eA5/u2XRd8OUkoMqEv3IBlFYSruNlXD8bRHDiqm0VNI=
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
github.com/ActiveState/termtest/conpty v0.5.0 h1:JLUe6YDs4Jw4xNPCU+8VwTpniYOGeKzQg4SM2YHQNA8=
Expand Down
33 changes: 21 additions & 12 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,35 @@ func (t *Terminal) TypedShortcut(s fyne.Shortcut) {
}

if runtime.GOOS == "darwin" {
// do the default thing for macOS as they separete ctrl/cmd
// do the default thing for macOS as they separate ctrl/cmd
t.ShortcutHandler.TypedShortcut(s)
} else {
// we need to override the default ctrl-X/C/V/A for non-mac and do it ourselves

if _, ok := s.(*fyne.ShortcutCut); ok {
_, _ = t.in.Write([]byte{0x18})

} else if _, ok := s.(*fyne.ShortcutCopy); ok {
_, _ = t.in.Write([]byte{0x3})

} else if _, ok := s.(*fyne.ShortcutPaste); ok {
_, _ = t.in.Write([]byte{0x16})

if ct, ok := s.(*fyne.ShortcutCut); ok {
if ct.Secondary {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could have exposed the triggering keys/key-code on the shortcut struct along side the Secondary bool? This would fix your issue here of trying to determine what keys to translate them into here; you could just write whatever key-code was originally captured when converting the input into a shortcut. The added bonus being that developers like my self would then be able to tell the exact keys used to trigger the shortcut and add custom handling if we choose to do so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't needed - the Secondary provides that exact information.
Plus the codes from the keyboard are not the ANSI terminal codes need to be which is where I am falling short.
Keyboard codes are available at the low-level for Fyne developers that really need them - but this is not that place.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keyboard codes are available at the low-level for Fyne developers that really need them - but this is not that place.

I agree, this isn't the place, but since they are not emitted as actual key events I was clutching at straws. You're right that I can do this, and it'll work, and it does basically represent the same thing, it's just from a my perspective it's not clean or nice, BUT I'm falling into different issue territory here, that's the whole "Should Fyne be hard-coding shortcut handling in the first place" thing which is already open elsewhere.

Plus the codes from the keyboard are not the ANSI terminal codes need to be which is where I am falling short.

Ah, I entirely missed your point on this and thought you were talking about keyboard codes, which is why I was confused by the values and that you couldn't get them! My bad.

// TODO check this is the right key combo
_, _ = t.in.Write([]byte{46}) // shift+del
} else {
_, _ = t.in.Write([]byte{0x18})
}
} else if cp, ok := s.(*fyne.ShortcutCopy); ok {
if cp.Secondary {
// TODO Ctrl insert keys "(0;146)"?
} else {
_, _ = t.in.Write([]byte{0x3})
}
} else if ps, ok := s.(*fyne.ShortcutPaste); ok {
if ps.Secondary {
// TODO check this is the right key combo
_, _ = t.in.Write([]byte{48}) // shift+ins
} else {
_, _ = t.in.Write([]byte{0x16})
}
} else if _, ok := s.(*fyne.ShortcutUndo); ok {
_, _ = t.in.Write([]byte{0x1a})

} else if _, ok := s.(*fyne.ShortcutSelectAll); ok {
_, _ = t.in.Write([]byte{0x1})

}
}
}
Expand Down
9 changes: 7 additions & 2 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ func (t *Terminal) copySelectedText(clipboard fyne.Clipboard) {
t.clearSelectedText()
}

func (t *Terminal) pasteText(clipboard fyne.Clipboard) {
content := clipboard.Content()
func (t *Terminal) pasteText(clipboard fyne.Clipboard, secondary bool) {
var content string
if secondary {
content = t.SelectedText()
} else {
content = clipboard.Content()
}

if t.bracketedPasteMode {
_, _ = t.in.Write(append(
Expand Down
8 changes: 4 additions & 4 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ func (t *Terminal) MinSize() fyne.Size {
// MouseDown handles the down action for desktop mouse events.
func (t *Terminal) MouseDown(ev *desktop.MouseEvent) {
if t.hasSelectedText() {
t.copySelectedText(fyne.CurrentApp().Clipboard())
t.clearSelectedText()
}
if ev.Button == desktop.MouseButtonSecondary {
t.pasteText(fyne.CurrentApp().Clipboard())
t.pasteText(fyne.CurrentApp().Clipboard(), true)
}

if t.onMouseDown == nil {
Expand Down Expand Up @@ -452,8 +451,9 @@ func (t *Terminal) setupShortcuts() {
paste = &fyne.ShortcutPaste{} // we look up clipboard later
}
t.ShortcutHandler.AddShortcut(paste,
func(_ fyne.Shortcut) {
t.pasteText(fyne.CurrentApp().Clipboard())
func(sh fyne.Shortcut) {
ps := sh.(*fyne.ShortcutPaste)
t.pasteText(fyne.CurrentApp().Clipboard(), ps.Secondary)
})
var shortcutCopy fyne.Shortcut
shortcutCopy = &desktop.CustomShortcut{KeyName: fyne.KeyC, Modifier: fyne.KeyModifierShift | fyne.KeyModifierShortcutDefault}
Expand Down
Loading