Class: Pvectl::Commands::Get::WatchLoop
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::WatchLoop
- Defined in:
- lib/pvectl/commands/get/watch_loop.rb
Overview
Handles continuous watch mode for the get command.
Repeatedly executes a block at specified intervals, clearing the screen between iterations when running in a TTY. Handles SIGINT for graceful termination.
Constant Summary collapse
- DEFAULT_INTERVAL =
Default refresh interval in seconds.
2- MIN_INTERVAL =
Minimum allowed refresh interval in seconds.
1
Instance Attribute Summary collapse
-
#interval ⇒ Integer
readonly
The effective refresh interval.
Instance Method Summary collapse
-
#initialize(interval: DEFAULT_INTERVAL, output: $stdout) ⇒ WatchLoop
constructor
Creates a new WatchLoop.
-
#run { ... } ⇒ void
Runs the watch loop, executing the block repeatedly.
-
#running? ⇒ Boolean
Checks if the loop is currently running.
-
#stop ⇒ void
Stops the watch loop.
Constructor Details
#initialize(interval: DEFAULT_INTERVAL, output: $stdout) ⇒ WatchLoop
Creates a new WatchLoop.
34 35 36 37 38 |
# File 'lib/pvectl/commands/get/watch_loop.rb', line 34 def initialize(interval: DEFAULT_INTERVAL, output: $stdout) @interval = [interval.to_i, MIN_INTERVAL].max @output = output @running = false end |
Instance Attribute Details
#interval ⇒ Integer (readonly)
Returns the effective refresh interval.
27 28 29 |
# File 'lib/pvectl/commands/get/watch_loop.rb', line 27 def interval @interval end |
Instance Method Details
#run { ... } ⇒ void
This method returns an undefined value.
Runs the watch loop, executing the block repeatedly.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pvectl/commands/get/watch_loop.rb', line 50 def run @running = true setup_signal_handler while @running clear_screen if tty? print_header if tty? yield sleep_interruptible(@interval) end end |
#running? ⇒ Boolean
Checks if the loop is currently running.
72 73 74 |
# File 'lib/pvectl/commands/get/watch_loop.rb', line 72 def running? @running end |
#stop ⇒ void
This method returns an undefined value.
Stops the watch loop.
65 66 67 |
# File 'lib/pvectl/commands/get/watch_loop.rb', line 65 def stop @running = false end |