Skip to content

Commit

Permalink
fix: don't use go-rod slow motion
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Oct 30, 2022
1 parent d6032ad commit e369116
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 25 deletions.
15 changes: 6 additions & 9 deletions command.go
Expand Up @@ -109,17 +109,17 @@ func ExecuteNoop(c Command, v *VHS) {}
func ExecuteKey(k input.Key) CommandFunc {
return func(c Command, v *VHS) {
typingSpeed, err := time.ParseDuration(c.Options)
if err == nil {
v.browser.SlowMotion(typingSpeed)
if err != nil {
typingSpeed = v.Options.TypingSpeed
}
repeat, err := strconv.Atoi(c.Args)
if err != nil {
repeat = 1
}
for i := 0; i < repeat; i++ {
_ = v.Page.Keyboard.Type(k)
time.Sleep(typingSpeed)
}
v.browser.SlowMotion(v.Options.TypingSpeed)
}
}

Expand All @@ -137,7 +137,6 @@ func ExecuteCtrl(c Command, v *VHS) {

// ExecuteHide is a CommandFunc that starts or stops the recording of the vhs.
func ExecuteHide(c Command, v *VHS) {
v.browser.SlowMotion(0)
v.PauseRecording()
}

Expand All @@ -152,7 +151,6 @@ func ExecuteRequire(c Command, v *VHS) {

// ExecuteShow is a CommandFunc that resumes the recording of the vhs.
func ExecuteShow(c Command, v *VHS) {
v.browser.SlowMotion(v.Options.TypingSpeed)
v.ResumeRecording()
}

Expand All @@ -169,8 +167,8 @@ func ExecuteSleep(c Command, v *VHS) {
// ExecuteType types the argument string on the running instance of vhs.
func ExecuteType(c Command, v *VHS) {
typingSpeed, err := time.ParseDuration(c.Options)
if err == nil {
v.browser.SlowMotion(typingSpeed)
if err != nil {
typingSpeed = v.Options.TypingSpeed
}
for _, r := range c.Args {
k, ok := keymap[r]
Expand All @@ -180,8 +178,8 @@ func ExecuteType(c Command, v *VHS) {
_ = v.Page.MustElement("textarea").Input(string(r))
v.Page.MustWaitIdle()
}
time.Sleep(typingSpeed)
}
v.browser.SlowMotion(v.Options.TypingSpeed)
}

// ExecuteOutput applies the output on the vhs videos.
Expand Down Expand Up @@ -288,7 +286,6 @@ func ExecuteSetTypingSpeed(c Command, v *VHS) {
return
}
v.Options.TypingSpeed = typingSpeed
v.browser.SlowMotion(typingSpeed)
}

// ExecuteSetPadding applies the padding on the vhs.
Expand Down
8 changes: 1 addition & 7 deletions evaluator.go
Expand Up @@ -89,12 +89,6 @@ func Evaluate(tape string, out io.Writer, opts ...EvaluatorOption) error {
}()

for _, cmd := range cmds[offset:] {

// Require commands are already run at this stage
if cmd.Type == REQUIRE {
continue
}

// When changing the FontFamily, FontSize, LineHeight, Padding
// The xterm.js canvas changes dimensions and causes FFMPEG to not work
// correctly (specifically) with palettegen.
Expand All @@ -104,7 +98,7 @@ func Evaluate(tape string, out io.Writer, opts ...EvaluatorOption) error {
//
// We should remove if isSetting statement.
isSetting := cmd.Type == SET && cmd.Options != "TypingSpeed"
if isSetting {
if isSetting || cmd.Type == REQUIRE {
fmt.Fprintln(out, cmd.Highlight(true))
continue
}
Expand Down
4 changes: 2 additions & 2 deletions examples/demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/neofetch/neofetch.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/neofetch/neofetch.mp4
Git LFS file not shown
4 changes: 2 additions & 2 deletions examples/neofetch/neofetch.webm
Git LFS file not shown
3 changes: 3 additions & 0 deletions examples/welcome.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vhs.go
Expand Up @@ -69,7 +69,7 @@ func New() VHS {
opts := DefaultVHSOptions()
path, _ := launcher.LookPath()
u := launcher.New().Leakless(false).Bin(path).MustLaunch()
browser := rod.New().ControlURL(u).MustConnect().SlowMotion(opts.TypingSpeed)
browser := rod.New().ControlURL(u).MustConnect()
page := browser.MustPage(fmt.Sprintf("http://localhost:%d", port))

mu := &sync.Mutex{}
Expand Down

0 comments on commit e369116

Please sign in to comment.