forked from asciinema/asciinema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorder.go
66 lines (50 loc) · 1.36 KB
/
recorder.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
65
66
package asciicast
import (
"github.com/asciinema/asciinema/terminal"
"github.com/asciinema/asciinema/util"
)
type Recorder interface {
Record(string, string, string, uint, bool, map[string]string) error
}
type AsciicastRecorder struct {
Terminal terminal.Terminal
}
func NewRecorder() Recorder {
return &AsciicastRecorder{Terminal: terminal.NewTerminal()}
}
func (r *AsciicastRecorder) Record(path, command, title string, maxWait uint, assumeYes bool, env map[string]string) error {
// TODO: touch savePath to ensure writing is possible
rows, cols, _ := r.Terminal.Size()
if rows > 30 || cols > 120 {
util.Warningf("Current terminal size is %vx%v.", cols, rows)
util.Warningf("It may be too big to be properly replayed on smaller screens.")
if !assumeYes {
util.Warningf("You can now resize it. Press <Enter> to start recording.")
util.ReadLine()
}
}
util.Printf("Asciicast recording started.")
util.Printf(`Hit Ctrl-D or type "exit" to finish.`)
stdout := NewStream(maxWait)
err := r.Terminal.Record(command, stdout)
if err != nil {
return err
}
stdout.Close()
util.Printf("Asciicast recording finished.")
rows, cols, _ = r.Terminal.Size()
asciicast := NewAsciicast(
cols,
rows,
stdout.Duration().Seconds(),
command,
title,
stdout.Frames,
env,
)
err = Save(asciicast, path)
if err != nil {
return err
}
return nil
}