class Puppet::Util::Colors::WideConsole

The win32console gem uses ANSI functions for writing to the console which doesn’t work for unicode strings, e.g. module tool. Ruby 1.9 does the same thing, but doesn’t account for ANSI escape sequences

Public Instance Methods

Write(str) click to toggle source
# File lib/puppet/util/colors.rb, line 149
def Write(str)
  result = false
  FFI::MemoryPointer.from_string_to_wide_string(str) do |msg_ptr|
    FFI::MemoryPointer.new(:dword, 1) do |numberOfCharsWritten_ptr|
      result = WriteConsoleW(@handle, msg_ptr,
        str.length, FFI::MemoryPointer.new(:dword, 1),
        FFI::MemoryPointer::NULL) != FFI::WIN32_FALSE
    end
  end

  result
end
WriteChar(str, col, row) click to toggle source
# File lib/puppet/util/colors.rb, line 132
def WriteChar(str, col, row)
  writeCoord = COORD.new()
  writeCoord[:X] = row
  writeCoord[:Y] = col

  chars_written = 0
  FFI::MemoryPointer.from_string_to_wide_string(str) do |msg_ptr|
    FFI::MemoryPointer.new(:dword, 1) do |numberOfCharsWritten_ptr|
      WriteConsoleOutputCharacterW(@handle, msg_ptr,
        str.length, writeCoord, numberOfCharsWritten_ptr)
      chars_written = numberOfCharsWritten_ptr.read_dword
    end
  end

  chars_written
end

Public Class Methods

new(t = nil) click to toggle source
# File lib/puppet/util/colors.rb, line 128
def initialize(t = nil)
  super(t)
end