tcellterm

package module
v0.0.0-...-7a53a29 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT Imports: 8 Imported by: 0

README

tcell-term

A virtual terminal widget for tcell

s, err := tcell.NewScreen()
if err != nil {
	panic(err)
}
quit := make(chan struct{})
termRedraw := make(chan struct{})

w, h := s.Size()
cmd := exec.Cmd("less", "/etc/hosts")
termWidth, termHeight := w / 2, h / 2
termX, termY := w / 4, h / 4
term := tcellterm.New()

//run command in term
go func() {
	term.Run(cmd, termRedraw, termWidth, termHeight)
	cmd.Wait()
	quit <- struct{}{}
}()

//event loop
go func() {
	for {
		ev := s.PollEvent()
		switch ev := ev.(type) {
		case *tcell.EventKey:
			//send key events to the terminal
			term.Event(ev)
		case *tcell.EventResize:
			w, h := s.Size()
			lh := h / 2
			lw := w / 2
			//resize event for the terminal
			term.Resize(lw, lh)
			s.Sync()
		}
	}
}()

//draw loop
loop:
for {
	select {
	case <-quit:
		break loop
	//terminal wants to be redrawn
	case <-termRedraw:
	}
	term.Draw(s, termX, termY)
}

s.Fini()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LINUX_KEY_MAP = map[tcell.Key]string{
		tcell.KeyEnter:      "\r",
		tcell.KeyBackspace:  "\x7f",
		tcell.KeyBackspace2: "\x7f",
		tcell.KeyTab:        "\t",
		tcell.KeyEscape:     "\x1b",
		tcell.KeyDown:       "\x1b[B",
		tcell.KeyUp:         "\x1b[A",
		tcell.KeyRight:      "\x1b[C",
		tcell.KeyLeft:       "\x1b[D",
		tcell.KeyHome:       "\x1b[1~",
		tcell.KeyEnd:        "\x1b[4~",
		tcell.KeyPgUp:       "\x1b[5~",
		tcell.KeyPgDn:       "\x1b[6~",
		tcell.KeyDelete:     "\x1b[3~",
		tcell.KeyInsert:     "\x1b[2~",
		tcell.KeyF1:         "\x1bOP",
		tcell.KeyF2:         "\x1bOQ",
		tcell.KeyF3:         "\x1bOR",
		tcell.KeyF4:         "\x1bOS",
		tcell.KeyF5:         "\x1b[15~",
		tcell.KeyF6:         "\x1b[17~",
		tcell.KeyF7:         "\x1b[18~",
		tcell.KeyF8:         "\x1b[19~",
		tcell.KeyF9:         "\x1b[20~",
		tcell.KeyF10:        "\x1b[21~",
		tcell.KeyF12:        "\x1b[24~",
	}

	LINUX_CTRL_KEY_MAP = map[tcell.Key]string{
		tcell.KeyUp:    "\x1b[1;5A",
		tcell.KeyDown:  "\x1b[1;5B",
		tcell.KeyRight: "\x1b[1;5C",
		tcell.KeyLeft:  "\x1b[1;5D",
	}

	LINUX_CTRL_RUNE_MAP = map[rune]string{
		'@':  "\x00",
		'`':  "\x00",
		'[':  "\x1b",
		'{':  "\x1b",
		'\\': "\x1c",
		'|':  "\x1c",
		']':  "\x1d",
		'}':  "\x1d",
		'^':  "\x1e",
		'~':  "\x1e",
		'_':  "\x1f",
		'?':  "\x7f",
	}

	LINUX_ALT_KEY_MAP = map[tcell.Key]string{
		tcell.KeyUp:    "\x1b[1;3A",
		tcell.KeyDown:  "\x1b[1;3B",
		tcell.KeyRight: "\x1b[1;3C",
		tcell.KeyLeft:  "\x1b[1;3D",
	}
)

Functions

This section is empty.

Types

type Option

type Option func(*Terminal)

func WithWindowManipulator

func WithWindowManipulator(wm termutil.WindowManipulator) Option

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Terminal

func (*Terminal) Draw

func (t *Terminal) Draw(s tcell.Screen, X, Y uint16)

func (*Terminal) Event

func (t *Terminal) Event(e tcell.Event)

func (*Terminal) Resize

func (t *Terminal) Resize(width, height int)

func (*Terminal) Run

func (t *Terminal) Run(cmd *exec.Cmd, redrawChan chan struct{}, width, height uint16) error

type WinSize

type WinSize struct {
	Rows   int16 /* rows, in characters */
	Cols   int16 /* columns, in characters */
	XPixel int16 /* horizontal size, pixels */
	YPixel int16 /* vertical size, pixels */
}

func GetWinSize

func GetWinSize() (sz WinSize, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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