monocle-print 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmQwZjE5MDc2Nzg1MWIxNWY3YmUwMTc1M2Y1NWU2Yjg5N2NlZGY1Ng==
4
+ ODM2ZmVhODYxMDhhYTc1NjdlNWJkNGI1ZDVkYjY4NDI3M2E0ZTRmYg==
5
5
  data.tar.gz: !binary |-
6
- ODM3ODlmMGNjYjc0MzVhYmU4M2Y1MjBmOWJhMjZlZjQ2YzZjOWM5OQ==
6
+ NzJhODM3MTczZmI4NzJkMTQxNmZkNDI3YWE2NjBhNTEzM2U0OTI1MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzU1NzczZWY0YmIyMWNkYWViMDIxNGVmNjA0MTViYWNiODY5NjlkMTI1ZTUz
10
- NTRmNWE4NDcxMTU1ZGU5NjM1NTg2NDUwMjljZWRmN2U0YjFiZDllY2UzZjIz
11
- YjkwYTdmOGQyMDM0ZmNmOGExYjFmYmUxM2JiNWQ4MWQwODU4MTg=
9
+ MDMxZjA0NjU1ODIzMWViMGU5YTVjZGVkNzczOTU1NGEwNjk4OTg0M2E3YjU1
10
+ MWFhMjk1OGQ0MzgyN2JkMTY2ZTRlN2NkODlkZjc1MjdhYmNkOWY2Mzk3NTM1
11
+ ODA3NmIzODlhNWJjZmRlZDY5NjgwYjI1NWVjZDUwYjFlMGEyMzA=
12
12
  data.tar.gz: !binary |-
13
- YzhjNTE3YjRlMTkwMjE5MWY4NzEwNTgyY2U2NjliZWNhOWM4MzUyMjU1MDE1
14
- MjFkYjEwYWNmZjgxODc1M2RkZjYwN2JmMjZkYzE1ODE1ZjBkZGI2ODNiNTA3
15
- MmQ0MjQ3MWNjNmU4ZmJlNGJkNmUwNWIyZmQ2M2FmOGVmYmFkZGE=
13
+ ODczNmI5YmYwNTYwNzdlMGVmNTAzYjkxZDJmMTUwMzE5NjllNzBjM2ZhYWFj
14
+ ZDg0MTEwZTM1YWVmM2ZlZDQwMjNhOTYwNmJiNmFlZjllNGQ1MDUxMjU5NDBm
15
+ OTcxNTI4MjI3MTUzZTZmNjg5NDcyYjYzMjk1OGYyOTgyMTBlNTE=
data/lib/monocle-print.rb CHANGED
@@ -11,7 +11,7 @@ require 'delegate'
11
11
  autoload :StringIO, 'stringio' unless defined?( StringIO )
12
12
 
13
13
  module MonoclePrint
14
- VERSION = '1.0.5'
14
+ VERSION = '1.1.0'
15
15
 
16
16
  def self.version
17
17
  VERSION
@@ -70,7 +70,9 @@ class OutputDevice < DelegateClass( IO )
70
70
 
71
71
  @background_stack = []
72
72
  @foreground_stack = []
73
- @background = @foreground = nil
73
+ @modifier_stack = []
74
+
75
+ @background = @foreground = @modifier = nil
74
76
  @use_color = options.fetch( :use_color, tty? )
75
77
 
76
78
  @cursor = Pair.new( 0, 0 )
@@ -120,7 +122,17 @@ class OutputDevice < DelegateClass( IO )
120
122
 
121
123
  alias on background
122
124
 
123
- for color in ANSI_COLORS.keys
125
+ def modifier( name = nil )
126
+ name or return( @modifier_stack.last )
127
+ begin
128
+ @modifier_stack.push( name )
129
+ yield
130
+ ensure
131
+ @modifier_stack.pop
132
+ end
133
+ end
134
+
135
+ for color in ANSI_COLOR_NAMES
124
136
  class_eval( <<-END, __FILE__, __LINE__ )
