mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 19:58: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"`
|
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 {
|
func Save(asciicast *Asciicast, path string) error {
|
||||||
bytes, err := json.MarshalIndent(asciicast, "", " ")
|
bytes, err := json.MarshalIndent(asciicast, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package asciicast
|
package asciicast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/asciinema/asciinema-cli/terminal"
|
"github.com/asciinema/asciinema-cli/terminal"
|
||||||
"github.com/asciinema/asciinema-cli/util"
|
"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()
|
rows, cols, _ = r.Terminal.Size()
|
||||||
|
|
||||||
asciicast := &Asciicast{
|
asciicast := NewAsciicast(
|
||||||
Version: 1,
|
cols,
|
||||||
Width: cols,
|
rows,
|
||||||
Height: rows,
|
stdout.Duration().Seconds(),
|
||||||
Duration: Duration(stdout.Duration().Seconds()),
|
command,
|
||||||
Command: command,
|
title,
|
||||||
Title: title,
|
stdout.Frames,
|
||||||
Env: &Env{Term: os.Getenv("TERM"), Shell: os.Getenv("SHELL")},
|
)
|
||||||
Stdout: stdout.Frames,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = Save(asciicast, path)
|
err = Save(asciicast, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user