Skip to content

Commit fa15200

Browse files
committed
Save line
1 parent cad4edc commit fa15200

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmd/gosgif/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ import (
55
"image/gif"
66
"io"
77
"log"
8+
"math"
89
"os"
10+
"strings"
11+
"syscall"
912
"time"
13+
"unsafe"
1014

1115
"github.com/mattn/go-sixel"
1216
)
1317

18+
type window struct {
19+
Row uint16
20+
Col uint16
21+
Xpixel uint16
22+
Ypixel uint16
23+
}
24+
1425
func main() {
1526
var r io.Reader
1627
if len(os.Args) > 1 {
@@ -33,6 +44,19 @@ func main() {
3344
enc.Width = g.Config.Width
3445
enc.Height = g.Config.Height
3546

47+
var w window
48+
_, _, err = syscall.Syscall(syscall.SYS_IOCTL,
49+
os.Stdout.Fd(),
50+
syscall.TIOCGWINSZ,
51+
uintptr(unsafe.Pointer(&w)),
52+
)
53+
if w.Xpixel > 0 && w.Ypixel > 0 && w.Col > 0 && w.Row > 0 {
54+
height := float64(w.Ypixel) / float64(w.Row)
55+
lines := int(math.Ceil(float64(enc.Height) / height))
56+
fmt.Print(strings.Repeat("\n", lines))
57+
fmt.Printf("\x1b[%dA", lines)
58+
fmt.Print("\x1b[s")
59+
}
3660
for {
3761
t := time.Now()
3862
for j := 0; j < len(g.Image); j++ {

0 commit comments

Comments
 (0)