2021-11-25 06:14:02 +03:00
|
|
|
package ec
|
|
|
|
|
|
|
|
import(
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"bufio"
|
|
|
|
"log"
|
2024-05-15 21:07:35 +03:00
|
|
|
"surdeus.su/core/cli/mtool"
|
2021-11-25 06:14:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const(
|
|
|
|
esc = '\\'
|
|
|
|
)
|
|
|
|
|
|
|
|
var(
|
|
|
|
CharMap = map[string]string{
|
|
|
|
"n":"\n",
|
|
|
|
"b":"\b",
|
|
|
|
"r":"\r",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func
|
|
|
|
handleEscChar(rd *bufio.Reader) error {
|
|
|
|
r, _, e := rd.ReadRune()
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
fmt.Print(CharMap[string(r)])
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
2023-03-24 16:54:51 +03:00
|
|
|
Run(flags *mtool.Flags) {
|
2021-11-25 06:14:02 +03:00
|
|
|
rd := bufio.NewReader(os.Stdin)
|
|
|
|
for {
|
|
|
|
r, _, e := rd.ReadRune()
|
|
|
|
if e == io.EOF {
|
|
|
|
break;
|
|
|
|
} else if e != nil {
|
|
|
|
log.Fatal(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if r == esc {
|
|
|
|
handleEscChar(rd)
|
|
|
|
} else {
|
|
|
|
fmt.Print(string(r))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|