Class: RubyWasm::StatusPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_wasm/build/executor.rb,
sig/ruby_wasm/build.rbs

Overview

Human readable status printer for the build.

Instance Method Summary collapse

Constructor Details

#initializeStatusPrinter

Returns a new instance of StatusPrinter.



162
163
164
165
166
# File 'lib/ruby_wasm/build/executor.rb', line 162

def initialize
  @mutex = Mutex.new
  @counter = 0
  @indicators = "|/-\\"
end

Instance Method Details

#donevoid

This method returns an undefined value.



197
198
199
# File 'lib/ruby_wasm/build/executor.rb', line 197

def done
  @mutex.synchronize { $stdout.print "\e[K" }
end

#stderr(message) ⇒ void

This method returns an undefined value.

Parameters:

  • message (String)


193
194
195
# File 'lib/ruby_wasm/build/executor.rb', line 193

def stderr(message)
  @mutex.synchronize { $stdout.print message }
end

#stdout(message) ⇒ void

This method returns an undefined value.

Parameters:

  • message (String)


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/ruby_wasm/build/executor.rb', line 168

def stdout(message)
  require "io/console"
  @mutex.synchronize do
    $stdout.print "\e[K"
    first_line = message.lines(chomp: true).first || ""

    # Make sure we don't line-wrap the output
    size =
      __skip__ =
        IO.respond_to?(:console_size) ? IO.console_size : IO.console.winsize
    terminal_width = size[1].to_i.nonzero? || 80
    width_limit = terminal_width / 2 - 3

    if first_line.length > width_limit
      first_line = (first_line[0..width_limit - 5] || "") + "..."
    end
    indicator = @indicators[@counter] || " "
    to_print = "  " + indicator + " " + first_line
    $stdout.print to_print
    $stdout.print "\e[1A\n"
    @counter += 1
    @counter = 0 if @counter >= @indicators.length
  end
end