From 0de2cbe553b79580847a0e7c713c4e8b209fd31a Mon Sep 17 00:00:00 2001 From: "Mike JS. Choi" Date: Tue, 5 Jun 2018 11:20:28 -0700 Subject: [PATCH] Add continuous evaluation to key binding table --- key/key.go | 18 ++++++++++++------ key/key_test.go | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/key/key.go b/key/key.go index d1b1932..6990ae9 100644 --- a/key/key.go +++ b/key/key.go @@ -35,6 +35,7 @@ const ( PreviousConflict = "previous" QuitApplication = "quit" ShowHelp = "help" + ContinuousEvaluation = "cont_eval" ) // defaultBinding is used when the user has not specified any of the @@ -52,6 +53,7 @@ var defaultBinding = Binding{ PreviousConflict: "p", QuitApplication: "q", ShowHelp: "h", + ContinuousEvaluation: "false", } // LoadSettings looks for a user specified key-binding settings file - `$HOME/.fac.yml` @@ -118,7 +120,7 @@ func (b Binding) consolidate() { if !ok || userValue == "" { b[key] = defaultValue - } else if len(userValue) > 1 { + } else if len(userValue) > 1 && userValue != "false" && userValue != "true" { b[key] = string(userValue[0]) } } @@ -126,14 +128,12 @@ func (b Binding) consolidate() { // verify looks through the user's key-binding settings and looks for any infractions such as.. // 1. Invalid/ignored key-binding keys -// 2. Multi-character key-mappings +// 2. Multi-character key-mappings (except for `cont_eval`) // 3. Duplicate key-mappings func (b Binding) verify() (warnings []string, fatals []string) { bindTable := map[string][]string{} for k, v := range b { - bindTable[string(v[0])] = append(bindTable[string(v[0])], k) - // Check for "1. Invalid/ignored key-binding keys" if _, ok := defaultBinding[k]; !ok { warnings = append(warnings, fmt.Sprintf("Invalid key: \"%s\" will be ignored", k)) @@ -142,9 +142,15 @@ func (b Binding) verify() (warnings []string, fatals []string) { } // Check for "2. Multi-character key-mappings" - if len(v) > 1 { - warnings = append(warnings, fmt.Sprintf("Illegal multi-character mapping: \"%s\" will be interpreted as '%s'", v, string(v[0]))) + if k == ContinuousEvaluation && v != "false" && v != "true" { + fatals = append(fatals, fmt.Sprintf("Invalid value: value for key '%s' must either be true or false", ContinuousEvaluation)) continue + } else if len(v) > 1 && k != ContinuousEvaluation { + abbreviated := string(v[0]) + warnings = append(warnings, fmt.Sprintf("Illegal multi-character mapping: \"%s\" will be interpreted as '%s'", v, abbreviated)) + bindTable[abbreviated] = append(bindTable[abbreviated], k) + } else { + bindTable[v] = append(bindTable[v], k) } } diff --git a/key/key_test.go b/key/key_test.go index 1b2a8eb..6bb8236 100644 --- a/key/key_test.go +++ b/key/key_test.go @@ -36,10 +36,7 @@ var tests = []struct { SelectLocal: "i", SelectIncoming: "incoming", }, - expected: Binding{ - SelectLocal: "l", - SelectIncoming: "i", - }, + expected: nil, warnings: []string{ "Illegal multi-character mapping: \"incoming\" will be interpreted as 'i'", }, @@ -47,6 +44,19 @@ var tests = []struct { "Duplicate key-mapping: \"select_incoming, select_local\" are all represented by 'i'", }, }, + { + settings: Binding{ + ContinuousEvaluation: "kinda", + SelectIncoming: "i", + SelectLocal: "i", + }, + expected: nil, + warnings: nil, + fatals: []string{ + "Invalid value: value for key 'cont_eval' must either be true or false", + "Duplicate key-mapping: \"select_incoming, select_local\" are all represented by 'i'", + }, + }, { settings: Binding{ ShowLinesDown: "d",