FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:35:07 2017 +0000
Revision:
0:a2cb7295a1f7
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a2cb7295a1f7 1 # ==========================================
ram54288 0:a2cb7295a1f7 2 # Unity Project - A Test Framework for C
ram54288 0:a2cb7295a1f7 3 # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
ram54288 0:a2cb7295a1f7 4 # [Released under MIT License. Please refer to license.txt for details]
ram54288 0:a2cb7295a1f7 5 # ==========================================
ram54288 0:a2cb7295a1f7 6
ram54288 0:a2cb7295a1f7 7 if RUBY_PLATFORM =~/(win|w)32$/
ram54288 0:a2cb7295a1f7 8 begin
ram54288 0:a2cb7295a1f7 9 require 'Win32API'
ram54288 0:a2cb7295a1f7 10 rescue LoadError
ram54288 0:a2cb7295a1f7 11 puts "ERROR! \"Win32API\" library not found"
ram54288 0:a2cb7295a1f7 12 puts "\"Win32API\" is required for colour on a windows machine"
ram54288 0:a2cb7295a1f7 13 puts " try => \"gem install Win32API\" on the command line"
ram54288 0:a2cb7295a1f7 14 puts
ram54288 0:a2cb7295a1f7 15 end
ram54288 0:a2cb7295a1f7 16 # puts
ram54288 0:a2cb7295a1f7 17 # puts 'Windows Environment Detected...'
ram54288 0:a2cb7295a1f7 18 # puts 'Win32API Library Found.'
ram54288 0:a2cb7295a1f7 19 # puts
ram54288 0:a2cb7295a1f7 20 end
ram54288 0:a2cb7295a1f7 21
ram54288 0:a2cb7295a1f7 22 class ColourCommandLine
ram54288 0:a2cb7295a1f7 23 def initialize
ram54288 0:a2cb7295a1f7 24 if RUBY_PLATFORM =~/(win|w)32$/
ram54288 0:a2cb7295a1f7 25 get_std_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
ram54288 0:a2cb7295a1f7 26 @set_console_txt_attrb =
ram54288 0:a2cb7295a1f7 27 Win32API.new("kernel32","SetConsoleTextAttribute",['L','N'], 'I')
ram54288 0:a2cb7295a1f7 28 @hout = get_std_handle.call(-11)
ram54288 0:a2cb7295a1f7 29 end
ram54288 0:a2cb7295a1f7 30 end
ram54288 0:a2cb7295a1f7 31
ram54288 0:a2cb7295a1f7 32 def change_to(new_colour)
ram54288 0:a2cb7295a1f7 33 if RUBY_PLATFORM =~/(win|w)32$/
ram54288 0:a2cb7295a1f7 34 @set_console_txt_attrb.call(@hout,self.win32_colour(new_colour))
ram54288 0:a2cb7295a1f7 35 else
ram54288 0:a2cb7295a1f7 36 "\033[30;#{posix_colour(new_colour)};22m"
ram54288 0:a2cb7295a1f7 37 end
ram54288 0:a2cb7295a1f7 38 end
ram54288 0:a2cb7295a1f7 39
ram54288 0:a2cb7295a1f7 40 def win32_colour(colour)
ram54288 0:a2cb7295a1f7 41 case colour
ram54288 0:a2cb7295a1f7 42 when :black then 0
ram54288 0:a2cb7295a1f7 43 when :dark_blue then 1
ram54288 0:a2cb7295a1f7 44 when :dark_green then 2
ram54288 0:a2cb7295a1f7 45 when :dark_cyan then 3
ram54288 0:a2cb7295a1f7 46 when :dark_red then 4
ram54288 0:a2cb7295a1f7 47 when :dark_purple then 5
ram54288 0:a2cb7295a1f7 48 when :dark_yellow, :narrative then 6
ram54288 0:a2cb7295a1f7 49 when :default_white, :default, :dark_white then 7
ram54288 0:a2cb7295a1f7 50 when :silver then 8
ram54288 0:a2cb7295a1f7 51 when :blue then 9
ram54288 0:a2cb7295a1f7 52 when :green, :success then 10
ram54288 0:a2cb7295a1f7 53 when :cyan, :output then 11
ram54288 0:a2cb7295a1f7 54 when :red, :failure then 12
ram54288 0:a2cb7295a1f7 55 when :purple then 13
ram54288 0:a2cb7295a1f7 56 when :yellow then 14
ram54288 0:a2cb7295a1f7 57 when :white then 15
ram54288 0:a2cb7295a1f7 58 else
ram54288 0:a2cb7295a1f7 59 0
ram54288 0:a2cb7295a1f7 60 end
ram54288 0:a2cb7295a1f7 61 end
ram54288 0:a2cb7295a1f7 62
ram54288 0:a2cb7295a1f7 63 def posix_colour(colour)
ram54288 0:a2cb7295a1f7 64 # ANSI Escape Codes - Foreground colors
ram54288 0:a2cb7295a1f7 65 # | Code | Color |
ram54288 0:a2cb7295a1f7 66 # | 39 | Default foreground color |
ram54288 0:a2cb7295a1f7 67 # | 30 | Black |
ram54288 0:a2cb7295a1f7 68 # | 31 | Red |
ram54288 0:a2cb7295a1f7 69 # | 32 | Green |
ram54288 0:a2cb7295a1f7 70 # | 33 | Yellow |
ram54288 0:a2cb7295a1f7 71 # | 34 | Blue |
ram54288 0:a2cb7295a1f7 72 # | 35 | Magenta |
ram54288 0:a2cb7295a1f7 73 # | 36 | Cyan |
ram54288 0:a2cb7295a1f7 74 # | 37 | Light gray |
ram54288 0:a2cb7295a1f7 75 # | 90 | Dark gray |
ram54288 0:a2cb7295a1f7 76 # | 91 | Light red |
ram54288 0:a2cb7295a1f7 77 # | 92 | Light green |
ram54288 0:a2cb7295a1f7 78 # | 93 | Light yellow |
ram54288 0:a2cb7295a1f7 79 # | 94 | Light blue |
ram54288 0:a2cb7295a1f7 80 # | 95 | Light magenta |
ram54288 0:a2cb7295a1f7 81 # | 96 | Light cyan |
ram54288 0:a2cb7295a1f7 82 # | 97 | White |
ram54288 0:a2cb7295a1f7 83
ram54288 0:a2cb7295a1f7 84 case colour
ram54288 0:a2cb7295a1f7 85 when :black then 30
ram54288 0:a2cb7295a1f7 86 when :red, :failure then 31
ram54288 0:a2cb7295a1f7 87 when :green, :success then 32
ram54288 0:a2cb7295a1f7 88 when :yellow then 33
ram54288 0:a2cb7295a1f7 89 when :blue, :narrative then 34
ram54288 0:a2cb7295a1f7 90 when :purple, :magenta then 35
ram54288 0:a2cb7295a1f7 91 when :cyan, :output then 36
ram54288 0:a2cb7295a1f7 92 when :white, :default_white then 37
ram54288 0:a2cb7295a1f7 93 when :default then 39
ram54288 0:a2cb7295a1f7 94 else
ram54288 0:a2cb7295a1f7 95 39
ram54288 0:a2cb7295a1f7 96 end
ram54288 0:a2cb7295a1f7 97 end
ram54288 0:a2cb7295a1f7 98
ram54288 0:a2cb7295a1f7 99 def out_c(mode, colour, str)
ram54288 0:a2cb7295a1f7 100 case RUBY_PLATFORM
ram54288 0:a2cb7295a1f7 101 when /(win|w)32$/
ram54288 0:a2cb7295a1f7 102 change_to(colour)
ram54288 0:a2cb7295a1f7 103 $stdout.puts str if mode == :puts
ram54288 0:a2cb7295a1f7 104 $stdout.print str if mode == :print
ram54288 0:a2cb7295a1f7 105 change_to(:default_white)
ram54288 0:a2cb7295a1f7 106 else
ram54288 0:a2cb7295a1f7 107 $stdout.puts("#{change_to(colour)}#{str}\033[0m") if mode == :puts
ram54288 0:a2cb7295a1f7 108 $stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print
ram54288 0:a2cb7295a1f7 109 end
ram54288 0:a2cb7295a1f7 110 end
ram54288 0:a2cb7295a1f7 111 end # ColourCommandLine
ram54288 0:a2cb7295a1f7 112
ram54288 0:a2cb7295a1f7 113 def colour_puts(role,str) ColourCommandLine.new.out_c(:puts, role, str) end
ram54288 0:a2cb7295a1f7 114 def colour_print(role,str) ColourCommandLine.new.out_c(:print, role, str) end
ram54288 0:a2cb7295a1f7 115