Welcome to mirror list, hosted at ThFree Co, Russian Federation.

prompt.go « prompt « Bowery « github.com « vendor - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f6037299efdc0f3886268426c06414ed676696cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2013-2015 Bowery, Inc.

// Package prompt implements a cross platform line-editing prompt. It also
// provides routines to use ANSI escape sequences across platforms for
// terminal connected io.Readers/io.Writers.
//
// If os.Stdin isn't connected to a terminal or (on Unix)if the terminal
// doesn't support the ANSI escape sequences needed a fallback prompt is
// provided that doesn't do line-editing. Unix terminals that are not supported
// will have the TERM environment variable set to either "dumb" or "cons25".
//
// The keyboard shortcuts are similar to those found in the Readline library:
//
//   - Enter / CTRL+D
//     - End the line.
//   - CTRL+C
//     - End the line, return error `ErrCTRLC`.
//   - Backspace
//     - Remove the character to the left.
//   - CTRL+L
//     - Clear the screen(keeping the current lines content).
//   - Home / End
//     - Jump to the beginning/end of the line.
//   - Up arrow / Down arrow
//     - Go back and forward in the history.
//   - Left arrow / Right arrow
//     - Move left/right one character.
//   - Delete
//     - Remove the character to the right.
package prompt

// Basic is a wrapper around Terminal.Basic.
func Basic(prefix string, required bool) (string, error) {
	term, err := NewTerminal()
	if err != nil {
		return "", err
	}
	defer term.Close()

	return term.Basic(prefix, required)
}

// BasicDefault is a wrapper around Terminal.BasicDefault.
func BasicDefault(prefix, def string) (string, error) {
	term, err := NewTerminal()
	if err != nil {
		return "", err
	}
	defer term.Close()

	return term.BasicDefault(prefix, def)
}

// Ask is a wrapper around Terminal.Ask.
func Ask(question string) (bool, error) {
	term, err := NewTerminal()
	if err != nil {
		return false, err
	}
	defer term.Close()

	return term.Ask(question)
}

// Custom is a wrapper around Terminal.Custom.
func Custom(prefix string, test func(string) (string, bool)) (string, error) {
	term, err := NewTerminal()
	if err != nil {
		return "", err
	}
	defer term.Close()

	return term.Custom(prefix, test)
}

// Password is a wrapper around Terminal.Password.
func Password(prefix string) (string, error) {
	term, err := NewTerminal()
	if err != nil {
		return "", err
	}
	defer term.Close()

	return term.Password(prefix)
}