Browse Source

Added NewHeaderEx

master v1.0.1
parent
commit
9ca8ae61a3
2 changed files with 20 additions and 6 deletions
  1. +1
    -0
      convert/ttyrec.go
  2. +19
    -6
      writer.go

+ 1
- 0
convert/ttyrec.go View File

@ -0,0 +1 @@
package convert

+ 19
- 6
writer.go View File

@ -18,13 +18,21 @@ type Encoder struct {
// NewEncoder can emit an asciicast v2 stream.
func NewEncoder(w io.Writer, width, height int) *Encoder {
return NewEncoderEx(w, Header{
Width: width,
Height: height,
})
}
// NewEncoderEx can emit an asciicast v2 stream.
func NewEncoderEx(w io.Writer, header Header) *Encoder {
header.Version = 2
if header.Timestamp == 0 {
header.Timestamp = time.Now().Unix()
}
return &Encoder{
Header: Header{
Version: Version,
Width: width,
Height: height,
},
w: w,
Header: header,
w: w,
}
}
@ -75,3 +83,8 @@ func (e *Encoder) WriteEvent(kind EventType, data string) error {
Data: data,
})
}
// WriteRawEvent writes a raw event.
func (e *Encoder) WriteRawEvent(event Event) error {
return e.writeJSON(&event)
}

Loading…
Cancel
Save