brakeman 4.5.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of brakeman might be problematic. Click here for more details.

Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +15 -0
  3. data/README.md +6 -6
  4. data/bundle/load.rb +3 -3
  5. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/AUTHORS +0 -0
  6. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/COPYING +0 -0
  7. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/Changelog.md +211 -15
  8. data/bundle/ruby/2.5.0/gems/highline-2.0.2/Gemfile +22 -0
  9. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/LICENSE +0 -0
  10. data/bundle/ruby/2.5.0/gems/highline-2.0.2/README.md +202 -0
  11. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/TODO +0 -0
  12. data/bundle/ruby/2.5.0/gems/highline-2.0.2/appveyor.yml +37 -0
  13. data/bundle/ruby/2.5.0/gems/highline-2.0.2/highline.gemspec +35 -0
  14. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline.rb +650 -0
  15. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/builtin_styles.rb +129 -0
  16. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/color_scheme.rb +49 -32
  17. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/compatibility.rb +23 -0
  18. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/custom_errors.rb +57 -0
  19. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/import.rb +48 -0
  20. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/io_console_compatible.rb +37 -0
  21. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/list.rb +177 -0
  22. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/list_renderer.rb +261 -0
  23. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/menu.rb +576 -0
  24. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/menu/item.rb +32 -0
  25. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/paginator.rb +52 -0
  26. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/question.rb +281 -131
  27. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/question/answer_converter.rb +103 -0
  28. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/question_asker.rb +150 -0
  29. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/simulate.rb +59 -0
  30. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/statement.rb +88 -0
  31. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/string.rb +36 -0
  32. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/string_extensions.rb +130 -0
  33. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/style.rb +325 -0
  34. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/template_renderer.rb +62 -0
  35. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal.rb +190 -0
  36. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/io_console.rb +36 -0
  37. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/ncurses.rb +38 -0
  38. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/unix_stty.rb +51 -0
  39. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/version.rb +3 -1
  40. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/wrapper.rb +53 -0
  41. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/History.rdoc +32 -0
  42. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/Manifest.txt +0 -0
  43. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/README.rdoc +0 -0
  44. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/compare/normalize.rb +0 -0
  45. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/debugging.md +0 -0
  46. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/rp_extensions.rb +1 -1
  47. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/rp_stringscanner.rb +0 -0
  48. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby20_parser.rb +2427 -2432
  49. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby20_parser.y +32 -29
  50. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby21_parser.rb +2101 -2109
  51. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby21_parser.y +32 -29
  52. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby22_parser.rb +2080 -2095
  53. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby22_parser.y +32 -29
  54. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0/lib/ruby25_parser.rb → ruby_parser-3.13.1/lib/ruby23_parser.rb} +2339 -2333
  55. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby23_parser.y +32 -29
  56. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby24_parser.rb +2347 -2335
  57. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby24_parser.y +32 -23
  58. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0/lib/ruby23_parser.rb → ruby_parser-3.13.1/lib/ruby25_parser.rb} +2349 -2337
  59. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby25_parser.y +32 -23
  60. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby26_parser.rb +2351 -2338
  61. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby26_parser.y +32 -23
  62. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rb +253 -161
  63. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rex +25 -25
  64. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rex.rb +68 -26
  65. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser.rb +3 -1
  66. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser.yy +34 -23
  67. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser_extras.rb +64 -43
  68. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/tools/munge.rb +2 -1
  69. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/tools/ripper.rb +6 -1
  70. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/CHANGELOG.md +4 -0
  71. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/MIT-LICENSE.txt +0 -0
  72. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/README.md +1 -1
  73. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/data/display_width.marshal.gz +0 -0
  74. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width.rb +0 -0
  75. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/constants.rb +2 -2
  76. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/index.rb +0 -0
  77. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/no_string_ext.rb +0 -0
  78. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/string_ext.rb +0 -0
  79. data/lib/brakeman.rb +7 -0
  80. data/lib/brakeman/app_tree.rb +34 -22
  81. data/lib/brakeman/checks.rb +7 -7
  82. data/lib/brakeman/checks/base_check.rb +9 -9
  83. data/lib/brakeman/checks/check_cross_site_scripting.rb +5 -0
  84. data/lib/brakeman/checks/check_default_routes.rb +5 -0
  85. data/lib/brakeman/checks/check_deserialize.rb +52 -0
  86. data/lib/brakeman/checks/check_dynamic_finders.rb +1 -1
  87. data/lib/brakeman/checks/check_force_ssl.rb +27 -0
  88. data/lib/brakeman/checks/check_json_parsing.rb +5 -0
  89. data/lib/brakeman/checks/check_link_to_href.rb +6 -1
  90. data/lib/brakeman/checks/check_mail_to.rb +1 -1
  91. data/lib/brakeman/checks/check_model_attr_accessible.rb +1 -1
  92. data/lib/brakeman/checks/check_model_attributes.rb +12 -50
  93. data/lib/brakeman/checks/check_model_serialize.rb +1 -1
  94. data/lib/brakeman/checks/check_nested_attributes_bypass.rb +3 -3
  95. data/lib/brakeman/checks/check_secrets.rb +1 -1
  96. data/lib/brakeman/checks/check_session_settings.rb +10 -10
  97. data/lib/brakeman/checks/check_simple_format.rb +5 -0
  98. data/lib/brakeman/checks/check_skip_before_filter.rb +1 -1
  99. data/lib/brakeman/checks/check_sql.rb +15 -17
  100. data/lib/brakeman/checks/check_validation_regex.rb +1 -1
  101. data/lib/brakeman/file_parser.rb +6 -8
  102. data/lib/brakeman/file_path.rb +71 -0
  103. data/lib/brakeman/options.rb +7 -0
  104. data/lib/brakeman/parsers/template_parser.rb +3 -3
  105. data/lib/brakeman/processor.rb +3 -4
  106. data/lib/brakeman/processors/alias_processor.rb +12 -6
  107. data/lib/brakeman/processors/base_processor.rb +8 -7
  108. data/lib/brakeman/processors/controller_alias_processor.rb +10 -7
  109. data/lib/brakeman/processors/controller_processor.rb +5 -9
  110. data/lib/brakeman/processors/haml_template_processor.rb +5 -0
  111. data/lib/brakeman/processors/lib/module_helper.rb +8 -8
  112. data/lib/brakeman/processors/lib/processor_helper.rb +3 -3
  113. data/lib/brakeman/processors/lib/rails2_config_processor.rb +3 -3
  114. data/lib/brakeman/processors/lib/rails2_route_processor.rb +2 -2
  115. data/lib/brakeman/processors/lib/rails3_config_processor.rb +3 -3
  116. data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -2
  117. data/lib/brakeman/processors/lib/render_helper.rb +2 -2
  118. data/lib/brakeman/processors/lib/render_path.rb +18 -1
  119. data/lib/brakeman/processors/library_processor.rb +5 -5
  120. data/lib/brakeman/processors/model_processor.rb +4 -5
  121. data/lib/brakeman/processors/output_processor.rb +5 -0
  122. data/lib/brakeman/processors/template_alias_processor.rb +4 -5
  123. data/lib/brakeman/processors/template_processor.rb +4 -4
  124. data/lib/brakeman/report.rb +3 -3
  125. data/lib/brakeman/report/ignore/config.rb +2 -3
  126. data/lib/brakeman/report/ignore/interactive.rb +2 -2
  127. data/lib/brakeman/report/pager.rb +1 -0
  128. data/lib/brakeman/report/report_base.rb +51 -6
  129. data/lib/brakeman/report/report_codeclimate.rb +3 -3
  130. data/lib/brakeman/report/report_hash.rb +1 -1
  131. data/lib/brakeman/report/report_html.rb +2 -2
  132. data/lib/brakeman/report/report_json.rb +1 -24
  133. data/lib/brakeman/report/report_table.rb +20 -4
  134. data/lib/brakeman/report/report_tabs.rb +1 -1
  135. data/lib/brakeman/report/report_text.rb +2 -2
  136. data/lib/brakeman/rescanner.rb +9 -12
  137. data/lib/brakeman/scanner.rb +19 -14
  138. data/lib/brakeman/tracker.rb +4 -4
  139. data/lib/brakeman/tracker/collection.rb +4 -3
  140. data/lib/brakeman/tracker/config.rb +6 -0
  141. data/lib/brakeman/util.rb +1 -147
  142. data/lib/brakeman/version.rb +1 -1
  143. data/lib/brakeman/warning.rb +23 -13
  144. data/lib/brakeman/warning_codes.rb +1 -0
  145. data/lib/ruby_parser/bm_sexp_processor.rb +1 -0
  146. metadata +78 -61
  147. data/bundle/ruby/2.5.0/gems/highline-1.7.10/Gemfile +0 -11
  148. data/bundle/ruby/2.5.0/gems/highline-1.7.10/INSTALL +0 -59
  149. data/bundle/ruby/2.5.0/gems/highline-1.7.10/README.rdoc +0 -74
  150. data/bundle/ruby/2.5.0/gems/highline-1.7.10/highline.gemspec +0 -37
  151. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline.rb +0 -1048
  152. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/compatibility.rb +0 -16
  153. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/import.rb +0 -41
  154. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/menu.rb +0 -381
  155. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/simulate.rb +0 -48
  156. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/string_extensions.rb +0 -111
  157. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/style.rb +0 -192
  158. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/system_extensions.rb +0 -254
  159. data/bundle/ruby/2.5.0/gems/highline-1.7.10/setup.rb +0 -1360
