Skip to content

Commit

Permalink
Merge pull request #1 from sharetribe/user-deletion-gif
Browse files Browse the repository at this point in the history
User deletion gif
  • Loading branch information
wontheone1 authored May 4, 2022
2 parents 52aa7a9 + f1791b6 commit 0d98adf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ There's no CLI implemented. You should open a Clojure REPL and call functions fr
6. Copy the recording to `./gifs/...` from the temporary location
```
mv /var/folders/0p/vtdv4p053pd6gkx8d5p98h000000gn/T/tmpoig8qzvd-ascii.cast ./gits/my-gif/original.cast
mv /var/folders/0p/vtdv4p053pd6gkx8d5p98h000000gn/T/tmpoig8qzvd-ascii.cast ./gifs/my-gif/original.cast
```
7. In your Clojure editor, open the asciiscripts `core` namespace `asciiscripts/src/core.clj`
8. Connect to REPL
9. In the `(comment ,,,)` block, add a new section for you GIF, something like:
9. In the `(comment ,,,)` block, add a new section for your GIF, something like:
```clj
(-> (read-cast "./gifs/my-gif/original.cast")
Expand Down Expand Up @@ -64,7 +64,7 @@ There's no CLI implemented. You should open a Clojure REPL and call functions fr
`:quantize`, otherwise quantize will override them)
* Resize (`:resize` op) the recording to certain width and height
11. When you're done editing, use [asciicast2git](https://github.com/asciinema/asciicast2gif) to convert `.cast` file to `.git`
11. When you're done editing, use [asciicast2git](https://github.com/asciinema/asciicast2gif) to convert `.cast` file to `.gif` file
Example:
Expand Down
35 changes: 35 additions & 0 deletions src/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@
e))
evts))))

(defmethod apply-op :pause-matching [data [_ {:keys [d match]}]]
;; Add pause
(update data :events
(fn [evts]
(map (fn [e] (if (re-find match (:data e))
(update e :d #(+ % d))
e))
evts))))

(defmethod apply-op :split [data [_ {:keys [start end d]}]]
(let [r 10M] ;; Adds some randomness to the splitted value, looks more realistic typing.
(update data :events
Expand Down Expand Up @@ -224,6 +233,11 @@
(defn apply-ops [data ops]
(reduce apply-op data ops))

(defn return-ids-of-matching [{:keys [events]} match]
(->> events
(filter #(re-find match (:data %)))
(map #(first (:id %)))))

(comment
;; Example.

Expand Down Expand Up @@ -307,5 +321,26 @@
#_(pp)
)

; Find IDs of where line breaks exist
(-> (read-cast "./gifs/user-deletion/pre.cast")
(return-ids-of-matching #"\r\r\n")
)
; => (4 70 118 171 216 261 310 323 328 389 415 465 469 509 564 584 624 656 695 711 729 734 769 816 820 832 837)

; Delete user gif
(-> (read-cast "./gifs/user-deletion/pre.cast")
(apply-ops [
[:resize {:width 80 :height 35}]
[:cut-start {:end [329]}]
[:str-replace {:match #"undefined" :replacement ""}]
[:quantize {:min 0.04M :max 0.5M}]
[:pause {:id [469] :d 1.5M}]
[:pause {:id [734] :d 1.5M}]
[:pause {:id [820] :d 1.5M}]
[:cut-end {:start [821]}]
])
(write-cast "./gifs/user-deletion/post.cast")
(pp)
)

)

0 comments on commit 0d98adf

Please sign in to comment.