Class: Tucue::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/tucue/ui.rb

Overview

curses-based TUI handling the key-input loop and screen drawing.

Rather than spawning a separate poll thread (curses is not thread-safe), the main loop uses a getch timeout so the screen refreshes periodically while still reacting to key presses promptly.

Constant Summary collapse

SEEK_SMALL =
5
SEEK_LARGE =
15
REFRESH_MS =

getch timeout in ms; also the screen refresh interval.

200
PROGRESS_WIDTH =
24

Instance Method Summary collapse

Constructor Details

#initialize(player, marker) ⇒ UI

Returns a new instance of UI.



20
21
22
23
24
25
# File 'lib/tucue/ui.rb', line 20

def initialize(player, marker)
  @player = player
  @marker = marker
  @status = ""
  @running = true
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tucue/ui.rb', line 27

def run
  @player.start
  @status = "Playing #{File.basename(@player.file)}"
  with_curses do
    loop do
      begin
        draw
        handle_key(@window.getch)
      rescue Tucue::Error => e
        # The player connection dropped (e.g. mpv reached end of file
        # or exited); report it and leave the loop cleanly.
        @status = "Playback ended: #{e.message}"
        @running = false
      end
      break unless @running
    end
  end
ensure
  @player.stop
end