muflax 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32e51e89418d15e5bd08d0f4dc646c24f942fde7
4
- data.tar.gz: dc547650ac0434a35bb5ac6907cb94fc2feb7d14
3
+ metadata.gz: e18db37633af5a0f277d21797637376d2721b2e4
4
+ data.tar.gz: 497b57bad006b26bc036fc34923ce042a5152845
5
5
  SHA512:
6
- metadata.gz: 10ed096b459325fed652ae748918075447b3c39bff60c65392cad58ff7b12bde8f2d0d7b8300cc041cc24376e8adead7bee88a244862a1dad3de484ba5885db8
7
- data.tar.gz: 68c7dac02fa6cd1afd081f5538b938a1374ac0f94762fb17a93f1e5428351ad43b700ea606a547383f31a51a2065a5d2b64b00f363e473e1f40e1a68ba033ccb
6
+ metadata.gz: 598dc5ef8f411290cd55b22f90a105633c6e97bbf3bb2f6aeb923abd82f3785b57daf7e5a0a3c51855533f3dd36fc7e90edafc3022df332bc06d534f6abd3b65
7
+ data.tar.gz: 951337d9166fd81021e323d5b1c86645199d874c4e936d2e0156669cf086dbb342bb4a18a27faf4dcc6df94503d42ab58c5d35e34ca0d00cee5e00bae67b761b
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- muflax (0.2.3)
4
+ muflax (0.2.4)
5
5
  activesupport (~> 5)
6
6
  awesome_print
7
7
  debug_inspector
data/lib/muflax/array.rb CHANGED
@@ -24,7 +24,7 @@ class Array
24
24
  end
25
25
 
26
26
  # justify all columns
27
- (0..columns).each do |column|
27
+ 0.upto(columns).each do |column|
28
28
  length = lines.map{|line| line[column]}.length_of_longest
29
29
 
30
30
  lines.each do |line|
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Copyright Stefan Dorn <mail@muflax.com>, 2017
4
+ # License: GNU GPLv3 (or later) <http://www.gnu.org/copyleft/gpl.html>
5
+
6
+ module Kernel
7
+ def clear_screen
8
+ print "\e[H\e[2J"
9
+ end
10
+ end
11
+
12
+ class Panes
13
+ class Section
14
+ attr_reader :lines
15
+ attr_accessor :divider
16
+
17
+ def initialize
18
+ @lines = []
19
+ @divider = nil
20
+ end
21
+
22
+ def <<(line) ; @lines << line ; end
23
+ def size ; @lines.size ; end
24
+ def empty? ; @lines.empty? ; end
25
+ end
26
+
27
+ attr_reader :width, :height, :columns
28
+ attr_reader :column_width, :column_height
29
+ attr_reader :remaining_columns, :remaining_lines
30
+ attr_reader :sections
31
+
32
+ def initialize columns: 2, separator: "|", divider: "="
33
+ # can't be bigger than the terminal
34
+ @width, @height = HighLine::SystemExtensions.terminal_size
35
+ @separator = separator
36
+ @divider = divider
37
+ seps = (columns-1) * separator.size
38
+ @columns = columns
39
+ @column_width = @width / columns - seps
40
+ @column_height = @height
41
+ @sections = []
42
+
43
+ # keep track of drawing positions
44
+ @used_lines = 0
45
+ @need_divider = false
46
+ end
47
+
48
+ def last_section
49
+ @sections << Section.new if @sections.empty?
50
+ @sections.last
51
+ end
52
+
53
+ def new_section
54
+ @sections << Section.new unless last_section.empty?
55
+ @sections.last
56
+ end
57
+
58
+ def total_lines ; @height * @columns ; end
59
+ def remaining_lines ; total_lines - @used_lines ; end
60
+ def remaining_lines_on_column ; remaining_lines % @height ; end
61
+ def used_columns ; @used_lines / @height ; end
62
+ def remaining_columns ; @columns - used_columns ; end
63
+ def column_full? ; remaining_lines_on_column <= 1 ; end
64
+
65
+ def new_column
66
+ unless column_full?
67
+ section [""]* remaining_lines_on_column
68
+ last_section.divider = false
69
+ last_section.lines << ""
70
+ end
71
+ end
72
+
73
+ def section *lines, max: :all, tail: false, header: false
74
+ lines = [*lines].flatten
75
+ section = new_section
76
+ left = remaining_lines_on_column
77
+
78
+ # ap h: @height, t: total_lines, r: remaining_lines, rc: remaining_lines_on_column, l: lines
79
+
80
+ num = case max
81
+ when :all ; lines.size
82
+ when :column ; left == 0 ? @column_height : left
83
+ # when :full_column ; @column_height
84
+ else ; raise "unknown: #{max}"
85
+ end
86
+
87
+ num = [num, remaining_lines].min
88
+ @used_lines += num
89
+
90
+ if @need_divider
91
+ if header
92
+ h = lines.first
93
+ lines = lines[1..-1]
94
+ div = h.sub(/^\s+/){|s| @divider*s.size}.sub(/\s+$/){|s| @divider*s.size}
95
+ section.divider = div + @divider * (@column_width - div.str_length)
96
+ else
97
+ @used_lines += 1
98
+ num -= 1 unless max == :all # compensate for the divider
99
+ section.divider = @divider * @column_width
100
+ end
101
+ end
102
+
103
+ to_print = tail ? lines.last(num) : lines.first(num)
104
+ @need_divider = ! column_full?
105
+
106
+ to_print.each do |line|
107
+ section << line.truncate(@column_width, omission: "⇏")
108
+ end
109
+ end
110
+
111
+ def show!
112
+ output = []
113
+ @sections.each do |s|
114
+ output << s.divider unless s.divider.nil?
115
+ output += s.lines
116
+ end
117
+
118
+ # ap w: @width, h: @height, cw: @column_width, ch: @column_height, c: @columns
119
+ # ap ul: @used_lines, os: output.size
120
+ # ap output
121
+
122
+ max_row = @column_height - 1
123
+ max_col = @columns - 1
124
+
125
+ clear_screen
126
+
127
+ (0..max_row).each do |row|
128
+ (0..max_col).each do |col|
129
+ i = col * @column_height + row
130
+ out = output[i]&.rstrip || ""
131
+ print out
132
+ print " " * (@column_width - out.str_length)
133
+ print HighLine.color("", :reset)
134
+
135
+ if col < max_col ; print @separator
136
+ elsif row < max_row ; print "\n"
137
+ else ; # skip
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Copyright Stefan Dorn <mail@muflax.com>, 2017
4
+ # License: GNU GPLv3 (or later) <http://www.gnu.org/copyleft/gpl.html>
5
+
6
+ class Table
7
+ def initialize separator: "\t", alignment: :left
8
+ @rows = []
9
+ @lengths = []
10
+ @separator = separator
11
+ @just = case alignment
12
+ when :left ; :ljust
13
+ when :right ; :rjust
14
+ when :center ; :center
15
+ else
16
+ raise "invalid alignment: #{alignment}"
17
+ end
18
+ end
19
+
20
+ def [](row) ; @rows[row] ; end
21
+ def []=(row, x) ; @rows[row] = x ; end
22
+
23
+ def <<(row)
24
+ row.each.with_index do |x, i|
25
+ l = @lengths[i] || 0
26
+ s = x.str_length
27
+ @lengths[i] = s if s > l
28
+ end
29
+
30
+ @rows << row
31
+ end
32
+
33
+ def render out
34
+ @rows.each.with_index do |row, row_i|
35
+ row.each.with_index do |elem, elem_i|
36
+ len = @lengths[elem_i]
37
+ next if len.nil?
38
+
39
+ # align element based on how much it's internally longer than it appears
40
+ aligned = if not elem.nil?
41
+ elem_diff = elem.to_s.length - elem.str_length
42
+ elem.send(@just, len + elem_diff)
43
+ else
44
+ " "*len
45
+ end
46
+
47
+ if elem_i == (row.size - 1)
48
+ out.write(aligned.rstrip)
49
+ else
50
+ out.write(aligned)
51
+ out.write(@separator)
52
+ end
53
+ end
54
+ out.write("\n") unless row_i == (@rows.size - 1)
55
+ end
56
+ end
57
+
58
+ def to_s
59
+ render(StringIO.new).string
60
+ end
61
+ end
data/muflax.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "muflax"
3
- s.version = "0.2.3"
3
+ s.version = "0.2.4"
4
4
 
