Convert Figma logo to code with AI

chzyer logoreadline

Readline is a pure go(golang) implementation for GNU-Readline kind library

2,076
273
2,076
106

Top Related Projects

A small self-contained alternative to readline and libedit

Library for building powerful interactive command line applications in Python

A bash inspired readline implementation for PowerShell

Quick Overview

chzyer/readline is a pure Go implementation of the GNU readline library. It provides a set of functions for reading lines of text from user input with line editing and history capabilities, making it useful for building interactive command-line interfaces in Go applications.

Pros

  • Pure Go implementation, no C dependencies
  • Supports various terminal key bindings and editing features
  • Provides history management and search functionality
  • Cross-platform compatibility (Windows, macOS, Linux)

Cons

  • May not have all features of the original GNU readline library
  • Limited documentation and examples compared to more established libraries
  • Potential performance differences compared to C-based implementations
  • Less active development and maintenance compared to some alternatives

Code Examples

  1. Basic line reading:
import "github.com/chzyer/readline"

rl, err := readline.New("> ")
if err != nil {
    panic(err)
}
defer rl.Close()

line, err := rl.Readline()
if err != nil {
    panic(err)
}
fmt.Println("You entered:", line)
  1. Using custom completer:
completer := readline.NewPrefixCompleter(
    readline.PcItem("say",
        readline.PcItem("hello"),
        readline.PcItem("bye"),
    ),
    readline.PcItem("help"),
)

rl, err := readline.NewEx(&readline.Config{
    Prompt:       "> ",
    AutoComplete: completer,
})
  1. Reading with a password prompt:
rl, err := readline.New("> ")
if err != nil {
    panic(err)
}
defer rl.Close()

password, err := rl.ReadPassword("Enter password: ")
if err != nil {
    panic(err)
}
fmt.Println("Password entered:", string(password))

Getting Started

To use chzyer/readline in your Go project, follow these steps:

  1. Install the package:

    go get -u github.com/chzyer/readline
    
  2. Import the package in your Go code:

    import "github.com/chzyer/readline"
    
  3. Create a new readline instance and use it to read input:

    rl, err := readline.New("> ")
    if err != nil {
        panic(err)
    }
    defer rl.Close()
    
    for {
        line, err := rl.Readline()
        if err != nil { // io.EOF, readline.ErrInterrupt
            break
        }
        fmt.Println("Line:", line)
    }
    

This basic setup allows you to start reading lines with a simple prompt. You can customize the behavior by providing additional configuration options when creating the readline instance.

Competitor Comparisons

A small self-contained alternative to readline and libedit

Pros of linenoise

  • Lightweight and simple implementation (single C file)
  • No external dependencies, easy to integrate
  • Cross-platform support (Unix, Windows, Android)

Cons of linenoise

  • Limited advanced features compared to readline
  • Less extensive documentation and community support
  • Fewer customization options for complex use cases

Code comparison

linenoise:

char *line = linenoise("hello> ");
if (line != NULL) {
    printf("You wrote: %s\n", line);
    linenoiseFree(line);
}

readline:

rl, err := readline.New("> ")
if err != nil {
    panic(err)
}
defer rl.Close()
line, err := rl.Readline()
if err != nil {
    panic(err)
}
fmt.Printf("Line: %s\n", line)

Key differences

  • linenoise is written in C, while readline is written in Go
  • readline offers more advanced features like history search and custom completion
  • linenoise focuses on simplicity and small footprint, while readline provides a more feature-rich experience

Use cases

  • linenoise: Ideal for embedded systems, simple CLI tools, or projects requiring minimal dependencies
  • readline: Better suited for complex interactive shells, applications needing advanced line editing features, or Go-based projects

Library for building powerful interactive command line applications in Python

Pros of python-prompt-toolkit

  • More feature-rich with advanced functionality like syntax highlighting and multi-line editing
  • Pure Python implementation, making it easier to install and use across different platforms
  • Actively maintained with regular updates and improvements

Cons of python-prompt-toolkit

  • Potentially slower performance compared to readline's C implementation
  • Steeper learning curve due to more complex API and additional features
  • Larger codebase and dependencies, which may increase project size

Code Comparison

python-prompt-toolkit:

from prompt_toolkit import prompt

user_input = prompt('Enter your name: ')
print(f"Hello, {user_input}!")

readline:

import readline

readline.parse_and_bind('tab: complete')
user_input = input('Enter your name: ')
print(f"Hello, {user_input}!")

Both libraries provide input functionality, but python-prompt-toolkit offers more advanced features out of the box, while readline focuses on basic line editing and history. python-prompt-toolkit's approach is more Pythonic and user-friendly, whereas readline requires additional configuration for features like tab completion.

A bash inspired readline implementation for PowerShell

Pros of PSReadLine

  • More comprehensive feature set, including syntax highlighting and multi-line editing
  • Specifically designed for PowerShell, offering better integration and PowerShell-specific functionality
  • Actively maintained with frequent updates and improvements

Cons of PSReadLine

  • Limited to PowerShell environment, not as versatile for other platforms or languages
  • Potentially more complex to set up and configure compared to readline

Code Comparison

PSReadLine:

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

readline:

rl, err := readline.New("> ")
if err != nil {
    panic(err)
}
defer rl.Close()

Key Differences

  • PSReadLine is tailored for PowerShell, while readline is a more general-purpose Go library
  • PSReadLine offers more advanced features like predictive IntelliSense and custom key bindings
  • readline provides a simpler, lightweight solution for basic line editing functionality

Use Cases

  • PSReadLine: Ideal for PowerShell users and developers looking for enhanced command-line experience
  • readline: Suitable for Go projects requiring basic line editing capabilities across different platforms

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status Software License Version GoDoc OpenCollective OpenCollective

A powerful readline library in Linux macOS Windows Solaris AIX

Guide

Repos using readline

cockroachdb robertkrimen/otto empire mehrdadrad/mylg knq/usql youtube/doorman bom-d-van/harp abiosoft/ishell Netflix/hal-9001 docker/go-p9p

Feedback

If you have any questions, please submit a github issue and any pull requests is welcomed :)

Backers

Love Readline? Help me keep it alive by donating funds to cover project expenses!
[Become a backer]

Sponsors

Become a sponsor and get your logo here on our Github page. [Become a sponsor]