...

Source file src/github.com/mattn/go-tty/_example/simple.go

Documentation: github.com/mattn/go-tty/_example

     1  // +build ignore
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"log"
     8  
     9  	"github.com/mattn/go-tty"
    10  )
    11  
    12  func main() {
    13  	t, err := tty.Open()
    14  	if err != nil {
    15  		log.Fatal(err)
    16  	}
    17  	defer t.Close()
    18  
    19  	go func() {
    20  		for ws := range t.SIGWINCH() {
    21  			fmt.Println("Resized", ws.W, ws.H)
    22  		}
    23  	}()
    24  
    25  	clean,err := t.Raw()
    26  	if err != nil {
    27  		log.Fatal(err)
    28  	}
    29  	defer clean()
    30  
    31  	fmt.Println("Hit any key")
    32  	for {
    33  		r, err := t.ReadRune()
    34  		if err != nil {
    35  			log.Fatal(err)
    36  		}
    37  		if r == 0 {
    38  			continue
    39  		}
    40  		fmt.Printf("0x%X: %c\n", r, r)
    41  		if !t.Buffered() {
    42  			break
    43  		}
    44  	}
    45  }
    46  

View as plain text