5
5
  s.authors = ["muflax"]
6
6
  s.summary = "muflax standard library"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muflax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - muflax
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDLDCCAhSgAwIBAgIBAzANBgkqhkiG9w0BAQUFADA8MQ0wCwYDVQQDDARtY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Yb
29
- pNY9O02iAik7VcnsSGB3oSR6yBKVb8d2pFmbUEPSenyN/hGrJJKFPqqmCO9jhzlY
24
+ 8ho98JIewpJitn3DMA0GCSqGSIb3DQEBBQUAA4IBAQCFvlpydHAKq6pEgwaG8nNR
25
+ JP21BB4467hKYRPHO4vQW+zA1ezZdFak4Ie71hGrxQXmjHBWDk6rMcC+SfgxKL+q
26
+ 1rOpOHgG08uq3RZgAi5tBoXSWid8+9Ii3aJc/9g2OF2ZELmEjvOueGBFkP57c8ju
27
+ 1EztgTx/sIwPTCMntncnw/83prQqO4G5S/cCguOqGQ9NQlXUczRJzrfDorGVAD0T
28
+ 9xjevPGDZ+8y8wc8/mXBPK1pTaBh2oi8947HaTq8EadxezFs2Je+oSnMbygfo/a7
29
+ 0rbAHpJPtzql3a4+gjK54qkJUWSUjWuLMHFIHhMt1laowNJUio6ASGx8tfzgLLnZ
30
30
  -----END CERTIFICATE-----
31
- date: 2017-05-16 00:00:00.000000000 Z
31
+ date: 2017-07-19 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
@@ -165,8 +165,10 @@ files:
165
165
  - lib/muflax/kernel.rb
166
166
  - lib/muflax/library.rb
167
167
  - lib/muflax/objects.rb
168
+ - lib/muflax/panes.rb
168
169
  - lib/muflax/regex.rb
169
170
  - lib/muflax/string.rb
171
+ - lib/muflax/table.rb
170
172
  - lib/muflax/value.rb
171
173
  - muflax.gemspec
172
174
  homepage: http://github.com/muflax/ruby-muflax
metadata.gz.sig CHANGED
Binary file