monocle-print 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/monocle-print.rb +5 -2
- data/lib/monocle-print/graphics.rb +32 -57
- data/lib/monocle-print/output-device.rb +2 -4
- data/lib/monocle-print/presentation.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGVhMTAyZWIyYjRmMzdlMjJlNzkzNDM5MjdmYzExOWYxODA5YjFlMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWFiZWYxNzUzYjgwZmFhZDU0OWI2ZDIyMzRmMDU4MWQ5MzgzMTFjNw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjAyNzQzNDAxMmVhMTYxYmVmZjgwNzlkYmI2ZWU4OWZiMzE4MjQ3NjQ1YjIz
|
10
|
+
ZTkxNDYyY2MzYjA0MDlkMDc4OGQ5ZjFhMjNjMjFkMTVmZWQxNjgxYzllNTRm
|
11
|
+
MjQwNTQ1NTJjYzc4NDkxNWZlZWE2ZDFhNTg1ZTkzNGQyOTVlM2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjIzZDUyODIzNGU1Yzc0ODc5ODkwMzQ4NTJlMjNjMmZmNGFiNTc3ZTdlMDE2
|
14
|
+
ZGUxM2QwZDllZTFlNDFjMDk2NTExZTQzNzY4OTUyZWRmOTdiMDhjMDRhYjBl
|
15
|
+
MTc5YmY3ZDA5NGFiMTEwMjMzMjRlYTA0ZmE3ZjFjMjdmMDhmODg=
|
data/lib/monocle-print.rb
CHANGED
@@ -7,8 +7,11 @@ rescue LoadError
|
|
7
7
|
# ignore
|
8
8
|
end
|
9
9
|
|
10
|
+
require 'delegate'
|
11
|
+
autoload :StringIO, 'stringio' unless defined?( StringIO )
|
12
|
+
|
10
13
|
module MonoclePrint
|
11
|
-
VERSION = '1.0.
|
14
|
+
VERSION = '1.0.4'
|
12
15
|
|
13
16
|
def self.version
|
14
17
|
VERSION
|
@@ -54,7 +57,7 @@ module_function
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def Style( obj )
|
57
|
-
Graphics === obj ? obj : Graphics
|
60
|
+
Graphics === obj ? obj : Graphics.style( obj )
|
58
61
|
end
|
59
62
|
|
60
63
|
def Rectangle( obj )
|
@@ -1,56 +1,36 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
+
require 'monocle-print/graphics/registry'
|
4
5
|
|
5
6
|
module MonoclePrint
|
6
|
-
Graphics =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
Graphics =
|
8
|
+
Struct.new(
|
9
|
+
:ew, # west east - horizontal line
|
10
|
+
:ns, # north south - vertical line
|
11
|
+
:es, # north west - top right corner
|
12
|
+
:sw, # north east
|
13
|
+
:nw, # south east
|
14
|
+
:en, # south west
|
15
|
+
:ens, # north south east
|
16
|
+
:nsw, # north south west
|
17
|
+
:enw, # east north west
|
18
|
+
:esw, # east south west
|
19
|
+
:ensw, # east north south west - intersection of horiz & vertical lines
|
20
|
+
:tree_fork,
|
21
|
+
:tree_tail,
|
22
|
+
:blank
|
23
|
+
)
|
22
24
|
|
23
25
|
class Graphics
|
24
26
|
include MonoclePrint
|
25
|
-
|
26
|
-
|
27
|
-
def self.styles
|
28
|
-
NAMED_STYLES.keys
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.define( name, *parts )
|
32
|
-
parts.map! { | p | Line( p ).freeze }
|
33
|
-
NAMED_STYLES[ name.to_s ] = new( *parts ).freeze
|
34
|
-
end
|
35
|
-
|
27
|
+
extend GraphicsRegistry
|
28
|
+
|
36
29
|
define :blank, '', '', '', '', '', '', '', '', '', '', '', '', ''
|
37
30
|
define :ascii, '-', '|', '+', '+', '+', '+', '+', '+', '+', '+', '+', '|', '`'
|
38
31
|
define :single_line, '─', '│', '┌', '┐', '┘', '└', '├', '┤', '┴', '┬', '┼', '├', '└'
|
39
32
|
define :double_line, '═', '║', '╔', '╗', '╝', '╚', '╠', '╣', '╩', '╦', '╬', '╠', '╚'
|
40
|
-
|
41
|
-
default_style = ENV.fetch( 'MONOCLE_PRINT_STYLE', 'ascii' )
|
42
|
-
unless styles.include?( default_style )
|
43
|
-
message = <<-END.gsub!( /^\s*\| ?/, '' ).strip!.gsub!( /\s+/, ' ' )
|
44
|
-
| cannot set MonoclePrint's default graphics style
|
45
|
-
| from the MONOCLE_PRINT_STYLE environment variable as `%p'
|
46
|
-
| is not a known style; defaulting to `ascii'
|
47
|
-
END
|
48
|
-
warn( message % default_style )
|
49
|
-
default_style = 'ascii'
|
50
|
-
end
|
51
|
-
|
52
|
-
DEFAULT_STYLE = default_style
|
53
|
-
|
33
|
+
|
54
34
|
def format( description )
|
55
35
|
out = Line( description )
|
56
36
|
out.gsub!( /<([nsewlrtbudhv]+)(?::(\d+))?>/i ) do
|
@@ -59,41 +39,40 @@ class Graphics
|
|
59
39
|
end
|
60
40
|
return( out )
|
61
41
|
end
|
62
|
-
|
42
|
+
|
63
43
|
def horizontal_line( width )
|
64
44
|
ew.tile( width )
|
65
45
|
end
|
66
|
-
|
46
|
+
|
67
47
|
def box_top( width )
|
68
48
|
format( "<se><ew:#{ width }><sw>" )
|
69
49
|
end
|
70
|
-
|
50
|
+
|
71
51
|
def box_bottom( width )
|
72
52
|
format( "<ne><ew:#{ width }><nw>" )
|
73
53
|
end
|
74
|
-
|
54
|
+
|
75
55
|
def table_top( *column_widths )
|
76
56
|
nw + line_with_joints( esw, column_widths ) + ne
|
77
57
|
end
|
78
|
-
|
58
|
+
|
79
59
|
def table_divide( *column_widths )
|
80
60
|
ens + line_with_joints( ensw, column_widths ) + nsw
|
81
61
|
end
|
82
|
-
|
62
|
+
|
83
63
|
def table_bottom( *column_widths )
|
84
64
|
sw + line_with_joints( enw, column_widths ) + se
|
85
65
|
end
|
86
|
-
|
66
|
+
|
87
67
|
def line_with_joints( joint, *widths )
|
88
68
|
widths.map { | w | horizontal_line( w ) }.join( joint )
|
89
69
|
end
|
90
|
-
|
70
|
+
|
91
71
|
alias h ew
|
92
72
|
alias v ns
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
73
|
+
|
74
|
+
private
|
75
|
+
|
97
76
|
def resolve_name( name )
|
98
77
|
name.downcase!
|
99
78
|
name.tr!( 'lrtbud', 'wensns' )
|
@@ -103,9 +82,5 @@ private
|
|
103
82
|
chars.uniq!
|
104
83
|
self[ chars.join('') ]
|
105
84
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
85
|
end
|
110
|
-
|
111
86
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
require 'delegate'
|
5
|
-
autoload :StringIO, 'stringio' unless defined?( StringIO )
|
6
4
|
|
7
5
|
module MonoclePrint
|
8
6
|
class OutputDevice < DelegateClass( IO )
|
@@ -424,8 +422,8 @@ private
|
|
424
422
|
detected_height, detected_width = size.height, size.width
|
425
423
|
end
|
426
424
|
Pair.new(
|
427
|
-
@
|
428
|
-
@
|
425
|
+
@forced_width || detected_width,
|
426
|
+
@forced_height || detected_height
|
429
427
|
)
|
430
428
|
rescue Exception
|
431
429
|
default_size
|
@@ -10,7 +10,7 @@ module Presentation
|
|
10
10
|
super
|
11
11
|
klass.extend( ClassMethods )
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
attr_accessor :owner
|
15
15
|
protected :owner=
|
16
16
|
|
@@ -41,7 +41,7 @@ module Presentation
|
|
41
41
|
|
42
42
|
def style( value = nil )
|
43
43
|
value and self.style = value
|
44
|
-
@style or @owner ? @owner.style : Graphics
|
44
|
+
@style or @owner ? @owner.style : Graphics.default
|
45
45
|
end
|
46
46
|
|
47
47
|
def style= value
|