0003-implement-animation-stepping.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From b2c3e20920c2595f800eb1cb1bd28b0ad03377e2 Mon Sep 17 00:00:00 2001
  2. From: bill-auger <mr.j.spam.me@gmail.com>
  3. Date: Tue, 21 Mar 2023 13:56:40 -0400
  4. Subject: [PATCH 3/5] implement animation stepping
  5. ---
  6. cowsay | 47 +++++++++++++++++++++++++++++++++++++++--------
  7. 1 file changed, 39 insertions(+), 8 deletions(-)
  8. diff --git a/cowsay b/cowsay
  9. index dc49542..aa356df 100755
  10. --- a/cowsay
  11. +++ b/cowsay
  12. @@ -45,7 +45,7 @@ if (($^O eq "MSWin32") or ($^O eq "Windows_NT")) { ## Many perls, eek!
  13. 'W' => 40,
  14. );
  15. -getopts('bde:f:ghlLnNpstT:wW:y', \%opts);
  16. +getopts('abde:f:ghlLnNpstT:wW:y', \%opts);
  17. &display_usage if $opts{'h'};
  18. &list_cowfiles if $opts{'l'};
  19. @@ -76,18 +76,49 @@ else {
  20. my $anim_duration = 3000000;
  21. my $n_anim_files = @anim_files;
  22. my $sleep_ivl = $anim_duration / $n_anim_files;
  23. - my $clear_string = `clear`;
  24. + $clear_string = `clear`;
  25. + $frame_n = 0;
  26. + $key = '';
  27. - for my $full (@anim_files) {
  28. - do $full;
  29. - die "$progname: $@\n" if $@;
  30. + # step through animation
  31. + if ($opts{'a'}) {
  32. + use Term::ReadKey;
  33. - print $clear_string;
  34. - &print_cow;
  35. - usleep($sleep_ivl);
  36. + while (not $key =~ /q/) {
  37. + if ($key =~ /,/ and $frame_n > 0 ) { --$frame_n; }
  38. + elsif ($key =~ /\./ and $frame_n < $n_anim_files - 1) { ++$frame_n; }
  39. + $full = $anim_files[$frame_n];
  40. + &print_frame;
  41. + &read_key;
  42. + }
  43. + # play complete animation
  44. + } else {
  45. + for $full (@anim_files) {
  46. + &print_frame;
  47. + usleep($sleep_ivl);
  48. + }
  49. }
  50. }
  51. +sub read_key {
  52. + $key = '';
  53. +
  54. + while (not $key =~ /,|\.|q/) {
  55. + ReadMode('cbreak');
  56. + $key = ReadKey(0);
  57. + ReadMode('normal');
  58. + }
  59. +}
  60. +
  61. +sub print_frame {
  62. + do $full;
  63. + die "$progname: $@\n" if $@;
  64. +
  65. + print $clear_string;
  66. + &print_cow;
  67. + if ($opts{'a'}) { print "frame[$frame_n]: $full\n"; }
  68. +}
  69. +
  70. sub print_cow {
  71. print @balloon_lines;
  72. print $the_cow;
  73. --
  74. 2.40.0