mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 03:38:03 +01:00
asciicast struct construction should better be handled in asciicast package
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user