keybind

package module
v0.0.0-...-629a3ce Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 5 Imported by: 0

README

go-keybind

Multi-platform terminal key input reader for go language integrated with utf-8.
You can handle all terminal input with this library.

Installation

$ go get github.com/k0kubun/go-keybind

Usage

You can enable reading all key input with keybind.Open().
ReadRune() reads one rune or control input.

bind := keybind.Open()
defer bind.Close()

for {
  ch, _ := bind.ReadRune()
  switch ch {
  case keybind.Escape:
    fmt.Println("ESCAPE")
  case keybind.Delete:
    fmt.Println("DELETE")
  case keybind.Tab:
    fmt.Println("TAB")
  default:
    if keybind.IsPrintable(ch) {
      fmt.Printf("%c\n", ch)
    } else {
      fmt.Printf("Ctrl+%c\n", '@'+ch)
    }
  }
}
Keys

You can check what is the input with following keybind.**

CtrlSpace = iota // or Ctrl+@
CtrlA
CtrlB
CtrlC
CtrlD
CtrlE
CtrlF
CtrlG
BackSpace // or Ctrl+H
Tab       // or Ctrl+I
CtrlJ
CtrlK
CtrlL
Return // or Ctrl+M
CtrlN
CtrlO
CtrlP
CtrlQ
CtrlR
CtrlS
CtrlT
CtrlU
CtrlV
CtrlW
CtrlX
CtrlY
CtrlZ
Escape           // or Ctrl+[
CtrlBackSlash    // Ctrl+\
CtrlRightBracket // Ctrl+]
CtrlHat          // Ctrl+^
CtrlUnderscore   // Ctrl+_
Delete

Documentation

API documentation can be found here: https://godoc.org/github.com/k0kubun/go-keybind

Documentation

Overview

Terminal key input receiver for go application. keybind.Bind() returns channel which returns each key input.

Index

Constants

View Source
const (
	// ASCII Control Characters
	NUL = iota
	SOH
	STX
	ETX
	EOT
	ENQ
	ACK
	BEL
	BS
	HT
	LF
	VT
	FF
	CR
	SO
	SI
	DLE
	DC1
	DC2
	DC3
	DC4
	NAK
	SYN
	ETB
	CAN
	EM
	SUB
	ESC
	FS
	GS
	RS
	US
	DEL = 127
)
View Source
const (
	// Major Key input for ASCII control characters
	CtrlSpace = iota // or Ctrl+@
	CtrlA
	CtrlB
	CtrlC
	CtrlD
	CtrlE
	CtrlF
	CtrlG
	BackSpace // or Ctrl+H
	Tab       // or Ctrl+I
	CtrlJ
	CtrlK
	CtrlL
	Return // or Ctrl+M
	CtrlN
	CtrlO
	CtrlP
	CtrlQ
	CtrlR
	CtrlS
	CtrlT
	CtrlU
	CtrlV
	CtrlW
	CtrlX
	CtrlY
	CtrlZ
	Escape           // or Ctrl+[
	CtrlBackSlash    // Ctrl+\
	CtrlRightBracket // Ctrl+]
	CtrlHat          // Ctrl+^
	CtrlUnderscore   // Ctrl+_
	Delete           = 127
)

Variables

This section is empty.

Functions

func IsPrintable

func IsPrintable(ch rune) bool

If given character is ASCII control characters, this function returns false.

Types

type Term

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

func Open

func Open() *Term

To receive all input, disable canonical mode, input echo and signal.

func (*Term) Close

func (t *Term) Close()

Close resets terminal to canonical mode.

func (*Term) ReadRune

func (t *Term) ReadRune() (rune, int, error)

ReadRune reads one rune or control sequence.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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