input_autocomplete

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 6 Imported by: 2

README

go-input-autocomplete

A useful input that can autocomplete users path to directories or files when tab key is pressed. The purpose is to be similar to bash/cmd native autocompletion.

Installation

go get github.com/JoaoDanielRufino/go-input-autocomplete

Usage

package main

import (
	"fmt"
	input_autocomplete "github.com/JoaoDanielRufino/go-input-autocomplete"
)

func main() {
	path, err := input_autocomplete.Read("Path: ")

	if err != nil {
		panic(err)
	}

	fmt.Println(path)
}

How it works

gif

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Autocomplete

func Autocomplete(path string) []string

func EnableVirtualTerminalWindows added in v1.1.0

func EnableVirtualTerminalWindows() error

func Read

func Read(text string) (string, error)

Types

type Cmd

type Cmd struct{}

func (Cmd) IsDir

func (c Cmd) IsDir(path string) (bool, error)

func (Cmd) ListContent

func (c Cmd) ListContent(path string) ([]string, error)

type Cursor

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

func NewCursor

func NewCursor() *Cursor

func (*Cursor) GetPosition

func (c *Cursor) GetPosition() int

func (*Cursor) IncrementPosition

func (c *Cursor) IncrementPosition()

func (*Cursor) MoveLeft

func (c *Cursor) MoveLeft()

func (*Cursor) MoveLeftNPos

func (c *Cursor) MoveLeftNPos(x int)

func (*Cursor) MoveRight

func (c *Cursor) MoveRight()

func (*Cursor) SetPosition

func (c *Cursor) SetPosition(newPos int)

type DirChecker

type DirChecker interface {
	IsDir(path string) (bool, error)
}

type DirListChecker

type DirListChecker interface {
	DirLister
	DirChecker
}

type DirLister

type DirLister interface {
	ListContent(path string) ([]string, error)
}

type Input

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

func NewInput

func NewInput(fixedText string) *Input

func (*Input) AddChar

func (i *Input) AddChar(char rune)

func (*Input) Autocomplete

func (i *Input) Autocomplete()

func (*Input) GetCurrentText

func (i *Input) GetCurrentText() string

func (*Input) MoveCursorLeft

func (i *Input) MoveCursorLeft()

func (*Input) MoveCursorRight

func (i *Input) MoveCursorRight()

func (*Input) Print

func (i *Input) Print()

func (*Input) RemoveChar

func (i *Input) RemoveChar()

func (*Input) RemoveLastSlashIfNeeded

func (i *Input) RemoveLastSlashIfNeeded()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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