Allow escaping meta characters with backslashes

One can escape meta characters in extended-search mode with backslashes.

  Prefixes:
    \'
    \!
    \^

  Suffix:
    \$

  Term separator:
    \<SPACE>

To keep things simple, we are not going to support escaping of escaped
sequences (e.g. \\') for matching them literally.

Since this is a breaking change, we will bump the minor version.

Close #444
This commit is contained in:
Junegunn Choi
2017-08-09 23:25:32 +09:00
parent dc55e68524
commit e85a8a68d0
4 changed files with 63 additions and 22 deletions

View File

@@ -281,9 +281,13 @@ func defaultKeymap() map[int][]action {
return keymap
}
func trimQuery(query string) []rune {
return []rune(strings.Replace(query, "\t", " ", -1))
}
// NewTerminal returns new Terminal object
func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
input := []rune(opts.Query)
input := trimQuery(opts.Query)
var header []string
if opts.Reverse {
header = opts.Header
@@ -1694,13 +1698,13 @@ func (t *Terminal) Loop() {
case actPreviousHistory:
if t.history != nil {
t.history.override(string(t.input))
t.input = []rune(t.history.previous())
t.input = trimQuery(t.history.previous())
t.cx = len(t.input)
}
case actNextHistory:
if t.history != nil {
t.history.override(string(t.input))
t.input = []rune(t.history.next())
t.input = trimQuery(t.history.next())
t.cx = len(t.input)
}
case actSigStop: