everyday-cli-utils 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7897a11ac454ad40fbac503cbee4929c032052f2
4
- data.tar.gz: 65d659f085bef676655c2c4c208c67cb63b8d55d
3
+ metadata.gz: 22981760ec07c6812935693a6ee28d02441e6bb1
4
+ data.tar.gz: f888f94e58a15d8bb2bfdb5ea04af6903dfe43b8
5
5
  SHA512:
6
- metadata.gz: 86d3c40d13be8545c2542fc76fb83179ead683b6d5524afb0c337c7c9d221a1b3bf021d7f09552aa665db831ba92c2b631c1028858072b6176e8e1198b0c3194
7
- data.tar.gz: 3b574b15dc95951a68f5241c7cf6aec251c514656f068589f47dce4e8b37f8325477e4ed0a2490e88bb82f082ec387f1696ea1cb18e5b99bc08b32b428bb9282
6
+ metadata.gz: 86fd47cad9ba83012945384c904870a346c374deda57a085221b1244cde553da9832473b66962aaa6c858549668f94937f1040149aa0ad8ae6ea6b591df1905f
7
+ data.tar.gz: 01344d8e1f8bbef5f4a4eb7d8da778474344dcdbfdbf8b948500b63c56e3cc991aeea1b6a7de48dca02dbc1f8d38bbad367d8b0f3e091b4938a54786e3d0a60b
@@ -23,6 +23,4 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'simplecov', '>= 0.8.2'
24
24
  spec.add_development_dependency 'coveralls', '>= 0.7.0'
25
25
  spec.add_development_dependency 'rspec'
26
-
27
- spec.add_dependency 'curses'
28
26
  end
@@ -1,40 +1,40 @@
1
- module EverydayCliUtils
2
- module CursesUtils
3
- COLOR_TO_CURSES = {
4
- :black => Curses::COLOR_BLACK,
5
- :red => Curses::COLOR_RED,
6
- :green => Curses::COLOR_GREEN,
7
- :yellow => Curses::COLOR_YELLOW,
8
- :blue => Curses::COLOR_BLUE,
9
- :purple => Curses::COLOR_MAGENTA,
10
- :cyan => Curses::COLOR_CYAN,
11
- :white => Curses::COLOR_WHITE,
12
- :none => -1,
13
- }
14
-
15
- def find_color(bgcolor, fgcolor)
16
- @colors.find_index { |v| v[0] == (fgcolor || :none) && v[1] == (bgcolor || :none) }
17
- end
18
-
19
- def add_color(bgcolor, fgcolor)
20
- Curses::init_pair(@colors.count + 1, COLOR_TO_CURSES[fgcolor || :none], COLOR_TO_CURSES[bgcolor || :none])
21
- ind = @colors.count + 1
22
- @colors << [fgcolor || :none, bgcolor || :none]
23
- ind
24
- end
25
-
26
-
27
- private
28
- def handle_color(fgcolor, bgcolor)
29
- return 0 if (fgcolor.nil? || fgcolor == :none) && (bgcolor.nil? || bgcolor == :none)
30
- ind = find_color(bgcolor, fgcolor)
31
- ind = ind.nil? ? add_color(bgcolor, fgcolor) : ind + 1
32
- Curses::color_pair(ind)
33
- end
34
-
35
- def get_format(str)
36
- bold, underline, fgcolor, bgcolor = Format::parse_format(str)
37
- (bold ? Curses::A_BOLD : 0) | (underline ? Curses::A_UNDERLINE : 0) | handle_color(fgcolor, bgcolor)
38
- end
39
- end
40
- end
1
+ #module EverydayCliUtils
2
+ # module CursesUtils
3
+ # COLOR_TO_CURSES = {
4
+ # :black => Curses::COLOR_BLACK,
5
+ # :red => Curses::COLOR_RED,
6
+ # :green => Curses::COLOR_GREEN,
7
+ # :yellow => Curses::COLOR_YELLOW,
8
+ # :blue => Curses::COLOR_BLUE,
9
+ # :purple => Curses::COLOR_MAGENTA,
10
+ # :cyan => Curses::COLOR_CYAN,
11
+ # :white => Curses::COLOR_WHITE,
12
+ # :none => -1,
13
+ # }
14
+ #
15
+ # def find_color(bgcolor, fgcolor)
16
+ # @colors.find_index { |v| v[0] == (fgcolor || :none) && v[1] == (bgcolor || :none) }
17
+ # end
18
+ #
19
+ # def add_color(bgcolor, fgcolor)
20
+ # Curses::init_pair(@colors.count + 1, COLOR_TO_CURSES[fgcolor || :none], COLOR_TO_CURSES[bgcolor || :none])
21
+ # ind = @colors.count + 1
22
+ # @colors << [fgcolor || :none, bgcolor || :none]
23
+ # ind
24
+ # end
25
+ #
26
+ #
27
+ # private
28
+ # def handle_color(fgcolor, bgcolor)
29
+ # return 0 if (fgcolor.nil? || fgcolor == :none) && (bgcolor.nil? || bgcolor == :none)
30
+ # ind = find_color(bgcolor, fgcolor)
31
+ # ind = ind.nil? ? add_color(bgcolor, fgcolor) : ind + 1
32
+ # Curses::color_pair(ind)
33
+ # end
34
+ #
35
+ # def get_format(str)
36
+ # bold, underline, fgcolor, bgcolor = Format::parse_format(str)
37
+ # (bold ? Curses::A_BOLD : 0) | (underline ? Curses::A_UNDERLINE : 0) | handle_color(fgcolor, bgcolor)
38
+ # end
39
+ # end
40
+ #end
@@ -1,199 +1,199 @@
1
- require 'curses'
2
- require_relative 'format'
3
- require_relative 'curses_utils'
4
-
5
- module EverydayCliUtils
6
- class MyCurses
7
- include CursesUtils
8
- #region External
9
- def initialize(use_curses, linesh, linesf)
10
- @use_curses = use_curses
11
- @linesh = linesh
12
- @linesf = linesf
13
- @colors = []
14
- @headers = []
15
- @bodies = []
16
- @footers = []
17
- @cur_l = 0
18
- @max_l = 0
19
- @ch = nil
20
- setup_curses(linesf, linesh) if @use_curses
21
- end
22
-
23
- def setup_curses(linesf, linesh)
24
- Curses::noecho
25
- Curses::init_screen
26
- @subpad_start = linesh
27
- update_subpad_size
28
- @padh = Curses::Pad.new(linesh, Curses::cols)
29
- @padb = Curses::Pad.new(Curses::lines - linesh - linesf, Curses::cols)
30
- @padf = Curses::Pad.new(linesf, Curses::cols)
31
- configure_curses
32
- end
33
-
34
- def configure_curses
35
- @padh.keypad(true)
36
- @padh.clear
37
- @padh.nodelay = true
38
- @padb.keypad(true)
39
- @padb.clear
40
- @padb.nodelay = true
41
- @padf.keypad(true)
42
- @padf.clear
43
- @padf.nodelay = true
44
- Curses::cbreak
45
- Curses::start_color
46
- Curses::use_default_colors
47
- end
48
-
49
- def clear
50
- @headers = []
51
- @bodies = []
52
- @footers = []
53
- end
54
-
55
- def myprints
56
- @use_curses ? print_curses : print_normal
57
- end
58
-
59
- def print_normal
60
- @headers.each { |v| puts v }
61
- @bodies.each { |v| puts v }
62
- @footers.each { |v| puts v }
63
- end
64
-
65
- def print_curses
66
- resize_curses
67
- myprint(@headers.join("\n"), @padh)
68
- myprint(@bodies.join("\n"), @padb)
69
- myprint(@footers.join("\n"), @padf)
70
- update_max_l
71
- @cur_l = [@cur_l, @max_l].min
72
- padh_refresh
73
- padb_refresh
74
- padf_refresh
75
- end
76
-
77
- def resize_curses
78
- @padh.resize(@headers.count, Curses::cols)
79
- @padb.resize(@bodies.count, Curses::cols)
80
- @padf.resize(@footers.count, Curses::cols)
81
- @padh.clear
82
- @padb.clear
83
- @padf.clear
84
- @padh.setpos(0, 0)
85
- @padb.setpos(0, 0)
86
- @padf.setpos(0, 0)
87
- end
88
-
89
- def read_ch
90
- @ch = @padf.getch
91
- end
92
-
93
- def clear_ch
94
- read_ch
95
- while @ch == 10 || @ch == Curses::Key::ENTER || @ch == Curses::Key::UP || @ch == Curses::Key::DOWN
96
- read_ch
97
- end
98
- end
99
-
100
- def scroll_iteration
101
- old_subpad_size = @subpad_size
102
- update_subpad_size
103
- update_max_l
104
- update_scroll(@subpad_size != old_subpad_size)
105
- sleep(0.05)
106
- read_ch
107
- end
108
-
109
- def header_live_append(str)
110
- @padh << str
111
- padh_refresh
112
- end
113
-
114
- def body_live_append(str)
115
- @padb << str
116
- padb_refresh
117
- end
118
-
119
- def footer_live_append(str)
120
- @padf << str
121
- padf_refresh
122
- end
123
-
124
- def dispose
125
- Curses::close_screen if @use_curses
126
- end
127
-
128
- #endregion
129
-
130
- #region Internal
131
- def myputs(text, pad)
132
- myprint("#{text}\n", pad)
133
- end
134
-
135
- def myprint(text, pad)
136
- if @use_curses
137
- if text.include?("\e")
138
- pieces = text.scan(/#{"\e"}\[(.+?)m([^#{"\e"}]+?)#{"\e"}\[0m|([^#{"\e"}]+)/)
139
- pieces.each { |v|
140
- if v[2].nil?
141
- pad.attron(get_format(v[0])) {
142
- pad << v[1]
143
- }
144
- else
145
- pad << v[2]
146
- end
147
- }
148
- else
149
- pad << text
150
- end
151
- else
152
- print text
153
- end
154
- end
155
-
156
- def update_max_l
157
- @max_l = [0, @bodies.count - @subpad_size].max
158
- end
159
-
160
- def update_subpad_size
161
- Curses::refresh
162
- @subpad_size = Curses::lines - @linesh - @linesf
163
- end
164
-
165
- def padh_refresh
166
- @padh.refresh(0, 0, 0, 0, @subpad_start - 1, Curses::cols - 1)
167
- end
168
-
169
- def padb_refresh
170
- @padb.refresh(@cur_l, 0, @subpad_start, 0, @subpad_start + @subpad_size - 1, Curses::cols - 1)
171
- end
172
-
173
- def padf_refresh
174
- @padf.refresh(0, 0, @subpad_start + [@subpad_size, @bodies.count].min, 0, @subpad_start + [@subpad_size, @bodies.count].min + @footers.count, Curses::cols - 1)
175
- end
176
-
177
- def update_scroll(force_refresh = false)
178
- if @ch == Curses::Key::UP
179
- @cur_l = [0, @cur_l - 1].max
180
- elsif @ch == Curses::Key::DOWN
181
- @cur_l = [@max_l, @cur_l + 1].min
182
- end
183
- @cur_l = [@cur_l, @max_l].min
184
- if @ch == Curses::Key::UP || @ch == Curses::Key::DOWN || force_refresh
185
- Curses::refresh
186
- padh_refresh
187
- padb_refresh
188
- padf_refresh
189
- end
190
- @cur_l
191
- end
192
-
193
- #endregion
194
-
195
- attr_reader :ch
196
- attr_accessor :bodies, :headers, :footers
197
- private :myputs, :myprint, :update_max_l, :update_subpad_size, :padh_refresh, :padb_refresh, :padf_refresh, :update_scroll
198
- end
199
- end
1
+ #require 'curses'
2
+ #require_relative 'format'
3
+ #require_relative 'curses_utils'
4
+ #
5
+ #module EverydayCliUtils
6
+ # class MyCurses
7
+ # include CursesUtils
8
+ # #region External
9
+ # def initialize(use_curses, linesh, linesf)
10
+ # @use_curses = use_curses
11
+ # @linesh = linesh
12
+ # @linesf = linesf
13
+ # @colors = []
14
+ # @headers = []
15
+ # @bodies = []
16
+ # @footers = []
17
+ # @cur_l = 0
18
+ # @max_l = 0
19
+ # @ch = nil
20
+ # setup_curses(linesf, linesh) if @use_curses
21
+ # end
22
+ #
23
+ # def setup_curses(linesf, linesh)
24
+ # Curses::noecho
25
+ # Curses::init_screen
26
+ # @subpad_start = linesh
27
+ # update_subpad_size
28
+ # @padh = Curses::Pad.new(linesh, Curses::cols)
29
+ # @padb = Curses::Pad.new(Curses::lines - linesh - linesf, Curses::cols)
30
+ # @padf = Curses::Pad.new(linesf, Curses::cols)
31
+ # configure_curses
32
+ # end
33
+ #
34
+ # def configure_curses
35
+ # @padh.keypad(true)
36
+ # @padh.clear
37
+ # @padh.nodelay = true
38
+ # @padb.keypad(true)
39
+ # @padb.clear
40
+ # @padb.nodelay = true
41
+ # @padf.keypad(true)
42
+ # @padf.clear
43
+ # @padf.nodelay = true
44
+ # Curses::cbreak
45
+ # Curses::start_color
46
+ # Curses::use_default_colors
47
+ # end
48
+ #
49
+ # def clear
50
+ # @headers = []
51
+ # @bodies = []
52
+ # @footers = []
53
+ # end
54
+ #
55
+ # def myprints
56
+ # @use_curses ? print_curses : print_normal
57
+ # end
58
+ #
59
+ # def print_normal
60
+ # @headers.each { |v| puts v }
61
+ # @bodies.each { |v| puts v }
62
+ # @footers.each { |v| puts v }
63
+ # end
64
+ #
65
+ # def print_curses
66
+ # resize_curses
67
+ # myprint(@headers.join("\n"), @padh)
68
+ # myprint(@bodies.join("\n"), @padb)
69
+ # myprint(@footers.join("\n"), @padf)
70
+ # update_max_l
71
+ # @cur_l = [@cur_l, @max_l].min
72
+ # padh_refresh
73
+ # padb_refresh
74
+ # padf_refresh
75
+ # end
76
+ #
77
+ # def resize_curses
78
+ # @padh.resize(@headers.count, Curses::cols)
79
+ # @padb.resize(@bodies.count, Curses::cols)
80
+ # @padf.resize(@footers.count, Curses::cols)
81
+ # @padh.clear
82
+ # @padb.clear
83
+ # @padf.clear
84
+ # @padh.setpos(0, 0)
85
+ # @padb.setpos(0, 0)
86
+ # @padf.setpos(0, 0)
87
+ # end
88
+ #
89
+ # def read_ch
90
+ # @ch = @padf.getch
91
+ # end
92
+ #
93
+ # def clear_ch
94
+ # read_ch
95
+ # while @ch == 10 || @ch == Curses::Key::ENTER || @ch == Curses::Key::UP || @ch == Curses::Key::DOWN
96
+ # read_ch
97
+ # end
98
+ # end
99
+ #
100
+ # def scroll_iteration
101
+ # old_subpad_size = @subpad_size
102
+ # update_subpad_size
103
+ # update_max_l
104
+ # update_scroll(@subpad_size != old_subpad_size)
105
+ # sleep(0.05)
106
+ # read_ch
107
+ # end
108
+ #
109
+ # def header_live_append(str)
110
+ # @padh << str
111
+ # padh_refresh
112
+ # end
113
+ #
114
+ # def body_live_append(str)
115
+ # @padb << str
116
+ # padb_refresh
117
+ # end
118
+ #
119
+ # def footer_live_append(str)
120
+ # @padf << str
121
+ # padf_refresh
122
+ # end
123
+ #
124
+ # def dispose
125
+ # Curses::close_screen if @use_curses
126
+ # end
127
+ #
128
+ # #endregion
129
+ #
130
+ # #region Internal
131
+ # def myputs(text, pad)
132
+ # myprint("#{text}\n", pad)
133
+ # end
134
+ #
135
+ # def myprint(text, pad)
136
+ # if @use_curses
137
+ # if text.include?("\e")
138
+ # pieces = text.scan(/#{"\e"}\[(.+?)m([^#{"\e"}]+?)#{"\e"}\[0m|([^#{"\e"}]+)/)
139
+ # pieces.each { |v|
140
+ # if v[2].nil?
141
+ # pad.attron(get_format(v[0])) {
142
+ # pad << v[1]
143
+ # }
144
+ # else
145
+ # pad << v[2]
146
+ # end
147
+ # }
148
+ # else
149
+ # pad << text
150
+ # end
151
+ # else
152
+ # print text
153
+ # end
154
+ # end
155
+ #
156
+ # def update_max_l
157
+ # @max_l = [0, @bodies.count - @subpad_size].max
158
+ # end
159
+ #
160
+ # def update_subpad_size
161
+ # Curses::refresh
162
+ # @subpad_size = Curses::lines - @linesh - @linesf
163
+ # end
164
+ #
165
+ # def padh_refresh
166
+ # @padh.refresh(0, 0, 0, 0, @subpad_start - 1, Curses::cols - 1)
167
+ # end
168
+ #
169
+ # def padb_refresh
170
+ # @padb.refresh(@cur_l, 0, @subpad_start, 0, @subpad_start + @subpad_size - 1, Curses::cols - 1)
171
+ # end
172
+ #
173
+ # def padf_refresh
174
+ # @padf.refresh(0, 0, @subpad_start + [@subpad_size, @bodies.count].min, 0, @subpad_start + [@subpad_size, @bodies.count].min + @footers.count, Curses::cols - 1)
175
+ # end
176
+ #
177
+ # def update_scroll(force_refresh = false)
178
+ # if @ch == Curses::Key::UP
179
+ # @cur_l = [0, @cur_l - 1].max
180
+ # elsif @ch == Curses::Key::DOWN
181
+ # @cur_l = [@max_l, @cur_l + 1].min
182
+ # end
183
+ # @cur_l = [@cur_l, @max_l].min
184
+ # if @ch == Curses::Key::UP || @ch == Curses::Key::DOWN || force_refresh
185
+ # Curses::refresh
186
+ # padh_refresh
187
+ # padb_refresh
188
+ # padf_refresh
189
+ # end
190
+ # @cur_l
191
+ # end
192
+ #
193
+ # #endregion
194
+ #
195
+ # attr_reader :ch
196
+ # attr_accessor :bodies, :headers, :footers
197
+ # private :myputs, :myprint, :update_max_l, :update_subpad_size, :padh_refresh, :padb_refresh, :padf_refresh, :update_scroll
198
+ # end
199
+ #end
@@ -1,3 +1,3 @@
1
1
  module EverydayCliUtils
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'everyday-cli-utils/version'
2
2
 
3
3
  module EverydayCliUtils
4
- AVAILABLE_MODULES = [:ask, :format, :format_safe, :histogram, :histogram_safe, :kmeans, :kmeans_safe, :maputil, :maputil_safe, :mycurses, :option]
4
+ AVAILABLE_MODULES = [:ask, :format, :format_safe, :histogram, :histogram_safe, :kmeans, :kmeans_safe, :maputil, :maputil_safe, :option]
5
5
  MODULE_TO_RELATIVE = {
6
6
  ask: 'everyday-cli-utils/ask',
7
7
  format: 'everyday-cli-utils/format',
@@ -12,7 +12,6 @@ module EverydayCliUtils
12
12
  kmeans_safe: 'everyday-cli-utils/safe/kmeans',
13
13
  maputil: 'everyday-cli-utils/maputil',
14
14
  maputil_safe: 'everyday-cli-utils/safe/maputil',
15
- mycurses: 'everyday-cli-utils/mycurses',
16
15
  option: 'everyday-cli-utils/option'
17
16
  }
18
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everyday-cli-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-26 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: curses
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  description: A few CLI and general utilities. Includes a numbered-menu select loop
98
84
  utility, a ANSI formatting escape code handler, a text-based histogram maker, k-means
99
85
  and n-means (k-means with minimum optimal k) calculators, various collection utility