123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package getch
- import (
- "bytes"
- "io"
- )
- func ReadLine(echo io.Writer, mask rune) (string, error) {
- var ret bytes.Buffer
- var err error
- if err = Start(); err == nil {
- var e *KeyEvent
- defer Stop()
- for err == nil && (e == nil || e.Code != KeyEnter) {
- if e, err = Getch(); e != nil {
- if e.Rune != 0 {
- ebytes := []byte(string(e.Rune))
- ret.Write(ebytes)
- if echo != nil {
- if mask == 0 {
- echo.Write(ebytes)
- } else {
- echo.Write([]byte(string(mask)))
- }
- }
- }
- }
- }
- }
- return ret.String(), err
- }
|