From cf6f54aa94b19a28ed563cd73a69f66d472956ae Mon Sep 17 00:00:00 2001 From: sloum Date: Sat, 3 Apr 2021 20:15:57 -0700 Subject: [PATCH] Adds readme and license info --- README.md | 20 ++++++++++++++++++ qline.go | 61 +++++++++++++++++++++++++++---------------------------- 2 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8dcb3de --- /dev/null +++ b/README.md @@ -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. + diff --git a/qline.go b/qline.go index d3760cd..4cfdb16 100644 --- a/qline.go +++ b/qline.go @@ -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) - } - -} -