asciicast struct construction should better be handled in asciicast package

This commit is contained in:
Marcin Kulik
2015-03-02 10:52:28 +01:00
parent 664b6fda6e
commit 0444b8545f
2 changed files with 21 additions and 12 deletions

View File

@@ -29,6 +29,19 @@ type Asciicast struct {
Stdout []Frame `json:"stdout"`
}
func NewAsciicast(width, height int, duration float64, command, title string, frames []Frame) *Asciicast {
return &Asciicast{
Version: 1,
Width: width,
Height: height,
Duration: Duration(duration),
Command: command,
Title: title,
Env: &Env{Term: os.Getenv("TERM"), Shell: os.Getenv("SHELL")},
Stdout: frames,
}
}
func Save(asciicast *Asciicast, path string) error {
bytes, err := json.MarshalIndent(asciicast, "", " ")
if err != nil {

View File

@@ -1,8 +1,6 @@
package asciicast
import (
"os"
"github.com/asciinema/asciinema-cli/terminal"
"github.com/asciinema/asciinema-cli/util"
)
@@ -46,16 +44,14 @@ func (r *AsciicastRecorder) Record(path, command, title string, maxWait uint) er
rows, cols, _ = r.Terminal.Size()
asciicast := &Asciicast{
Version: 1,
Width: cols,
Height: rows,
Duration: Duration(stdout.Duration().Seconds()),
Command: command,
Title: title,
Env: &Env{Term: os.Getenv("TERM"), Shell: os.Getenv("SHELL")},
Stdout: stdout.Frames,
}
asciicast := NewAsciicast(
cols,
rows,
stdout.Duration().Seconds(),
command,
title,
stdout.Frames,
)
err = Save(asciicast, path)
if err != nil {