125
137
  def #{ color }
126
138
  foreground( :#{ color } ) { yield }
@@ -132,6 +144,14 @@ class OutputDevice < DelegateClass( IO )
132
144
  END
133
145
  end
134
146
 
147
+ for modifier in ANSI_MODIFIER_NAMES
148
+ class_eval( <<-END, __FILE__, __LINE__ )
149
+ def #{ modifier }
150
+ modifier( :#{ modifier } ) { yield }
151
+ end
152
+ END
153
+ end
154
+
135
155
  def use_color?
136
156
  @use_color
137
157
  end
@@ -374,7 +394,6 @@ class OutputDevice < DelegateClass( IO )
374
394
  return!
375
395
  end
376
396
 
377
-
378
397
  for m in %w( horizontal_line box_top box_bottom )
379
398
  class_eval( <<-END, __FILE__, __LINE__ + 1 )
380
399
  def #{ m }
@@ -387,14 +406,21 @@ class OutputDevice < DelegateClass( IO )
387
406
  def color_code
388
407
  @use_color or return ''
389
408
  code = ''
409
+
390
410
  case fg = @foreground_stack.last
391
411
  when Fixnum then code << xterm_color( ?f, fg )
392
412
  when String, Symbol then code << ansi_color( ?f, fg )
393
413
  end
414
+
394
415
  case bg = @background_stack.last
395
416
  when Fixnum then code << xterm_color( ?b, bg )
396
417
  when String, Symbol then code << ansi_color( ?b, bg )
397
418
  end
419
+
420
+ case mod = @modifier_stack.last
421
+ when String, Symbol then code << ansi_modifier( mod )
422
+ end
423
+
398
424
  code
399
425
  end
400
426
 
@@ -11,13 +11,24 @@ module TerminalEscapes
11
11
  :yellow => 3, :green => 2, :black => 0,
12
12
  :red => 1, :cyan => 6
13
13
  }
14
-
14
+ ANSI_COLOR_NAMES = ANSI_COLORS.keys.freeze
15
+
16
+ ANSI_MODIFIERS =
17
+ {
18
+ :bold => 1,
19
+ :underline => 4,
20
+ :blink => 5,
21
+ :reverse => 7,
22
+ :conceal => 8
23
+ }
24
+ ANSI_MODIFIER_NAMES = ANSI_MODIFIERS.keys.freeze
25
+
15
26
  module_function
16
-
27
+
17
28
  #def term_info
18
29
  # @term_info ||= TermInfo.new
19
30
  #end
20
-
31
+
21
32
  def ansi_color( type, color, bold = nil )
22
33
  offset =
23
34
  case type
@@ -29,7 +40,7 @@ module TerminalEscapes
29
40
  end
30
41
  "\e[#{ '1;' if bold }#{ code }m"
31
42
  end
32
-
43
+
33
44
  def xterm_color( type, color_index, bold = nil )
34
45
  prefix =
35
46
  case type
@@ -38,7 +49,7 @@ module TerminalEscapes
38
49
  end
39
50
  "\e[#{ prefix };5;#{ color_index }m"
40
51
  end
41
-
52
+
42
53
  def konsole_color( type, r, g, b, bold = nil)
43
54
  prefix =
44
55
  case type
@@ -47,115 +58,123 @@ module TerminalEscapes
47
58
  end
48
59
  "\e[#{ prefix };2;#{ r };#{ g };#{ b }m"
49
60
  end
50
-
61
+
62
+ def ansi_modifier( name )
63
+ code =
64
+ ANSI_MODIFIERS.fetch( name.to_sym ) do
65
+ fail ArgumentError, "unknown modifier name `%s'" % name
66
+ end
67
+ "\e[#{ code }m"
68
+ end
69
+
51
70
  def clear_attr
52
71
  "\e[0m"
53
72
  end
54
-
73
+
55
74
  def bold
56
75
  "\e[1m"
57
76
  end
58
-
77
+
59
78
  def underline
60
79
  "\e[4m"
61
80
  end
62
-
81
+
63
82
  def blink
64
83
  "\e[5m"
65
84
  end
66
-
85
+
67
86
  def reverse
68
87
  "\e[7m"
69
88
  end
70
-
89
+
71
90
  def conceal
72
91
  "\e[8m"
73
92
  end
74
-
93
+
75
94
  def set_cursor( line = 0, column = 0 )
76
95
  "\e[%i;%iH" % [ line, column ]
77
96
  end
78
-
97
+
79
98
  def cursor_up( lines = 1 )
80
99
  "\e[%iA" % lines
81
100
  end
82
-
101
+
83
102
  def cursor_down( lines = 1 )
84
103
  "\e[%iB" % lines
85
104
  end
86
-
105
+
87
106
  def cursor_forward( columns = 1 )
88
107
  "\e[%iC" % columns
89
108
  end
90
-
109
+
91
110
  def cursor_backward( columns = 1 )
92
111
  "\e[%iD" % columns
93
112
  end
94
-
113
+
95
114
  def save_cursor
96
115
  "\e[s"
97
116
  end
98
-
117
+
99
118
  def restore_cursor
100
119
  "\e[u"
101
120
  end
102
-
121
+
103
122
  #def clear_line
104
123
  # "\e[K"
105
124
  #end
106
-
125
+
107
126
  # VT100 escapes
108
127
  def double_height_top
109
128
  "\e#3"
110
129
  end
111
-
130
+
112
131
  def dobule_height_bottom
113
132
  "\e#4"
114
133
  end
115
-
134
+
116
135
  def single_width
117
136
  "\e#5"
118
137
  end
119
-
138
+
120
139
  def double_width
121
140
  "\e#6"
122
141
  end
123
-
142
+
124
143
  def clear_right
125
144
  "\e[0K"
126
145
  end
127
-
146
+
128
147
  def clear_left
129
148
  "\e[1K"
130
149
  end
131
-
150
+
132
151
  def clear_line
133
152
  "\e[2K"
134
153
  end
135
-
154
+
136
155
  def clear_down
137
156
  "\e[0J"
138
157
  end
139
-
158
+
140
159
  def clear_up
141
160
  "\e[1J"
142
161
  end
143
-
162
+
144
163
  def clear_screen
145
164
  "\e[2J"
146
165
  end
147
-
166
+
148
167
  end
149
168
  end
150
169
 
151
170
  if __FILE__ == $0
152
-
171
+
153
172
  TE = MonoclePrint::TerminalEscapes
154
173
  for attr in %w[ bold underline blink reverse conceal ]
155
174
  print( "This should be #{ attr }:".ljust( 30 ) )
156
175
  printf( "%swhateva\e[0m\n", TE.send( attr ) )
157
176
  end
158
-
177
+
159
178
  colors = TE::ANSI_COLORS.keys.map(&:to_s).sort!
160
179
  for color in colors
161
180
  print( "This should be #{ color }:".ljust( 30 ) )
@@ -163,7 +182,7 @@ if __FILE__ == $0
163
182
  printf( "%swhateva\e[0m\t", TE.ansi_color( ?b, color ) )
164
183
  printf( "%sbright_whateva\e[0m\n", TE.ansi_color( ?f, color, true ) )
165
184
  end
166
-
185
+
167
186
  for dir in %w( left right line )
168
187
  name = "clear_#{ dir }"
169
188
  code = TE.send( name )
@@ -177,7 +196,7 @@ if __FILE__ == $0
177
196
  puts("at end")
178
197
  printf("%-14s =>%s\n", name, code, name)
179
198
  end
180
-
199
+
181
200
  puts( "[ Tabs ]" )
182
201
  puts( " \eHx \eHx \eHx ")
183
202
  puts( "one\ttwo\tthree\tfour" )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monocle-print
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - monocle-print
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-27 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc