label_printer/printer/printer.go
TT-392 4a0a055234 Squashed 'faxmachine/' content from commit d23200b
git-subtree-dir: faxmachine
git-subtree-split: d23200bcfdedb9f8cc57e6a3c65b5ef93fcbfd19
2024-09-12 20:45:00 +02:00

38 lines
628 B
Go

package printer
import (
"fmt"
"io"
"os"
"os/exec"
)
type Printer struct {
devicePath string
}
func New(devicePath string) *Printer {
return &Printer{
devicePath: devicePath,
}
}
func (p *Printer) PrintText(text string) error {
lp, err := os.OpenFile(p.devicePath, os.O_WRONLY, 0)
if err != nil {
return fmt.Errorf("failed to open: %v", err)
}
defer lp.Close()
cmd := exec.Command("./printtext", text)
cmd.Stdout = lp
return cmd.Run()
}
func (p *Printer) PrintImage(data io.Reader, caption string) error {
cmd := exec.Command("./printimg", p.devicePath, caption)
cmd.Stdin = data
return cmd.Run()
}