Skip to content

Commit

Permalink
Add ctrl-D handler to exit shell
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed May 6, 2020
1 parent fa99672 commit a3af865
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cmd/fyneterm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/canvas"
"fyne.io/fyne/driver/desktop"
"fyne.io/fyne/layout"

"github.com/fyne-io/terminal"
Expand Down Expand Up @@ -52,6 +53,12 @@ func main() {
t := terminal.NewTerminal()
setupListener(t, w)
w.SetContent(fyne.NewContainerWithLayout(layout.NewMaxLayout(), bg, img, t))
w.Canvas().AddShortcut(&desktop.CustomShortcut{
KeyName: fyne.KeyD,
Modifier: desktop.ControlModifier,
}, func (_ fyne.Shortcut) {
t.Close()
})

cellSize := guessCellSize()
w.Resize(fyne.NewSize(cellSize.Width*80, cellSize.Height*24))
Expand Down
6 changes: 3 additions & 3 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func (t *Terminal) open() error {
return nil
}

func (t *Terminal) close() error {
return t.pty.Close()
func (t *Terminal) Close() {
t.pty.Write([]byte("exit\n"))
}

// don't call often - should we cache?
Expand Down Expand Up @@ -147,7 +147,7 @@ func (t *Terminal) Run() error {

t.run()

return t.close()
return t.pty.Close()
}

// NewTerminal sets up a new terminal instance with the bash shell
Expand Down

0 comments on commit a3af865

Please sign in to comment.