@@ -1,111 +0,0 @@
1
- # Extensions for class String
2
- #
3
- # HighLine::String is a subclass of String with convenience methods added for colorization.
4
- #
5
- # Available convenience methods include:
6
- # * 'color' method e.g. highline_string.color(:bright_blue, :underline)
7
- # * colors e.g. highline_string.magenta
8
- # * RGB colors e.g. highline_string.rgb_ff6000
9
- # or highline_string.rgb(255,96,0)
10
- # * background colors e.g. highline_string.on_magenta
11
- # * RGB background colors e.g. highline_string.on_rgb_ff6000
12
- # or highline_string.on_rgb(255,96,0)
13
- # * styles e.g. highline_string.underline
14
- #
15
- # Additionally, convenience methods can be chained, for instance the following are equivalent:
16
- # highline_string.bright_blue.blink.underline
17
- # highline_string.color(:bright_blue, :blink, :underline)
18
- # HighLine.color(highline_string, :bright_blue, :blink, :underline)
19
- #
20
- # For those less squeamish about possible conflicts, the same convenience methods can be
21
- # added to the built-in String class, as follows:
22
- #
23
- # require 'highline'
24
- # Highline.colorize_strings
25
-
26
- class HighLine
27
- def self.String(s)
28
- HighLine::String.new(s)
29
- end
30
-
31
- module StringExtensions
32
- def self.included(base)
33
- HighLine::COLORS.each do |color|
34
- color = color.downcase
35
- base.class_eval <<-END
36
- undef :#{color} if method_defined? :#{color}
37
- def #{color}
38
- color(:#{color})
39
- end
40
- END
41
-
42
- base.class_eval <<-END
43
- undef :on_#{color} if method_defined? :on_#{color}
44
- def on_#{color}
45
- on(:#{color})
46
- end
47
- END
48
- HighLine::STYLES.each do |style|
49
- style = style.downcase
50
- base.class_eval <<-END
51
- undef :#{style} if method_defined? :#{style}
52
- def #{style}
53
- color(:#{style})
54
- end
55
- END
56
- end
57
- end
58
-
59
- base.class_eval do
60
- undef :color if method_defined? :color
61
- undef :foreground if method_defined? :foreground
62
- def color(*args)
63
- self.class.new(HighLine.color(self, *args))
64
- end
65
- alias_method :foreground, :color
66
-
67
- undef :on if method_defined? :on
68
- def on(arg)
69
- color(('on_' + arg.to_s).to_sym)
70
- end
71
-
72
- undef :uncolor if method_defined? :uncolor
73
- def uncolor
74
- self.class.new(HighLine.uncolor(self))
75
- end
76
-
77
- undef :rgb if method_defined? :rgb
78
- def rgb(*colors)
79
- color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
80
- raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
81
- color("rgb_#{color_code}".to_sym)
82
- end
83
-
84
- undef :on_rgb if method_defined? :on_rgb
85
- def on_rgb(*colors)
86
- color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
87
- raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
88
- color("on_rgb_#{color_code}".to_sym)
89
- end
90
-
91
- # TODO Chain existing method_missing
92
- undef :method_missing if method_defined? :method_missing
93
- def method_missing(method, *args, &blk)
94
- if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
95
- color(method)
96
- else
97
- raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>"
98
- end
99
- end
100
- end
101
- end
102
- end
103
-
104
- class HighLine::String < ::String
105
- include StringExtensions
106
- end
107
-
108
- def self.colorize_strings
109
- ::String.send(:include, StringExtensions)
110
- end
111
- end
@@ -1,192 +0,0 @@
1
- # color_scheme.rb
2
- #
3
- # Created by Richard LeBer on 2011-06-27.
4
- # Copyright 2011. All rights reserved
5
- #
6
- # This is Free Software. See LICENSE and COPYING for details
7
-
8
- class HighLine
9
-
10
- def self.Style(*args)
11
- args = args.compact.flatten
12
- if args.size==1
13
- arg = args.first
14
- if arg.is_a?(Style)
15
- Style.list[arg.name] || Style.index(arg)
16
- elsif arg.is_a?(::String) && arg =~ /^\e\[/ # arg is a code
17
- if styles = Style.code_index[arg]
18
- styles.first
19
- else
20
- Style.new(:code=>arg)
21
- end
22
- elsif style = Style.list[arg]
23
- style
24
- elsif HighLine.color_scheme && HighLine.color_scheme[arg]
25
- HighLine.color_scheme[arg]
26
- elsif arg.is_a?(Hash)
27
- Style.new(arg)
28
- elsif arg.to_s.downcase =~ /^rgb_([a-f0-9]{6})$/
29
- Style.rgb($1)
30
- elsif arg.to_s.downcase =~ /^on_rgb_([a-f0-9]{6})$/
31
- Style.rgb($1).on
32
- else
33
- raise NameError, "#{arg.inspect} is not a defined Style"
34
- end
35
- else
36
- name = args
37
- Style.list[name] || Style.new(:list=>args)
38
- end
39
- end
40
-
41
- class Style
42
-
43
- def self.index(style)
44
- if style.name
45
- @@styles ||= {}
46
- @@styles[style.name] = style
47
- end
48
- if !style.list
49
- @@code_index ||= {}
50
- @@code_index[style.code] ||= []
51
- @@code_index[style.code].reject!{|indexed_style| indexed_style.name == style.name}
52
- @@code_index[style.code] << style
53
- end
54
- style
55
- end
56
-
57
- def self.rgb_hex(*colors)
58
- colors.map do |color|
59
- color.is_a?(Numeric) ? '%02x'%color : color.to_s
60
- end.join
61
- end
62
-
63
- def self.rgb_parts(hex)
64
- hex.scan(/../).map{|part| part.to_i(16)}
65
- end
66
-
67
- def self.rgb(*colors)
68
- hex = rgb_hex(*colors)
69
- name = ('rgb_' + hex).to_sym
70
- if style = list[name]
71
- style
72
- else
73
- parts = rgb_parts(hex)
74
- new(:name=>name, :code=>"\e[38;5;#{rgb_number(parts)}m", :rgb=>parts)
75
- end
76
- end
77
-
78
- def self.rgb_number(*parts)
79
- parts = parts.flatten
80
- 16 + parts.inject(0) {|kode, part| kode*6 + (part/256.0*6.0).floor}
81
- end
82
-
83
- def self.ansi_rgb_to_hex(ansi_number)
84
- raise "Invalid ANSI rgb code #{ansi_number}" unless (16..231).include?(ansi_number)
85
- parts = (ansi_number-16).to_s(6).rjust(3,'0').scan(/./).map{|d| (d.to_i*255.0/6.0).ceil}
86
- rgb_hex(*parts)
87
- end
88
-
89
- def self.list
90
- @@styles ||= {}
91
- end
92
-
93
- def self.code_index
94
- @@code_index ||= {}
95
- end
96
-
97
- def self.uncolor(string)
98
- string.gsub(/\e\[\d+(;\d+)*m/, '')
99
- end
100
-
101
- attr_reader :name, :list
102
- attr_accessor :rgb, :builtin
103
-
104
- # Single color/styles have :name, :code, :rgb (possibly), :builtin
105
- # Compound styles have :name, :list, :builtin
106
- def initialize(defn = {})
107
- @definition = defn
108
- @name = defn[:name]
109
- @code = defn[:code]
110
- @rgb = defn[:rgb]
111
- @list = defn[:list]
112
- @builtin = defn[:builtin]
113
- if @rgb
114
- hex = self.class.rgb_hex(@rgb)
115
- @name ||= 'rgb_' + hex
116
- elsif @list
117
- @name ||= @list
118
- end
119
- self.class.index self unless defn[:no_index]
120
- end
121
-
122
- def dup
123
- self.class.new(@definition)
124
- end
125
-
126
- def to_hash
127
- @definition
128
- end
129
-
130
- def color(string)
131
- code + string + HighLine::CLEAR
132
- end
133
-
134
- def code
135
- if @list
136
- @list.map{|element| HighLine.Style(element).code}.join
137
- else
138
- @code
139
- end
140
- end
141
-
142
- def red
143
- @rgb && @rgb[0]
144
- end
145
-
146
- def green
147
- @rgb && @rgb[1]
148
- end
149
-
150
- def blue
151
- @rgb && @rgb[2]
152
- end
153
-
154
- def variant(new_name, options={})
155
- raise "Cannot create a variant of a style list (#{inspect})" if @list
156
- new_code = options[:code] || code
157
- if options[:increment]
158
- raise "Unexpected code in #{inspect}" unless new_code =~ /^(.*?)(\d+)(.*)/
159
- new_code = $1 + ($2.to_i + options[:increment]).to_s + $3
160
- end
161
- new_rgb = options[:rgb] || @rgb
162
- self.class.new(self.to_hash.merge(:name=>new_name, :code=>new_code, :rgb=>new_rgb))
163
- end
164
-
165
- def on
166
- new_name = ('on_'+@name.to_s).to_sym
167
- self.class.list[new_name] ||= variant(new_name, :increment=>10)
168
- end
169
-
170
- def bright
171
- create_bright_variant(:bright)
172
- end
173
-
174
- def light
175
- create_bright_variant(:light)
176
- end
177
-
178
- private
179
-
180
- def create_bright_variant(variant_name)
181
- raise "Cannot create a #{name} variant of a style list (#{inspect})" if @list
182
- new_name = ("#{variant_name}_"+@name.to_s).to_sym
183
- new_rgb = @rgb == [0,0,0] ? [128, 128, 128] : @rgb.map {|color| color==0 ? 0 : [color+128,255].min }
184
-
185
- find_style(new_name) or variant(new_name, :increment=>60, :rgb=>new_rgb)
186
- end
187
-
188
- def find_style(name)
189
- self.class.list[name]
190
- end
191
- end
192
- end
@@ -1,254 +0,0 @@
1
- # system_extensions.rb
2
- #
3
- # Created by James Edward Gray II on 2006-06-14.
4
- # Copyright 2006 Gray Productions. All rights reserved.
5
- #
6
- # This is Free Software. See LICENSE and COPYING for details.
7
-
8
- require "highline/compatibility"
9
-
10
- class HighLine
11
- module SystemExtensions
12
- JRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
13
-
14
- if JRUBY
15
- JRUBY_OVER_17 = JRUBY_VERSION =~ /^1.7/ || JRUBY_VERSION =~ /^9/
16
-
17
- def initialize_system_extensions
18
- require 'java'
19
- require 'readline'
20
- if JRUBY_OVER_17
21
- java_import 'jline.console.ConsoleReader'
22
-
23
- input = @input && @input.to_inputstream
24
- output = @output && @output.to_outputstream
25
-
26
- @java_console = ConsoleReader.new(input, output)
27
- @java_console.set_history_enabled(false)
28
- @java_console.set_bell_enabled(true)
29
- @java_console.set_pagination_enabled(false)
30
- @java_terminal = @java_console.getTerminal
31
- elsif JRUBY_VERSION =~ /^1.6/
32
- java_import 'java.io.OutputStreamWriter'
33
- java_import 'java.nio.channels.Channels'
34
- java_import 'jline.ConsoleReader'
35
- java_import 'jline.Terminal'
36
-
37
- @java_input = Channels.newInputStream(@input.to_channel)
38
- @java_output = OutputStreamWriter.new(Channels.newOutputStream(@output.to_channel))
39
- @java_terminal = Terminal.getTerminal
40
- @java_console = ConsoleReader.new(@java_input, @java_output)
41
- @java_console.setUseHistory(false)
42
- @java_console.setBellEnabled(true)
43
- @java_console.setUsePagination(false)
44
- end
45
- end
46
- end
47
-
48
- extend self
49
-
50
- #
51
- # This section builds character reading and terminal size functions
52
- # to suit the proper platform we're running on. Be warned: Here be
53
- # dragons!
54
- #
55
- if RUBY_PLATFORM =~ /mswin(?!ce)|mingw|bccwin/i
56
- begin
57
- require "fiddle"
58
-
59
- module WinAPI
60
- include Fiddle
61
- Handle = RUBY_VERSION >= "2.0.0" ? Fiddle::Handle : DL::Handle
62
- Kernel32 = Handle.new("kernel32")
63
- Crt = Handle.new("msvcrt") rescue Handle.new("crtdll")
64
-
65
- def self._getch
66
- @@_m_getch ||= Function.new(Crt["_getch"], [], TYPE_INT)
67
- @@_m_getch.call
68
- end
69
-
70
- def self.GetStdHandle(handle_type)
71
- @@get_std_handle ||= Function.new(Kernel32["GetStdHandle"], [-TYPE_INT], -TYPE_INT)
72
- @@get_std_handle.call(handle_type)
73
- end
74
-
75
- def self.GetConsoleScreenBufferInfo(cons_handle, lp_buffer)
76
- @@get_console_screen_buffer_info ||=
77
- Function.new(Kernel32["GetConsoleScreenBufferInfo"], [TYPE_LONG, TYPE_VOIDP], TYPE_INT)
78
- @@get_console_screen_buffer_info.call(cons_handle, lp_buffer)
79
- end
80
- end
81
- rescue LoadError
82
- require "dl/import"
83
-
84
- module WinAPI
85
- if defined?(DL::Importer)
86
- # Ruby 1.9
87
- extend DL::Importer
88
- else
89
- # Ruby 1.8
90
- extend DL::Importable
91
- end
92
- begin
93
- dlload "msvcrt", "kernel32"
94
- rescue DL::DLError
95
- dlload "crtdll", "kernel32"
96
- end
97
- extern "unsigned long _getch()"
98
- extern "unsigned long GetConsoleScreenBufferInfo(unsigned long, void*)"
99
- extern "unsigned long GetStdHandle(unsigned long)"
100
-
101
- # Ruby 1.8 DL::Importable.import does mname[0,1].downcase so FooBar becomes fooBar
102
- if defined?(getConsoleScreenBufferInfo)
103
- alias_method :GetConsoleScreenBufferInfo, :getConsoleScreenBufferInfo
104
- module_function :GetConsoleScreenBufferInfo
105
- end
106
- if defined?(getStdHandle)
107
- alias_method :GetStdHandle, :getStdHandle
108
- module_function :GetStdHandle
109
- end
110
- end
111
- end
112
-
113
- CHARACTER_MODE = "Win32API" # For Debugging purposes only.
114
-
115
- #
116
- # Windows savvy getc().
117
- #
118
- # *WARNING*: This method ignores <tt>input</tt> and reads one
119
- # character from +STDIN+!
120
- #
121
- def get_character( input = STDIN )
122
- WinAPI._getch
123
- end
124
-
125
- # We do not define a raw_no_echo_mode for Windows as _getch turns off echo
126
- def raw_no_echo_mode
127
- end
128
-
129
- def restore_mode
130
- end
131
-
132
- # A Windows savvy method to fetch the console columns, and rows.
133
- def terminal_size
134
- format = 'SSSSSssssSS'
135
- buf = ([0] * format.size).pack(format)
136
- stdout_handle = WinAPI.GetStdHandle(0xFFFFFFF5)
137
-
138
- WinAPI.GetConsoleScreenBufferInfo(stdout_handle, buf)
139
- _, _, _, _, _,
140
- left, top, right, bottom, _, _ = buf.unpack(format)
141
- return right - left + 1, bottom - top + 1
142
- end
143
- else # If we're not on Windows try...
144
- begin
145
- require "termios" # Unix, first choice termios.
146
-
147
- CHARACTER_MODE = "termios" # For Debugging purposes only.
148
-
149
- def raw_no_echo_mode
150
- @state = Termios.getattr(@input)
151
- new_settings = @state.dup
152
- new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON)
153
- new_settings.c_cc[Termios::VMIN] = 1
154
- Termios.setattr(@input, Termios::TCSANOW, new_settings)
155
- end
156
-
157
- def restore_mode
158
- Termios.setattr(@input, Termios::TCSANOW, @state)
159
- end
160
- rescue LoadError # If our first choice fails, try using JLine
161
- if JRUBY # if we are on JRuby. JLine is bundled with JRuby.
162
- CHARACTER_MODE = "jline" # For Debugging purposes only.
163
-
164
- def terminal_size
165
- if JRUBY_OVER_17
166
- [ @java_terminal.get_width, @java_terminal.get_height ]
167
- else
168
- [ @java_terminal.getTerminalWidth, @java_terminal.getTerminalHeight ]
169
- end
170
- end
171
-
172
- def raw_no_echo_mode
173
- @state = @java_console.getEchoCharacter
174
- @java_console.setEchoCharacter 0
175
- end
176
-
177
- def restore_mode
178
- @java_console.setEchoCharacter @state
179
- end
180
- else # If we are not on JRuby, try ncurses
181
- begin
182
- require 'ffi-ncurses'
183
- CHARACTER_MODE = "ncurses" # For Debugging purposes only.
184
-
185
- def raw_no_echo_mode
186
- FFI::NCurses.initscr
187
- FFI::NCurses.cbreak
188
- end
189
-
190
- def restore_mode
191
- FFI::NCurses.endwin
192
- end
193
-
194
- #
195
- # A ncurses savvy method to fetch the console columns, and rows.
196
- #
197
- def terminal_size
198
- size = [80, 40]
199
- FFI::NCurses.initscr
200
- begin
201
- size = FFI::NCurses.getmaxyx(FFI::NCurses.stdscr).reverse
202
- ensure
203
- FFI::NCurses.endwin
204
- end
205
- size
206
- end
207
- rescue LoadError # Finally, if all else fails, use stty
208
- # *WARNING*: This requires the external "stty" program!
209
- CHARACTER_MODE = "stty" # For Debugging purposes only.
210
-
211
- def raw_no_echo_mode
212
- @state = `stty -g`
213
- system "stty raw -echo -icanon isig"
214
- end
215
-
216
- def restore_mode
217
- system "stty #{@state}"
218
- print "\r"
219
- end
220
- end
221
- end
222
- end
223
-
224
- # For termios and stty
225
- if not method_defined?(:terminal_size)
226
- # A Unix savvy method using stty to fetch the console columns, and rows.
227
- # ... stty does not work in JRuby
228
- def terminal_size
229
- begin
230
- require "io/console"
231
- winsize = IO.console.winsize.reverse rescue nil
232
- return winsize if winsize
233
- rescue LoadError
234
- end
235
-
236
- if /solaris/ =~ RUBY_PLATFORM and
237
- `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
238
- [$2, $1].map { |x| x.to_i }
239
- elsif `stty size` =~ /^(\d+)\s(\d+)$/
240
- [$2.to_i, $1.to_i]
241
- else
242
- [ 80, 24 ]
243
- end
244
- end
245
- end
246
- end
247
-
248
- if not method_defined?(:get_character)
249
- def get_character( input = STDIN )
250
- input.getbyte
251
- end
252
- end
253
- end
254
- end