Skip to content

Golang implementation of "getchar" function which allows you to intercept entered symbols right after key presses.

License

Notifications You must be signed in to change notification settings

NexoMichael/inputreader

Repository files navigation

Golang implementation of "getchar" function which allows you to intercept entered symbols right after key presses.

BuildStatus Widget CodeCovWidget GoReport Widget GoDoc Widget

Installation

Use the go command:

go get github.com/NexoMichael/inputreader

Usage

package main

import (
    "fmt"
    "os"
    "syscall"

    input "github.com/NexoMichael/inputreader"
)

func main() {
    reader, _ := input.NewInputReader(os.Stdin)
    defer func() {
        reader.Close()
    }()

    var b [1]byte
    for {
        n, err := reader.Read(b[:])
        if err != nil || n == 0 {
            return
        }

        fmt.Printf(" - code is %d\n\r", b[0])

        switch syscall.Signal(b[0]) {
        case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
            return
        }
    }
}

Requirements

inputreader package requires Go >= 1.5.

Copyright

Copyright (C) 2018 by Mikhail Kochegarov mikhail@kochegarov.biz.

UUID package releaed under MIT License. See LICENSE for details.

About

Golang implementation of "getchar" function which allows you to intercept entered symbols right after key presses.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages