diff --git a/ec/run.go b/ec/run.go new file mode 100644 index 0000000..5295453 --- /dev/null +++ b/ec/run.go @@ -0,0 +1,52 @@ +package ec + +import( + "fmt" + "io" + "os" + "bufio" + "log" +) + +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 +Run(args []string) int { + 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)) + } + } + return 0 +} diff --git a/main.go b/main.go index e506673..07a6433 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import( "goblin/noext" "goblin/mergelbl" "goblin/basename" + "goblin/ec" ) func main() { @@ -46,6 +47,7 @@ func main() { "urlprs" : urlprs.Run, "noext" : noext.Run, "mergelbl" : mergelbl.Run, + "ec" : ec.Run, } if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {