inputreader

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2018 License: MIT Imports: 6 Imported by: 0

README

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 (C) 2018 by Mikhail Kochegarov mikhail@kochegarov.biz.

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InputLine

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

InputLine holds current eneterd line of symbols

func NewBuffer

func NewBuffer() *InputLine

NewBuffer returns new InputLine buffer with default size equal to 4 KB.

func (*InputLine) Buffer

func (l *InputLine) Buffer() []byte

Buffer returns current entered synmbols

func (*InputLine) ReadLine

func (l *InputLine) ReadLine(r io.Reader) ([]byte, error)

ReadLine tries to return a single line, not including the end-of-line bytes.

type InputReader

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

InputReader provides ReaderCloser interface for standart input or other input source pipe.

func NewInputReader

func NewInputReader(in *os.File) (*InputReader, error)

NewInputReader returns a new InputReader for *os.File pipe.

func (*InputReader) Close

func (r *InputReader) Close() (err error)

Close resets terminal settings to the initial state.

func (*InputReader) Read

func (r *InputReader) Read(p []byte) (n int, err error)

Read reads data into p. It returns the number of bytes read into p. The bytes are taken from at most one Read on the underlying Reader, hence n may be less than len(p). At EOF, the count will be zero and err will be io.EOF.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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