github.com/axw/llgo@v0.0.0-20160805011314-95b5fe4dca20/third_party/liner/README.md (about)

     1  Liner
     2  =====
     3  
     4  Liner is a command line editor with history. It was inspired by linenoise;
     5  everything Unix-like is a VT100 (or is trying very hard to be). If your
     6  terminal is not pretending to be a VT100, change it. Liner also support
     7  Windows.
     8  
     9  Liner is released under the X11 license (which is similar to the new BSD
    10  license).
    11  
    12  Line Editing
    13  ------------
    14  
    15  The following line editing commands are supported on platforms and terminals
    16  that Liner supports:
    17  
    18  Keystroke    | Action
    19  ---------    | ------
    20  Ctrl-A, Home | Move cursor to beginning of line
    21  Ctrl-E, End  | Move cursor to end of line
    22  Ctrl-B, Left | Move cursor one character left
    23  Ctrl-F, Right| Move cursor one character right
    24  Ctrl-Left, Alt-B    | Move cursor to previous word
    25  Ctrl-Right, Alt-F   | Move cursor to next word
    26  Ctrl-D, Del  | (if line is *not* empty) Delete character under cursor
    27  Ctrl-D       | (if line *is* empty) End of File - usually quits application
    28  Ctrl-C       | Reset input (create new empty prompt)
    29  Ctrl-L       | Clear screen (line is unmodified)
    30  Ctrl-T       | Transpose previous character with current character
    31  Ctrl-H, BackSpace | Delete character before cursor
    32  Ctrl-W       | Delete word leading up to cursor
    33  Ctrl-K       | Delete from cursor to end of line
    34  Ctrl-U       | Delete from start of line to cursor
    35  Ctrl-P, Up   | Previous match from history
    36  Ctrl-N, Down | Next match from history
    37  Ctrl-R       | Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
    38  Ctrl-Y       | Paste from Yank buffer (Alt-Y to paste next yank instead)
    39  Tab          | Next completion
    40  Shift-Tab    | (after Tab) Previous completion
    41  
    42  Getting started
    43  -----------------
    44  
    45  ```go
    46  package main
    47  
    48  import (
    49  	"log"
    50  	"os"
    51  	"path/filepath"
    52  	"strings"
    53  
    54  	"github.com/peterh/liner"
    55  )
    56  
    57  var (
    58  	history_fn = filepath.Join(os.TempDir(), ".liner_example_history")
    59  	names      = []string{"john", "james", "mary", "nancy"}
    60  )
    61  
    62  func main() {
    63  	line := liner.NewLiner()
    64  	defer line.Close()
    65  
    66  	line.SetCtrlCAborts(true)
    67  
    68  	line.SetCompleter(func(line string) (c []string) {
    69  		for _, n := range names {
    70  			if strings.HasPrefix(n, strings.ToLower(line)) {
    71  				c = append(c, n)
    72  			}
    73  		}
    74  		return
    75  	})
    76  
    77  	if f, err := os.Open(history_fn); err == nil {
    78  		line.ReadHistory(f)
    79  		f.Close()
    80  	}
    81  
    82  	if name, err := line.Prompt("What is your name? "); err == nil {
    83  		log.Print("Got: ", name)
    84  		line.AppendHistory(name)
    85  	} else if err == liner.ErrPromptAborted {
    86  		log.Print("Aborted")
    87  	} else {
    88  		log.Print("Error reading line: ", err)
    89  	}
    90  
    91  	if f, err := os.Create(history_fn); err != nil {
    92  		log.Print("Error writing history file: ", err)
    93  	} else {
    94  		line.WriteHistory(f)
    95  		f.Close()
    96  	}
    97  }
    98  ```
    99  
   100  For documentation, see http://godoc.org/github.com/peterh/liner