Module: PatchELF::Helper
- Defined in:
- lib/patchelf/helper.rb
Overview
Helper methods for internal usage.
Constant Summary collapse
- PAGE_SIZE =
The size of one page.
0x1000- COLOR_CODE =
Color codes for pretty print.
{ esc_m: "\e[0m", info: "\e[38;5;82m", # light green warn: "\e[38;5;230m", # light yellow error: "\e[38;5;196m" # heavy red }.freeze
Class Method Summary collapse
-
.aligndown(val, align = PAGE_SIZE) ⇒ Integer
Aligned result.
-
.alignup(val, align = PAGE_SIZE) ⇒ Integer
Aligned result.
-
.color_enabled? ⇒ Boolean
For #colorize to decide if need add color codes.
-
.colorize(str, type) ⇒ String
For wrapping string with color codes for prettier inspect.
Class Method Details
.aligndown(val, align = PAGE_SIZE) ⇒ Integer
Returns Aligned result.
51 52 53 |
# File 'lib/patchelf/helper.rb', line 51 def aligndown(val, align = PAGE_SIZE) val - (val & (align - 1)) end |
.alignup(val, align = PAGE_SIZE) ⇒ Integer
Returns Aligned result.
66 67 68 |
# File 'lib/patchelf/helper.rb', line 66 def alignup(val, align = PAGE_SIZE) (val & (align - 1)).zero? ? val : (aligndown(val, align) + align) end |
.color_enabled? ⇒ Boolean
For #colorize to decide if need add color codes.
36 37 38 |
# File 'lib/patchelf/helper.rb', line 36 def color_enabled? $stderr.tty? end |
.colorize(str, type) ⇒ String
For wrapping string with color codes for prettier inspect.
26 27 28 29 30 31 32 |
# File 'lib/patchelf/helper.rb', line 26 def colorize(str, type) return str unless color_enabled? cc = COLOR_CODE color = cc.key?(type) ? cc[type] : '' "#{color}#{str.sub(COLOR_CODE[:esc_m], color)}#{cc[:esc_m]}" end |