refined-refinements 0.0.2.3 → 0.0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/refined-refinements/cached_http.rb +2 -0
- data/lib/refined-refinements/cli/commander.rb +8 -6
- data/lib/refined-refinements/cli/prompt.rb +11 -9
- data/lib/refined-refinements/collection.rb +6 -6
- data/lib/refined-refinements/colours.rb +7 -3
- data/lib/refined-refinements/curses/app.rb +14 -12
- data/lib/refined-refinements/curses/colours.rb +3 -1
- data/lib/refined-refinements/curses/commander.rb +3 -1
- data/lib/refined-refinements/date.rb +3 -1
- data/lib/refined-refinements/homepath.rb +7 -5
- data/lib/refined-refinements/hour.rb +5 -3
- data/lib/refined-refinements/matching.rb +2 -0
- data/lib/refined-refinements/string.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 547988a8cf6bef7cd70cdc4ac0f4dea1a943f1ef4471be71619042f351809050
|
4
|
+
data.tar.gz: 95fe3fae78320daa206d3d929ec05a8a737431a5c687b2c30ef80b3c6d4cdc7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d0d126efd64be8b2f9e48495088a28916a20f52b1c842e495aaa741f6c387f6092009afd017624c2af75b8f51cd7a7f8e064384de2d5734ef034cf3a2323116
|
7
|
+
data.tar.gz: c5857d2f22d070ee44b2a41fe6dd058671967c5d4185c3baea0ba8960bfbe46406d961b943856544d444af4b218e91cf798818eb7f4292300392a228f736414c
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'refined-refinements/string'
|
2
4
|
require 'refined-refinements/colours'
|
3
5
|
|
@@ -14,18 +16,18 @@ module RR
|
|
14
16
|
end
|
15
17
|
|
16
18
|
def help_template(program_name)
|
17
|
-
|
18
|
-
<red.bold>:: #{program_name} ::</red.bold>
|
19
|
+
<<~EOF
|
20
|
+
<red.bold>:: #{program_name} ::</red.bold>
|
19
21
|
|
20
|
-
<cyan.bold>Commands</cyan.bold>
|
22
|
+
<cyan.bold>Commands</cyan.bold>
|
21
23
|
EOF
|
22
24
|
end
|
23
25
|
|
24
26
|
def help
|
25
|
-
self.commands.reduce(self.help_template)
|
27
|
+
self.commands.reduce(self.help_template) { |buffer, (command_name, command_class)|
|
26
28
|
command_help = command_class.help && command_class.help.split("\n").map { |line| line.sub(/^ {4}/, '') }.join("\n")
|
27
29
|
command_class.help ? [buffer, command_help].join("\n") : buffer
|
28
|
-
|
30
|
+
}.colourise
|
29
31
|
end
|
30
32
|
|
31
33
|
def commands
|
@@ -46,7 +48,7 @@ module RR
|
|
46
48
|
class << self
|
47
49
|
attr_accessor :help
|
48
50
|
def main_command
|
49
|
-
File.basename($
|
51
|
+
File.basename($PROGRAM_NAME)
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# def prompt_type
|
2
4
|
# @prompt.prompt(:type, 'Type', options: Expense::TYPES) do
|
3
5
|
# clean_value do |raw_value|
|
@@ -23,7 +25,7 @@ module RR
|
|
23
25
|
def validate_raw_value(*regexps, allow_empty: nil)
|
24
26
|
@callbacks[:validate_raw_value] = Proc.new do |raw_value|
|
25
27
|
unless (allow_empty && raw_value.empty?) || regexps.any? { |regexp| raw_value.match(regexp) }
|
26
|
-
raise InvalidResponse
|
28
|
+
raise InvalidResponse, "Doesn't match any of the regexps."
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -41,14 +43,14 @@ module RR
|
|
41
43
|
clean_value = @callbacks[:get_clean_value].call(raw_value)
|
42
44
|
|
43
45
|
unless @callbacks[:validate_clean_value].call(clean_value)
|
44
|
-
raise InvalidResponse
|
46
|
+
raise InvalidResponse, "validate_clean_value failed"
|
45
47
|
end
|
46
48
|
|
47
49
|
clean_value
|
48
50
|
end
|
49
51
|
|
50
52
|
def self_or_retrieve_by_index(list, raw_value, default_value = nil)
|
51
|
-
if
|
53
|
+
if /^\d+$/.match?(raw_value)
|
52
54
|
list[raw_value.to_i - 1]
|
53
55
|
elsif raw_value.empty?
|
54
56
|
default_value
|
@@ -58,19 +60,19 @@ module RR
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def retrieve_by_index_or_self_if_on_the_list(list, raw_value, default_value = nil)
|
61
|
-
if
|
63
|
+
if /^\d+$/.match?(raw_value)
|
62
64
|
list[raw_value.to_i - 1]
|
63
65
|
elsif list.include?(raw_value)
|
64
66
|
raw_value
|
65
67
|
elsif raw_value.empty? && default_value
|
66
68
|
default_value
|
67
69
|
else
|
68
|
-
raise InvalidResponse
|
70
|
+
raise InvalidResponse, raw_value
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
def convert_money_to_cents(raw_value)
|
73
|
-
if
|
75
|
+
if /\./.match?(raw_value)
|
74
76
|
raw_value.delete('.').to_i
|
75
77
|
else
|
76
78
|
"#{raw_value}00".to_i
|
@@ -98,7 +100,7 @@ module RR
|
|
98
100
|
help = help(**options)
|
99
101
|
prompt = "<bold>#{prompt_text}</bold>#{" (#{help})" if help}: ".colourise
|
100
102
|
@data[key] = answer.run(@block.call(prompt))
|
101
|
-
raise InvalidResponse
|
103
|
+
raise InvalidResponse if @data[key].nil? && options[:required]
|
102
104
|
@data[key]
|
103
105
|
rescue InvalidResponse => error
|
104
106
|
puts "<red>Invalid response</red> (#{error.message}), try again.".colourise
|
@@ -113,7 +115,7 @@ module RR
|
|
113
115
|
# TODO: If it evals as nil, shall we still add it to the data?
|
114
116
|
def help(help: nil, options: Array.new, default: nil, **rest)
|
115
117
|
if help then help
|
116
|
-
elsif help.nil? && !
|
118
|
+
elsif help.nil? && !options.empty?
|
117
119
|
options = options.map.with_index { |key, index|
|
118
120
|
if default == key
|
119
121
|
"<green.bold>#{key}</green.bold> <bright_black>default</bright_black>"
|
@@ -122,7 +124,7 @@ module RR
|
|
122
124
|
end
|
123
125
|
}.join(' ').colourise
|
124
126
|
# default ? "#{options}; defaults to #{default}" : options
|
125
|
-
|
127
|
+
end
|
126
128
|
end
|
127
129
|
|
128
130
|
def set_completion_proc(proc, character = ' ', &block)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'forwardable'
|
3
5
|
require 'pathname'
|
@@ -22,11 +24,9 @@ module RR
|
|
22
24
|
|
23
25
|
def items(&block)
|
24
26
|
@items ||= self.load_raw_collection.map do |data|
|
25
|
-
begin
|
26
27
|
block.call(data)
|
27
|
-
|
28
|
+
rescue StandardError => error
|
28
29
|
abort "Loading item #{data.inspect} failed: #{error.message}.\n\n#{error.backtrace}"
|
29
|
-
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -48,7 +48,7 @@ module RR
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def filter_out(filter_name, &block)
|
51
|
-
@activity_filters[filter_name] = Proc.new { |item| !
|
51
|
+
@activity_filters[filter_name] = Proc.new { |item| !block.call(item) } if block
|
52
52
|
self
|
53
53
|
end
|
54
54
|
|
@@ -57,7 +57,7 @@ module RR
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def has_filter?(filter_name)
|
60
|
-
@activity_filters.
|
60
|
+
@activity_filters.key?(filter_name)
|
61
61
|
end
|
62
62
|
|
63
63
|
def filtered_out_items(filter_name)
|
@@ -99,7 +99,7 @@ module RR
|
|
99
99
|
|
100
100
|
def save_to(path)
|
101
101
|
updated_data = self.serialise
|
102
|
-
if
|
102
|
+
if !File.exist?(path) || File.read(path) != updated_data
|
103
103
|
path.open('w') do |file|
|
104
104
|
file.write(updated_data)
|
105
105
|
end
|
@@ -48,7 +48,7 @@ module RR
|
|
48
48
|
|
49
49
|
# block.call(result, Array.new, options) #unless was_called
|
50
50
|
|
51
|
-
result.match(RR::ColourExts::REGEXP) ? result.colourise(options.merge(recursed: true)) : result #block.call(result, [options[:bold] ? :bold : nil].compact, options)
|
51
|
+
result.match?(RR::ColourExts::REGEXP) ? result.colourise(options.merge(recursed: true)) : result #block.call(result, [options[:bold] ? :bold : nil].compact, options)
|
52
52
|
end
|
53
53
|
|
54
54
|
# FIXME: bold true doesn't do anything for the text that is not wrapped
|
@@ -56,7 +56,7 @@ module RR
|
|
56
56
|
def colourise(options = Hash.new)
|
57
57
|
colours = RR::ColourExts.colours
|
58
58
|
|
59
|
-
self.parse_colours(options) do |inner_text, methods, options|
|
59
|
+
self.dup.parse_colours(options) do |inner_text, methods, options|
|
60
60
|
methods.reduce(inner_text) do |result, method|
|
61
61
|
# (print ' '; p [:r, result, method]) if result.match(/(<\/[^>]+>)/) ####
|
62
62
|
result.gsub!(/(<\/[^>]+>)/, "#{colours.send(method)}\\1")
|
@@ -127,7 +127,7 @@ module RR
|
|
127
127
|
|
128
128
|
def titlecase
|
129
129
|
@template_string.sub(/>(#{self.remove_tags[0]})/) do |match|
|
130
|
-
">#{
|
130
|
+
">#{Regexp.last_match(1).upcase}"
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -178,3 +178,7 @@ end
|
|
178
178
|
# puts s1.colourise, ''
|
179
179
|
# puts s2.colourise(bold: true), ''
|
180
180
|
# puts s3.colourise, ''
|
181
|
+
#
|
182
|
+
# OR DIRECT (without .colourise):
|
183
|
+
# using RR::ColouredTerminal
|
184
|
+
# puts "<green>Test</green>"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'curses'
|
2
4
|
require 'refined-refinements/curses/colours'
|
3
5
|
require 'refined-refinements/curses/commander'
|
@@ -45,7 +47,7 @@ class App
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def destroy
|
48
|
-
raise QuitAppError
|
50
|
+
raise QuitAppError
|
49
51
|
end
|
50
52
|
|
51
53
|
def set_up
|
@@ -68,7 +70,7 @@ class App
|
|
68
70
|
|
69
71
|
until (char = window.getch) == 13 || @quit
|
70
72
|
begin
|
71
|
-
if (190..200).
|
73
|
+
if (190..200).cover?(char) # Reading unicode.
|
72
74
|
char_buffer = [char]
|
73
75
|
else
|
74
76
|
char_buffer << char
|
@@ -77,7 +79,7 @@ class App
|
|
77
79
|
end
|
78
80
|
rescue KeyboardInterrupt => interrupt
|
79
81
|
begin
|
80
|
-
unknown_key_handler
|
82
|
+
unknown_key_handler&.call(interrupt)
|
81
83
|
rescue QuitError
|
82
84
|
@quit = true
|
83
85
|
end
|
@@ -111,7 +113,7 @@ class App
|
|
111
113
|
# window.write([:input, buffer].inspect + "\n")
|
112
114
|
# window.refresh
|
113
115
|
# sleep 2.5
|
114
|
-
|
116
|
+
buffer
|
115
117
|
end
|
116
118
|
|
117
119
|
def commander
|
@@ -142,11 +144,11 @@ class App
|
|
142
144
|
cursor = buffer.length
|
143
145
|
when 11 # Ctrl+k.
|
144
146
|
# yank_register = buffer[cursor..-1] # Ctrl+y suspends it currently.
|
145
|
-
if cursor == 0
|
146
|
-
|
147
|
+
buffer = if cursor == 0
|
148
|
+
''
|
147
149
|
else
|
148
|
-
buffer
|
149
|
-
|
150
|
+
buffer[0..(cursor - 1)]
|
151
|
+
end
|
150
152
|
when 127 # Backspace.
|
151
153
|
unless buffer.empty?
|
152
154
|
buffer = buffer[0..-2]; cursor -= 1
|
@@ -160,11 +162,11 @@ class App
|
|
160
162
|
@history_index ||= @history.length - 1
|
161
163
|
|
162
164
|
window.setpos(window.cury + 1, 0)
|
163
|
-
window.write("DBG: #{@history_index}, #{(0..@history.length).
|
165
|
+
window.write("DBG: #{@history_index}, #{(0..@history.length).cover?(@history_index)}")
|
164
166
|
window.setpos(window.cury - 1, cursor + original_x)
|
165
167
|
window.refresh
|
166
168
|
|
167
|
-
if (0..@history.length).
|
169
|
+
if (0..@history.length).cover?(@history_index)
|
168
170
|
@buffer_before_calling_history = buffer
|
169
171
|
buffer = @history[@history_index - 1]
|
170
172
|
else
|
@@ -188,9 +190,9 @@ class App
|
|
188
190
|
# window.addch(char)
|
189
191
|
buffer.insert(cursor, char); cursor += 1
|
190
192
|
else
|
191
|
-
raise KeyboardInterrupt
|
193
|
+
raise KeyboardInterrupt, char # TODO: Just return it, it's not really an error.
|
192
194
|
end
|
193
195
|
|
194
|
-
|
196
|
+
[buffer, cursor]
|
195
197
|
end
|
196
198
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'refined-refinements/colours'
|
2
4
|
|
3
5
|
module RR
|
@@ -28,7 +30,7 @@ module RR
|
|
28
30
|
attributes << (Curses.color_pair(fg_colour) | Curses::COLOR_WHITE)
|
29
31
|
end
|
30
32
|
|
31
|
-
if !
|
33
|
+
if !attributes.empty? && !colours.include?(:clear)
|
32
34
|
self.multi_attron(*attributes) do
|
33
35
|
self.addstr(chunk)
|
34
36
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'refined-refinements/string'
|
2
4
|
|
3
5
|
class QuitError < StandardError
|
@@ -92,7 +94,7 @@ class Commander
|
|
92
94
|
def available_commands_help
|
93
95
|
commands_help = @commands.reduce(Array.new) { |buffer, command|
|
94
96
|
keys_text = command.keys.join_with_and('or') { |word| "<yellow.bold>#{word}</yellow.bold>" }
|
95
|
-
buffer <<
|
97
|
+
buffer << keys_text.to_s
|
96
98
|
}.join_with_and
|
97
99
|
|
98
100
|
"<green>Available commands</green> are #{commands_help}. Press <yellow>?</yellow> for <red>help</red>."
|
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RR
|
2
4
|
class Homepath
|
3
5
|
def initialize(path)
|
4
|
-
if path.start_with?('~')
|
5
|
-
|
6
|
+
@path = if path.start_with?('~')
|
7
|
+
File.expand_path(path)
|
6
8
|
else
|
7
|
-
|
8
|
-
|
9
|
+
path # Can be relative.
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
def to_s
|
12
14
|
@path.sub(ENV['HOME'], '~')
|
13
15
|
end
|
14
|
-
|
16
|
+
alias inspect to_s
|
15
17
|
|
16
18
|
def expand
|
17
19
|
@path
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Hour
|
2
4
|
def self.parse(string)
|
3
5
|
hours, minutes = string.split(':')
|
@@ -42,7 +44,7 @@ class Hour
|
|
42
44
|
elsif hour_or_minutes.is_a?(Integer)
|
43
45
|
self.class.new(0, @minutes.send(method_name, hour_or_minutes))
|
44
46
|
else
|
45
|
-
raise TypeError
|
47
|
+
raise TypeError, "Hour or Integer (for minutes) expected, got #{hour_or_minutes.class}."
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -71,7 +73,7 @@ class Hour
|
|
71
73
|
elsif anotherHour.is_a?(Time)
|
72
74
|
self.send(method_name, Hour.now)
|
73
75
|
else
|
74
|
-
raise TypeError
|
76
|
+
raise TypeError, "#{self.class}##{method_name} expects #{self.class} or Time object."
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
@@ -79,7 +81,7 @@ class Hour
|
|
79
81
|
def inspect
|
80
82
|
"#{self.hours}:#{format('%02d', self.minutes_over_the_hour)}"
|
81
83
|
end
|
82
|
-
|
84
|
+
alias to_s inspect
|
83
85
|
|
84
86
|
def to_time(today = Time.now)
|
85
87
|
Time.new(today.year, today.month, today.day, self.hours, self.minutes_over_the_hour)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refined-refinements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James C Russell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "."
|
14
14
|
email: james@101ideas.cz
|