sikh

package module
v0.0.0-...-f19515b Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 6 Imported by: 0

README

Sikh

A small stdin key-hooking library. It reads the raw input from a keypress, compares it against a map, and returns a string coresponding with the key pressed.

func Halt()
func ReadBytes()
func Start(handler func(string))

Usage

package main

import (
    "fmt"
    "github.com/kyleraywed/sikh"
)

func main() {
    // switch over the string and implement logic
	sikh.Start(func(s string) {
		switch s {
		case "[Ctrl+c]":
			sikh.Halt() // do not forget this
		case "[Esc]":
			fmt.Println("Trying to escape? Try ctrl+c")
		default:
			fmt.Println(s)
		}
	})

	// read raw bytes from keypresses until Esc is pressed
	sikh.ReadBytes()
}

Notes and design

  • Start blocks until Halt() is called; if you don't include some logic to call Halt(), you will have to kill the process yourself.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Halt

func Halt()

func ReadBytes

func ReadBytes()

Present the user with a prompt to easier map out keys, ESC to quit.

func Start

func Start(handler func(string))

Start reading keypresses. Define logic via a handler function.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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