Example #1
0
func (c *RecordCommand) Execute(command, title string, assumeYes bool, maxWait float64, filename string) error {
	var upload bool
	var err error

	if filename != "" {
		upload = false
	} else {
		filename, err = tmpPath()
		if err != nil {
			return err
		}
		upload = true
	}

	err = c.Recorder.Record(filename, command, title, maxWait, assumeYes, c.Env)
	if err != nil {
		return err
	}

	if upload {
		if !assumeYes {
			util.Printf("Press <Enter> to upload, <Ctrl-C> to cancel.")
			util.ReadLine()
		}

		var url, warn string
		var err error

		util.WithSpinner(0, func() {
			url, warn, err = c.API.UploadAsciicast(filename)
		})

		if warn != "" {
			util.Warningf(warn)
		}

		if err != nil {
			util.Warningf("Upload failed, asciicast saved at %v", filename)
			util.Warningf("Retry later by executing: asciinema upload %v", filename)
			return err
		}

		os.Remove(filename)
		fmt.Println(url)
	}

	return nil
}
Example #2
0
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
}
Example #3
0
func (c *UploadCommand) Execute(filename string) error {
	url, warn, err := c.API.UploadAsciicast(filename)

	if warn != "" {
		util.Warningf(warn)
	}

	if err != nil {
		return err
	}

	fmt.Println(url)

	return nil
}