Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"os"
"time"

"github.com/charmbracelet/vhs/lexer"
"github.com/charmbracelet/vhs/parser"
Expand Down Expand Up @@ -137,6 +138,8 @@ func Evaluate(ctx context.Context, tape string, out io.Writer, opts ...Evaluator
}
}()

start := time.Now()

for _, cmd := range cmds[offset:] {
if ctx.Err() != nil {
teardown()
Expand All @@ -160,6 +163,16 @@ func Evaluate(ctx context.Context, tape string, out io.Writer, opts ...Evaluator
_, _ = fmt.Fprintln(out, Highlight(cmd, true))
continue
}

if withTimestampFlag {
elapsed := time.Since(start)
hours := int(elapsed.Hours())
minutes := int(elapsed.Minutes()) % 60
seconds := int(elapsed.Seconds()) % 60
stopwatch := fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
fmt.Print(stopwatch, " : ")
}

_, _ = fmt.Fprintln(out, Highlight(cmd, !v.recording || cmd.Type == token.SHOW || cmd.Type == token.HIDE || isSetting))
err := Execute(cmd, &v)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var (
publishFlag bool
outputs *[]string

withTimestampFlag bool

quietFlag bool

//nolint:wrapcheck
Expand Down Expand Up @@ -255,6 +257,7 @@ func main() {

func init() {
rootCmd.Flags().BoolVarP(&publishFlag, "publish", "p", false, "publish your GIF to vhs.charm.sh and get a shareable URL")
rootCmd.Flags().BoolVarP(&withTimestampFlag, "with-timestamp", "t", false, "Get timestamp for each command in the output")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is ok to leave as timestamp instead of with-timestamp

rootCmd.PersistentFlags().BoolVarP(&quietFlag, "quiet", "q", false, "quiet do not log messages. If publish flag is provided, it will log shareable URL")

outputs = rootCmd.Flags().StringSliceP("output", "o", []string{}, "file name(s) of video output")
Expand Down