You can easily write a portable one. Just read and discard until no more 
available. Then make the call to the input read. 

> On May 3, 2019, at 7:28 AM, Steve Mynott <steve.myn...@gmail.com> wrote:
> 
> I've a terminal app where I read y/n confirm using  fmt.Scanln and I'm trying 
> to flush the keyboard buffer before this.
> 
> On linux (and probably other UNIX systems) I can use 
> 
> unix.Syscall(unix.SYS_IOCTL, 0, unix.TCFLSH, 0)
> 
> but this isn't portable (specifically to macOS which it would be nice to 
> support) since on cross compiling I see "undefined: unix.TCFLSH" Maybe this 
> is some BSDism?
> 
> Rossetta code suggests using a ncurses function from 
> https://github.com/rthornton128/goncurses but that seems sort of ugly?
> 
> https://rosettacode.org/wiki/Keyboard_input/Flush_the_keyboard_buffer#Go  
> 
> Is there a simple way which works at least on UNIX and macOS?
> 
> -- 
> Steve Mynott <steve.myn...@gmail.com>
> cv25519/ECF8B611205B447E091246AF959E3D6197190DD5
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to