-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_linux.go
64 lines (54 loc) · 1.37 KB
/
print_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"image/color"
"log/slog"
"os/exec"
"slices"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
func print(a fyne.App, w fyne.Window) {
slog.Info("printing")
dlg := dialog.NewCustomWithoutButtons("Printing...", container.NewStack(canvas.NewRectangle(color.Transparent), widget.NewProgressBarInfinite()), w)
dlg.Show()
var lines []string
lines = append(lines, "AUTO-GENERATED by gecfg-editor version "+a.Metadata().Version)
lines = append(lines, "<github.com/MatusOllah/gecfg-editor>")
lines = append(lines, "")
lines = append(lines, "File name: "+openFileName)
lines = append(lines, "")
var keys []string
for k, _ := range theMap {
keys = append(keys, k)
}
slices.Sort(keys)
for _, k := range keys {
lines = append(lines, fmt.Sprintf("%s (%T) = %v", k, theMap[k], theMap[k]))
}
if err := printOneDocument(lines); err != nil {
slog.Error(err.Error())
dlg.Hide()
dialog.NewError(err, w).Show()
return
}
dlg.Hide()
}
func printOneDocument(lines []string) error {
cmd := exec.Command("lp")
slog.Info("executing", "path", cmd.Path, "args", cmd.Args)
if err := cmd.Start(); err != nil {
return err
}
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
for _, line := range lines {
fmt.Fprintf(stdin, line+"\r\n")
}
return stdin.Close()
}