From d25ac560264698b1f77b43e4786f9bccc35c91e6 Mon Sep 17 00:00:00 2001 From: henderjon Date: Thu, 21 Sep 2023 09:01:28 -0500 Subject: [PATCH] adds Config option to disable bell; DisableBell --- readline.go | 33 ++++++++++++++++++--------------- terminal.go | 4 +++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/readline.go b/readline.go index 63b9171..38100e7 100644 --- a/readline.go +++ b/readline.go @@ -1,20 +1,20 @@ // Readline is a pure go implementation for GNU-Readline kind library. // // example: -// rl, err := readline.New("> ") -// if err != nil { -// panic(err) -// } -// defer rl.Close() // -// for { -// line, err := rl.Readline() -// if err != nil { // io.EOF -// break -// } -// println(line) -// } +// rl, err := readline.New("> ") +// if err != nil { +// panic(err) +// } +// defer rl.Close() // +// for { +// line, err := rl.Readline() +// if err != nil { // io.EOF +// break +// } +// println(line) +// } package readline import ( @@ -68,6 +68,8 @@ type Config struct { // it use in IM usually. UniqueEditLine bool + DisableBell bool + // filter input runes (may be used to disable CtrlZ or for translating some keys to different actions) // -> output = new (translated) rune and true/false if continue with processing this one FuncFilterInputRune func(rune) (rune, bool) @@ -301,9 +303,10 @@ func (i *Instance) Write(b []byte) (int, error) { // WriteStdin prefill the next Stdin fetch // Next time you call ReadLine() this value will be writen before the user input // ie : -// i := readline.New() -// i.WriteStdin([]byte("test")) -// _, _= i.Readline() +// +// i := readline.New() +// i.WriteStdin([]byte("test")) +// _, _= i.Readline() // // gives // diff --git a/terminal.go b/terminal.go index 38413d0..1e1774a 100644 --- a/terminal.go +++ b/terminal.go @@ -214,7 +214,9 @@ func (t *Terminal) ioloop() { } func (t *Terminal) Bell() { - fmt.Fprintf(t, "%c", CharBell) + if !t.cfg.DisableBell { + fmt.Fprintf(t, "%c", CharBell) + } } func (t *Terminal) Close() error {