1
1
Fork 0

Adds readme and license info

This commit is contained in:
sloum 2021-04-03 20:15:57 -07:00
parent 4863be6bba
commit cf6f54aa94
2 changed files with 50 additions and 31 deletions

20
README.md Normal file
View File

@ -0,0 +1,20 @@
# qline
qline provides one function: provide an editable input field to the user along with a prompt and initial data.
Unlike readline, editline, linenoise, etc. there is no history, no word jumping, or other builtin features. Just a simple, navigable, editable line of text with an optional prompt.
## Usage
``` go
var prompt string = "> "
var default string = "Edit Me"
var in string = qline.GetInput(prompt, default)
```
Arrow keys, backspace, delete, home, and end all work as one might expect. There are no CTRL keys, no vi mode, etc.
## License
qline is available under the MIT license. A copy of which is included as a comment in the sole source code file for this package.

View File

@ -1,5 +1,34 @@
package qline
// qline is a line input library for terminals that utilize
// vt100 compatible escape sequences
//
// Copyright © 2021 Brian Evans
//
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the “Software”), to deal in the
// Software without restriction, including without
// limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
import (
"bufio"
"fmt"
@ -17,7 +46,6 @@ const (
Delete
Home
End
PrintScreen
PageUp
PageDown
Escape rune = 27
@ -225,6 +253,7 @@ func readKey(reader *bufio.Reader) (rune, error) {
case isDeleteKey(escSeq):
char = Delete
case escSeq[len(escSeq)-1] == 'R':
// This is a request for cursor position
_, cols, err := parseCursorPosition(escSeq)
if err == nil {
err = fmt.Errorf("response")
@ -271,33 +300,3 @@ func isEndKey(seq string) bool {
}
}
func PrintKey(k rune) {
switch true {
case k == UpArrow:
fmt.Println("UpArrow")
case k == DownArrow:
fmt.Println("DownArrow")
case k == LeftArrow:
fmt.Println("LeftArrow")
case k == RightArrow:
fmt.Println("RightArrow")
case k == Escape:
fmt.Println("Escape")
case k == NewLine:
fmt.Println("NewLine")
case k == CarriageReturn:
fmt.Println("CarriageReturn")
case k == Delete:
fmt.Println("Delete")
case k == Home:
fmt.Println("Home")
case k == End:
fmt.Println("End")
case k == BackSpace:
fmt.Println("BackSpace")
default:
fmt.Printf("%c (%d)\n", k, k)
}
}