31 lines
566 B
Go
31 lines
566 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/hennedo/escpos"
|
|
"github.com/qiniu/iconv"
|
|
)
|
|
|
|
func encode(input string) []byte {
|
|
cd, err := iconv.Open("cp437", "utf-8")
|
|
if err != nil {
|
|
log.Fatalf("failed to load cp437 encoding: %v\n", err)
|
|
}
|
|
outbuf := make([]byte, len(input)+32)
|
|
encoded, _, err := cd.Conv([]byte(input), outbuf)
|
|
if err != nil {
|
|
log.Fatalf("failed to convert to cp437: %v\n", err)
|
|
}
|
|
return encoded
|
|
}
|
|
|
|
func main() {
|
|
p := escpos.New(os.Stdout)
|
|
p.WriteRaw(encode(os.Args[1]))
|
|
p.LineFeed()
|
|
p.LineFeed()
|
|
p.LineFeed()
|
|
p.PrintAndCut()
|
|
}
|