sleepycat

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

sleepycat

sleepycat is a Go package for reading user input from the terminal.

The package provides typed input functions and a consistent option-based API for prompts, validation, and retry behavior.

Installation

go get github.com/Rajdeep-Nemo/sleepycat

Example

package main

import (
	"fmt"
	"os"

	"github.com/Rajdeep-Nemo/sleepycat"
)

func main() {
	age, err := sleepycat.Int(
		sleepycat.Prompt("Enter age: "),
		sleepycat.MaxAttempt(3),
	)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	fmt.Println(age)
}

Available

Input
  • Int()
  • Float32()
  • Float64()
  • Bool()
  • String()
  • Byte()
  • Rune()
  • Int8()
  • Int16()
  • Int32()
  • Int64()
  • Uint()
  • Uint8()
  • Uint16()
  • Uint32()
  • Uint64()
Options
  • Prompt()
  • MaxAttempt()

Project Structure

sleepycat/
├── .github/
│   └── workflows/
│       └── ci.yml              # Continuous integration
│
├── examples/                   # Example programs
│   ├── int/
│   │   └── main.go             
│   └── ...                     # More Examples
│
├── internal/
│   └── input.go                # Terminal input helpers
│
├── config.go                   # Config and functional options
├── parser.go                   # Shared parsing/retry logic
├── int.go                      # Integer input
├── float32.go                  # 32 bit float input
├── float64.go                  # 64 bit float input
├── ...                         # Other inputs
│
├── helpers_test.go             # Shared helper functions
├── int_test.go
├── float32_test.go
├── float64_test.go
├── ...                         # Other test cases
│
├── .gitignore
├── go.mod
├── go.sum
├── LICENSE
└── README.md

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(opts ...option) (bool, error)

Bool reads a boolean value from the input source.

func Byte

func Byte(opts ...option) (byte, error)

Byte reads a single ASCII character from the input source and returns it as a byte.

func Float32

func Float32(opts ...option) (float32, error)

Float32 reads a floating-point number from the input source and returns it as a float32.

func Float64

func Float64(opts ...option) (float64, error)

Float64 reads a floating-point number from the input source and returns it as a float64.

func Int

func Int(opts ...option) (int, error)

Int reads an integer from the input source and returns it as an int.

func Int8 added in v0.9.0

func Int8(opts ...option) (int8, error)

Int8 reads an integer from the input source and returns it as an int8.

func Int16 added in v0.9.0

func Int16(opts ...option) (int16, error)

Int16 reads an integer from the input source and returns it as an int16.

func Int32 added in v0.9.0

func Int32(opts ...option) (int32, error)

Int32 reads an integer from the input source and returns it as an int32.

func Int64 added in v0.9.0

func Int64(opts ...option) (int64, error)

Int64 reads an integer from the input source and returns it as an int64.

func MaxAttempt

func MaxAttempt(count int) option

MaxAttempt limits the number of input attempts. A value of 0 allows unlimited attempts.

func Prompt

func Prompt(inputPrompt string) option

Prompt sets the text displayed before reading input.

func Rune added in v0.8.0

func Rune(opts ...option) (rune, error)

Rune reads a Unicode code point from the input source.

func String

func String(opts ...option) (string, error)

String reads a string from the input source. MaxAttempt does not affect String because every input is valid.

func Uint added in v1.0.0

func Uint(opts ...option) (uint, error)

Uint reads an unsigned integer from the input source and returns it as a uint.

func Uint8 added in v1.0.0

func Uint8(opts ...option) (uint8, error)

Uint8 reads an unsigned integer from the input source and returns it as a uint8.

func Uint16 added in v1.0.0

func Uint16(opts ...option) (uint16, error)

Uint16 reads an unsigned integer from the input source and returns it as a uint16.

func Uint32 added in v1.0.0

func Uint32(opts ...option) (uint32, error)

Uint32 reads an unsigned integer from the input source and returns it as a uint32.

func Uint64 added in v1.0.0

func Uint64(opts ...option) (uint64, error)

Uint64 reads an unsigned integer from the input source and returns it as a uint64.

Types

This section is empty.

Directories

Path Synopsis
examples
boolean command
byte command
float32 command
float64 command
int command
int16 command
int32 command
int64 command
int8 command
rune command
string command
uint command
uint16 command
uint32 command
uint64 command
uint8 command

Jump to

Keyboard shortcuts

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