Class: TTY::Command::Window::PlainStep

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/command/window/step.rb

Overview

Fallback step for environments without windowed rendering: the same interface as Step, rendered as plain scrolling text. Commands stream their full output between a start marker and a ✔/✖ summary line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, output:) ⇒ PlainStep

Returns a new instance of PlainStep.



225
226
227
228
229
230
231
232
233
# File 'lib/tty/command/window/step.rb', line 225

def initialize(title:, output:)
  @title = title.to_s
  @output = output
  @active = true
  @at_line_start = true
  @started_at = Block.clock
  @pastel = Pastel.new(enabled: color?)
  @output.puts("#{@pastel.dim('──')} #{@title}")
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



223
224
225
# File 'lib/tty/command/window/step.rb', line 223

def output
  @output
end

Instance Method Details

#active?Boolean

Returns false once #finish has run.

Returns:

  • (Boolean)

    false once #finish has run



236
237
238
# File 'lib/tty/command/window/step.rb', line 236

def active?
  @active
end

#finish(success: true) ⇒ self

Print the ✔/✖ summary line.

Parameters:

  • success (Boolean) (defaults to: true)

Returns:

  • (self)


270
271
272
273
274
275
276
277
278
279
# File 'lib/tty/command/window/step.rb', line 270

def finish(success: true)
  return self unless @active

  @active = false
  @output.write("\n") unless @at_line_start
  glyph = success ? @pastel.green(Block::SUCCESS_GLYPH) : @pastel.red(Block::FAILURE_GLYPH)
  elapsed = Window.format_elapsed(Block.clock - @started_at)
  @output.puts("#{glyph} #{@title} #{@pastel.dim("#{elapsed}")}")
  self
end

#log(text) ⇒ self

Parameters:

  • text (String)

Returns:

  • (self)


242
243
244
245
246
247
# File 'lib/tty/command/window/step.rb', line 242

def log(text)
  @output.write("\n") unless @at_line_start
  @at_line_start = true
  @output.puts(text)
  self
end

#retitle(title) ⇒ self

Parameters:

  • title (String)

Returns:

  • (self)


251
252
253
254
# File 'lib/tty/command/window/step.rb', line 251

def retitle(title)
  @title = title.to_s
  self
end

#run(cmd, *args) ⇒ TTY::Command::Result

Run a command inside this step's window; raises TTY::Command::ExitError on failure like #run.

Sugar for cmd.run_windowed(*args, window: self).

Parameters:

Returns:

  • (TTY::Command::Result)


257
258
259
# File 'lib/tty/command/window/step.rb', line 257

def run(cmd, *args, &)
  cmd.run_windowed(*args_with_window(args), &)
end

#run!(cmd, *args) ⇒ TTY::Command::Result

Same as #run but never raises on non-zero exit.

Returns:

  • (TTY::Command::Result)


262
263
264
# File 'lib/tty/command/window/step.rb', line 262

def run!(cmd, *args, &)
  cmd.run_windowed!(*args_with_window(args), &)
end

#write_output(chunk) ⇒ Object



282
283
284
285
# File 'lib/tty/command/window/step.rb', line 282

def write_output(chunk)
  @at_line_start = chunk.end_with?("\n") unless chunk.empty?
  @output.write(chunk)
end