Class: AsciinemaWin::Player
- Inherits:
-
Object
- Object
- AsciinemaWin::Player
- Defined in:
- lib/asciinema_win/player.rb
Overview
Terminal session player for Windows
Plays back asciicast v2 recordings with accurate timing, using Rich-Ruby for terminal output rendering. Supports speed control, idle time limiting, and interactive controls.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#idle_time_limit ⇒ Float?
readonly
Maximum idle time between frames.
-
#max_idle_time ⇒ Float?
readonly
Alternative max idle time setting.
-
#pause_on_markers ⇒ Boolean
readonly
Whether to pause at markers.
-
#position ⇒ Float
readonly
Current playback position in seconds.
-
#speed ⇒ Float
readonly
Playback speed multiplier.
-
#state ⇒ Symbol
readonly
Current playback state (:idle, :playing, :paused, :stopped).
Instance Method Summary collapse
-
#info(input_path) ⇒ Hash
Get recording info without playing.
-
#initialize(speed: 1.0, idle_time_limit: nil, max_idle_time: nil, pause_on_markers: false) ⇒ Player
constructor
Create a new player.
-
#pause ⇒ void
Pause playback.
-
#play(input_path) ⇒ void
Play a recording from a file.
-
#play_stream(io) ⇒ void
Play from an IO stream.
-
#resume ⇒ void
Resume playback after pause.
-
#set_speed(multiplier) ⇒ void
Set playback speed.
-
#stop ⇒ void
Stop playback.
Constructor Details
#initialize(speed: 1.0, idle_time_limit: nil, max_idle_time: nil, pause_on_markers: false) ⇒ Player
Create a new player
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/asciinema_win/player.rb', line 46 def initialize( speed: 1.0, idle_time_limit: nil, max_idle_time: nil, pause_on_markers: false ) @speed = speed.to_f @speed = 1.0 if @speed <= 0 @idle_time_limit = idle_time_limit&.to_f @max_idle_time = max_idle_time&.to_f @pause_on_markers = pause_on_markers @state = :idle @position = 0.0 @reader = nil @header = nil end |
Instance Attribute Details
#idle_time_limit ⇒ Float? (readonly)
Returns Maximum idle time between frames.
26 27 28 |
# File 'lib/asciinema_win/player.rb', line 26 def idle_time_limit @idle_time_limit end |
#max_idle_time ⇒ Float? (readonly)
Returns Alternative max idle time setting.
29 30 31 |
# File 'lib/asciinema_win/player.rb', line 29 def max_idle_time @max_idle_time end |
#pause_on_markers ⇒ Boolean (readonly)
Returns Whether to pause at markers.
32 33 34 |
# File 'lib/asciinema_win/player.rb', line 32 def pause_on_markers @pause_on_markers end |
#position ⇒ Float (readonly)
Returns Current playback position in seconds.
38 39 40 |
# File 'lib/asciinema_win/player.rb', line 38 def position @position end |
#speed ⇒ Float (readonly)
Returns Playback speed multiplier.
23 24 25 |
# File 'lib/asciinema_win/player.rb', line 23 def speed @speed end |
#state ⇒ Symbol (readonly)
Returns Current playback state (:idle, :playing, :paused, :stopped).
35 36 37 |
# File 'lib/asciinema_win/player.rb', line 35 def state @state end |
Instance Method Details
#info(input_path) ⇒ Hash
Get recording info without playing
148 149 150 |
# File 'lib/asciinema_win/player.rb', line 148 def info(input_path) Asciicast::Reader.info(input_path) end |
#pause ⇒ void
This method returns an undefined value.
Pause playback
114 115 116 117 118 |
# File 'lib/asciinema_win/player.rb', line 114 def pause return unless @state == :playing @state = :paused end |
#play(input_path) ⇒ void
This method returns an undefined value.
Play a recording from a file
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/asciinema_win/player.rb', line 71 def play(input_path) raise PlaybackError, "Already playing" if @state == :playing File.open(input_path, "r", encoding: "UTF-8") do |file| @reader = Asciicast::Reader.new(file) @header = @reader.header @state = :playing @position = 0.0 begin setup_terminal play_events ensure restore_terminal @state = :stopped end end end |
#play_stream(io) ⇒ void
This method returns an undefined value.
Play from an IO stream
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/asciinema_win/player.rb', line 94 def play_stream(io) raise PlaybackError, "Already playing" if @state == :playing @reader = Asciicast::Reader.new(io) @header = @reader.header @state = :playing @position = 0.0 begin setup_terminal play_events ensure restore_terminal @state = :stopped end end |
#resume ⇒ void
This method returns an undefined value.
Resume playback after pause
123 124 125 126 127 |
# File 'lib/asciinema_win/player.rb', line 123 def resume return unless @state == :paused @state = :playing end |
#set_speed(multiplier) ⇒ void
This method returns an undefined value.
Set playback speed
140 141 142 |
# File 'lib/asciinema_win/player.rb', line 140 def set_speed(multiplier) @speed = [multiplier.to_f, 0.1].max end |
#stop ⇒ void
This method returns an undefined value.
Stop playback
132 133 134 |
# File 'lib/asciinema_win/player.rb', line 132 def stop @state = :stopped end |