package keymapimport ()// readline global options specific to this library.var readlineOptions = map[string]interface{}{// General edition"autopairs": false,// Completion"autocomplete": false,"completion-list-separator": "--","completion-selection-style": "\x1b[1;30m",// Prompt & General UI"transient-prompt": false,"usage-hint-always": false,"history-autosuggest": false,"multiline-column": true,"multiline-column-numbered": false,}// ReloadConfig parses all valid .inputrc configurations and immediately// updates/reloads all related settings (editing mode, variables behavior, etc.)func ( *Engine) ( ...inputrc.Option) ( error) {// Builtin Go binds (in addition to default readline binds) .loadBuiltinOptions() .loadBuiltinBinds() , := user.Current()// Parse library-specific configurations. // // This library implements various additional commands and keymaps. // Parse the configuration with a specific App name, ignoring errors.inputrc.UserDefault(, .config, inputrc.WithApp("go"))// Parse user configurations. // // Those default settings are the base options often needed // by /etc/inputrc on various Linux distros (for special keys). := []inputrc.Option{inputrc.WithMode("emacs"),inputrc.WithTerm(os.Getenv("TERM")), } = append(, ...)// This will only overwrite binds that have been // set in those configs, and leave the default ones // (those just set above), so as to keep most of the // default functionality working out of the box. = inputrc.UserDefault(, .config, ...)if != nil {return }// Some configuration variables might have an // effect on our various keymaps and bindings. .overrideBindsSpecial()// Startup editing modeswitch .config.GetString("editing-mode") {case"emacs": .main = Emacscase"vi": .main = ViInsert }returnnil}// loadBuiltinOptions loads some options specific to// this library, if they are not loaded already.func ( *Engine) () {for , := rangereadlineOptions {if := .config.Get(); == nil { .config.Set(, ) } }}// loadBuiltinBinds adds additional command mappings that are not part// of the standard C readline configuration: those binds therefore can// reference commands or keymaps only implemented/used in this library.func ( *Engine) () {// Emacs specialsfor , := rangeemacsKeys { .config.Binds[string(Emacs)][] = }// Vim main keymapsfor , := rangevicmdKeys { .config.Binds[string(ViCommand)][] = .config.Binds[string(ViMove)][] = .config.Binds[string(Vi)][] = }for , := rangeviinsKeys { .config.Binds[string(ViInsert)][] = }// Vim local keymaps .config.Binds[string(Visual)] = visualKeys .config.Binds[string(ViOpp)] = vioppKeys .config.Binds[string(MenuSelect)] = menuselectKeys .config.Binds[string(Isearch)] = menuselectKeys// Default TTY bindsfor , := range .config.Binds { [inputrc.Unescape(`\C-C`)] = inputrc.Bind{Action: "abort"} }}// overrideBindsSpecial overwrites some binds as dictated by the configuration variables.func ( *Engine) () {// Disable completion functions if requiredif .config.GetBool("disable-completion") {for , := range .config.Binds {for , := range {switch .Action {case"complete", "menu-complete", "possible-completions": [] = inputrc.Bind{Action: "self-insert"} } } } }}func printBindsReadable( []string, map[string][]string) {for , := range { := []sort.Strings()switch {caselen() == 0:caselen() > 5:var []stringfor := 0; < 5; ++ { = append(, "\""+[]+"\"") } := strings.Join(, ", ")fmt.Printf("%s can be found on %s ...\n", , )default:var []stringfor , := range { = append(, "\""++"\"") } := strings.Join(, ", ")fmt.Printf("%s can be found on %s\n", , ) } }}func printBindsInputrc( []string, map[string][]string) {for , := range { := []sort.Strings()iflen() > 0 {for , := range {fmt.Printf("\"%s\": %s\n", , ) } } }}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.