terminal

package module
v0.0.0-...-027064e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2023 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Code Status Build Status Coverage Status Join us on Slack

Fyne Terminal

A terminal emulator using the Fyne toolkit, supports Linux, macOS, Windows and BSD.

Running on Linux with a custom zsh theme. screenshot

Running on macOS with a powerlevel10k zsh theme and classic style. screenshot

Running on Windows with PowerShell running inside. screenshot

Installing on command line

Just use the go get command (you'll need a Go and C compiler installed first):

go get github.com/fyne-io/terminal/cmd/fyneterm

Installing as an app

To get the app installed alongside your other applications (with metadata, icons etc), use the fyne tool, as illustrated below:

$ go get fyne.io/fyne/v2/cmd/fyne
$ fyne get github.com/fyne-io/terminal/cmd/fyneterm

TODO

There are lots of great things that could be added to this app. Already planned is:

  • Tabs
  • Scroll-back
  • Background and font/size customisation
  • Split panels
  • Windows support
  • Copy and Paste

Library

You can also use this project as a library to create your own terminal based applications, using the import path "github.com/fyne-io/terminal".

There are two modes, using the default shell (macOS and Linux) or connecting to a remote shell.

Local Shell

To load a terminal widget and launch the current shell (works on macOS and Linux) use the RunLocalShell method after creating a Terminal, as follows:

	// win is a fyne.Window created to hold the content
	t := terminal.New()
	w.SetContent(t)

	go func() {
		_ = t.RunLocalShell()
		a.Quit()
	}()
	w.ShowAndRun()

Remote connection

For example to open a terminal to an SSH connection that you have created:

	// session is an *ssh.Session from golang.org/x/crypto/ssh
	// win is a fyne.Window created to hold the content
	in, _ := session.StdinPipe()
	out, _ := session.StdoutPipe()

	go session.Run("$SHELL || bash")

	t := terminal.New()
	w.SetContent(t)

	go func() {
		_ = t.RunWithConnection(in, out)
		a.Quit()
	}()
	w.ShowAndRun()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Title         string
	Rows, Columns uint
}

Config is the state of a terminal, updated upon certain actions or commands. Use Terminal.OnConfigure hook to register for changes.

type Terminal

type Terminal struct {
	widget.BaseWidget
	fyne.ShortcutHandler
	// contains filtered or unexported fields
}

Terminal is a terminal widget that loads a shell and handles input/output.

func New

func New() *Terminal

New sets up a new terminal instance with the bash shell

func (*Terminal) AcceptsTab

func (t *Terminal) AcceptsTab() bool

AcceptsTab indicates that this widget will use the Tab key (avoids loss of focus).

func (*Terminal) AddListener

func (t *Terminal) AddListener(listener chan Config)

AddListener registers a new outgoing channel that will have our Config sent each time it changes.

func (*Terminal) CreateRenderer

func (t *Terminal) CreateRenderer() fyne.WidgetRenderer

CreateRenderer requests a new renderer for this terminal (just a wrapper around the TextGrid)

func (*Terminal) Exit

func (t *Terminal) Exit()

Exit requests that this terminal exits. If there are embedded shells it will exit the child one only.

func (*Terminal) FocusGained

func (t *Terminal) FocusGained()

FocusGained notifies the terminal that it has focus

func (*Terminal) FocusLost

func (t *Terminal) FocusLost()

FocusLost tells the terminal it no longer has focus

func (*Terminal) Focused

func (t *Terminal) Focused() bool

Focused is used to determine if this terminal currently has focus

func (*Terminal) MinSize

func (t *Terminal) MinSize() fyne.Size

MinSize provides a size large enough that a terminal could technically funcion.

func (*Terminal) MouseDown

func (t *Terminal) MouseDown(ev *desktop.MouseEvent)

MouseDown handles the down action for desktop mouse events.

func (*Terminal) MouseUp

func (t *Terminal) MouseUp(ev *desktop.MouseEvent)

MouseUp handles the up action for desktop mouse events.

func (*Terminal) RemoveListener

func (t *Terminal) RemoveListener(listener chan Config)

RemoveListener de-registers a Config channel and closes it

func (*Terminal) Resize

func (t *Terminal) Resize(s fyne.Size)

Resize is called when this terminal widget has been resized. It ensures that the virtual terminal is within the bounds of the widget.

func (*Terminal) RunLocalShell

func (t *Terminal) RunLocalShell() error

RunLocalShell starts the terminal by loading a shell and starting to process the input/output.

func (*Terminal) RunWithConnection

func (t *Terminal) RunWithConnection(in io.WriteCloser, out io.Reader) error

RunWithConnection starts the terminal by connecting to an external resource like an SSH connection.

func (*Terminal) SetDebug

func (t *Terminal) SetDebug(debug bool)

SetDebug turns on output about terminal codes and other errors if the parameter is `true`.

func (*Terminal) SetStartDir

func (t *Terminal) SetStartDir(path string)

SetStartDir can be called before one of the Run calls to specify the initial directory.

func (*Terminal) Tapped

func (t *Terminal) Tapped(ev *fyne.PointEvent)

Tapped makes sure we ask for focus if user taps us.

func (*Terminal) TouchCancel

func (t *Terminal) TouchCancel(ev *mobile.TouchEvent)

TouchCancel handles the tap action for mobile apps that lose focus during tap.

func (*Terminal) TouchDown

func (t *Terminal) TouchDown(ev *mobile.TouchEvent)

TouchDown handles the down action for mobile touch events.

func (*Terminal) TouchUp

func (t *Terminal) TouchUp(ev *mobile.TouchEvent)

TouchUp handles the up action for mobile touch events.

func (*Terminal) TypedKey

func (t *Terminal) TypedKey(e *fyne.KeyEvent)

TypedKey will be called if a non-printable keyboard event occurs

func (*Terminal) TypedRune

func (t *Terminal) TypedRune(r rune)

TypedRune is called when the user types a visible character

func (*Terminal) TypedShortcut

func (t *Terminal) TypedShortcut(s fyne.Shortcut)

TypedShortcut handles key combinations, we pass them on to the tty.

func (*Terminal) Write

func (t *Terminal) Write(b []byte) (int, error)

Write is used to send commands into an open terminal connection. Errors will be returned if the connection is not established, has closed, or there was a problem in transmission.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL