youplot 0.4.3 → 0.4.5

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
  SHA256:
3
- metadata.gz: 5b3b1cbdabc0a74b4010d13fa59fe9724ac9c07783414a7a7584f8cab27b49ec
4
- data.tar.gz: f5cf98b592a248c4d74e06078d97050e85c892e94c0dd78ec17e92f6bdc856d0
3
+ metadata.gz: 725b5bffb6d597af728d9b57aedea75dbdf62182ab5c211c4ecdca35b686cb69
4
+ data.tar.gz: 7eb1d48b2ba900f9955b0cb257f95d79646101598b86d841951b3271b55e0d2b
5
5
  SHA512:
6
- metadata.gz: aebe50c600b66e9cb8e3a64da3ddafff70472f495d51b812987cc835017ca19fd1347fbe2ee88fac66e111837ffef59bf6c271f2f6515ae7e60a526050ded5b3
7
- data.tar.gz: b37e2a5a2d8eb33700690d28b6e6f5851fbefb0e88ae10bcb6d9f65f06f966c31b81c7587135c6d296bde0caefbc81239046ec06535cefa9329f2ac6d8a8788f
6
+ metadata.gz: 0ead7ed4edd2948b03f14b77256b03aaaef25f69795c61483b1440c2f6572a29b99d90336a0852e56f5f1c1331d8a9ae47bac421e2c444c282e1814658bd464e
7
+ data.tar.gz: e76b86a9c7ef5df17cc97e1f5b5c860d82c7d7650b6606d687d26ff24664032a52053f3c00bdbd8d072d8b95ce4ab2506f4119ae7ccf75791fcd4e9bd1838d29
data/README.md CHANGED
@@ -211,6 +211,14 @@ The following sub-commands are available.
211
211
 
212
212
  * Not yet supported.
213
213
 
214
+ ### YouPlot Configuration (youplotrc)
215
+
216
+ You can specify default options in a configuration file in YAML format. For more information, enter the following command.
217
+
218
+ ```
219
+ uplot --config
220
+ ```
221
+
214
222
  ## Tools that are useful to use with YouPlot
215
223
 
216
224
  * [csvtk](https://github.com/shenwei356/csvtk)
@@ -241,6 +249,10 @@ bundle exec rake install # Installation from source code
241
249
  bundle exec exe/uplot # Run youplot (Try out the edited code)
242
250
  ```
243
251
 
252
+ Do you need commit rights to my repository?
253
+ Do you want to get admin rights and take over the project?
254
+ If so, please feel free to contact us.
255
+
244
256
  ### Acknowledgements
245
257
 
246
258
  * [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation
@@ -63,9 +63,15 @@ module YouPlot
63
63
  # normal mode
64
64
  else
65
65
  # Sometimes the input file does not end with a newline code.
66
- while (input = Kernel.gets(nil))
66
+ begin
67
+ begin
68
+ input = Kernel.gets(nil)
69
+ rescue Errno::ENOENT => e
70
+ warn e.message
71
+ next
72
+ end
67
73
  main(input)
68
- end
74
+ end until input
69
75
  end
70
76
  end
71
77
 
@@ -135,7 +141,12 @@ module YouPlot
135
141
  rescue CSV::MalformedCSVError => e
136
142
  warn 'Failed to parse the text. '
137
143
  warn 'Please try to set the correct character encoding with --encoding option.'
138
- raise e
144
+ warn e.backtrace.grep(/youplot/).first
145
+ exit 1
146
+ rescue ArgumentError => e
147
+ warn 'Failed to parse the text. '
148
+ warn e.backtrace.grep(/youplot/).first
149
+ exit 1
139
150
  end
140
151
 
141
152
  data
@@ -149,9 +160,9 @@ module YouPlot
149
160
  @backend.barplot(data, params, count: true, reverse: options[:reverse])
150
161
  when :hist, :histogram
151
162
  @backend.histogram(data, params)
152
- when :line, :lineplot
163
+ when :line, :lineplot, :l
153
164
  @backend.line(data, params, options[:fmt])
154
- when :lines, :lineplots
165
+ when :lines, :lineplots, :ls
155
166
  @backend.lines(data, params, options[:fmt])
156
167
  when :scatter, :s
157
168
  @backend.scatter(data, params, options[:fmt])
@@ -9,7 +9,8 @@ module YouPlot
9
9
  class Error < StandardError; end
10
10
 
11
11
  attr_reader :command, :options, :params,
12
- :main_parser, :sub_parser
12
+ :main_parser, :sub_parser,
13
+ :config_file, :config
13
14
 
14
15
  def initialize
15
16
  @command = nil
@@ -30,6 +31,61 @@ module YouPlot
30
31
  @params = Parameters.new
31
32
  end
32
33
 
34
+ def apply_config_file
35
+ return if !config_file && find_config_file.nil?
36
+
37
+ read_config_file
38
+ configure
39
+ end
40
+
41
+ def config_file_candidate_paths
42
+ # keep the order of the paths
43
+ paths = []
44
+ paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
45
+ paths << '.youplot.yml'
46
+ paths << '.youplotrc'
47
+ if ENV['HOME']
48
+ paths << File.join(ENV['HOME'], '.youplotrc')
49
+ paths << File.join(ENV['HOME'], '.youplot.yml')
50
+ paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplotrc')
51
+ paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplot.yml')
52
+ end
53
+ paths
54
+ end
55
+
56
+ def find_config_file
57
+ config_file_candidate_paths.each do |file|
58
+ path = File.expand_path(file)
59
+ next unless File.exist?(path)
60
+
61
+ @config_file = path
62
+ ENV['MYYOUPLOTRC'] = path
63
+ return @config_file
64
+ end
65
+ nil
66
+ end
67
+
68
+ def read_config_file
69
+ require 'yaml'
70
+ @config = YAML.load_file(config_file)
71
+ end
72
+
73
+ def configure
74
+ option_members = @options.members
75
+ param_members = @params.members
76
+ # It would be more useful to be able to configure by plot type
77
+ config.each do |k, v|
78
+ k = k.to_sym
79
+ if option_members.include?(k)
80
+ @options[k] ||= v
81
+ elsif param_members.include?(k)
82
+ @params[k] ||= v
83
+ else
84
+ raise Error, "Unknown option/param in config file: #{k}"
85
+ end
86
+ end
87
+ end
88
+
33
89
  def create_base_parser
34
90
  OptionParser.new do |parser|
35
91
  parser.program_name = 'YouPlot'
@@ -104,6 +160,9 @@ module YouPlot
104
160
  puts parser.help
105
161
  exit if YouPlot.run_as_executable?
106
162
  end
163
+ parser.on('--config FILE', 'specify a config file') do |v|
164
+ @config_file = v
165
+ end
107
166
  parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
108
167
  options[:debug] = v
109
168
  end
@@ -135,6 +194,7 @@ module YouPlot
135
194
  colors color show the list of available colors
136
195
 
137
196
  General options:
197
+ --config print config file info
138
198
  --help print command specific help menu
139
199
  --version print the version of YouPlot
140
200
  MSG
@@ -142,10 +202,36 @@ module YouPlot
142
202
  # Help for the main parser is simple.
143
203
  # Simply show the banner above.
144
204
  main_parser.on('--help', 'print sub-command help menu') do
145
- puts main_parser.banner
146
- puts
147
- exit if YouPlot.run_as_executable?
205
+ show_main_help
148
206
  end
207
+
208
+ main_parser.on('--config', 'show config file info') do
209
+ show_config_info
210
+ end
211
+ end
212
+
213
+ def show_main_help(out = $stdout)
214
+ out.puts main_parser.banner
215
+ out.puts
216
+ exit if YouPlot.run_as_executable?
217
+ end
218
+
219
+ def show_config_info
220
+ if ENV['MYYOUPLOTRC']
221
+ puts "config file : #{ENV['MYYOUPLOTRC']}"
222
+ puts config.inspect
223
+ else
224
+ puts <<~EOS
225
+ Configuration file not found.
226
+ It should be a YAML file, like this example:
227
+ width : 40
228
+ height : 20
229
+ By default, YouPlot will look for the configuration file in these locations:
230
+ #{config_file_candidate_paths.map { |s| ' ' + s }.join("\n")}
231
+ If you have the file elsewhere, you can specify its location with the `MYYOUPLOTRC` environment variable.
232
+ EOS
233
+ end
234
+ exit if YouPlot.run_as_executable?
149
235
  end
150
236
 
151
237
  def sub_parser_add_symbol
@@ -215,10 +301,13 @@ module YouPlot
215
301
  case command
216
302
 
217
303
  # If you type only `uplot` in the terminal.
304
+ # Output help to standard error output.
218
305
  when nil
219
- warn main_parser.banner
220
- warn "\n"
221
- exit 1 if YouPlot.run_as_executable?
306
+ show_main_help($stderr)
307
+
308
+ # Output help to standard output.
309
+ when :help
310
+ show_main_help
222
311
 
223
312
  when :barplot, :bar
224
313
  sub_parser_add_symbol
@@ -241,14 +330,14 @@ module YouPlot
241
330
  params.nbins = v
242
331
  end
243
332
 
244
- when :lineplot, :line
333
+ when :lineplot, :line, :l
245
334
  sub_parser_add_canvas
246
335
  sub_parser_add_grid
247
336
  sub_parser_add_fmt_yx
248
337
  sub_parser_add_ylim
249
338
  sub_parser_add_xlim
250
339
 
251
- when :lineplots, :lines
340
+ when :lineplots, :lines, :ls
252
341
  sub_parser_add_canvas
253
342
  sub_parser_add_grid
254
343
  sub_parser_add_fmt_xyxy
@@ -277,14 +366,19 @@ module YouPlot
277
366
  options[:color_names] = v
278
367
  end
279
368
 
369
+ # Currently it simply displays the configuration file,
370
+ # but in the future this may be changed to open a text editor like Vim
371
+ # to edit the configuration file.
372
+ when :config
373
+ show_config_info
374
+
280
375
  else
281
- error_message = "uplot: unrecognized command '#{command}'"
282
- if YouPlot.run_as_executable?
283
- warn error_message
284
- exit 1
285
- else
286
- raise Error, error_message
287
- end
376
+ error_message = "YouPlot: unrecognized command '#{command}'"
377
+ raise Error, error_message unless YouPlot.run_as_executable?
378
+
379
+ warn error_message
380
+ exit 1
381
+
288
382
  end
289
383
  end
290
384
 
@@ -292,7 +386,7 @@ module YouPlot
292
386
  begin
293
387
  create_main_parser.order!(argv)
294
388
  rescue OptionParser::ParseError => e
295
- warn "uplot: #{e.message}"
389
+ warn "YouPlot: #{e.message}"
296
390
  exit 1 if YouPlot.run_as_executable?
297
391
  end
298
392
 
@@ -301,7 +395,14 @@ module YouPlot
301
395
  begin
302
396
  create_sub_parser&.parse!(argv)
303
397
  rescue OptionParser::ParseError => e
304
- warn "uplot: #{e.message}"
398
+ warn "YouPlot: #{e.message}"
399
+ exit 1 if YouPlot.run_as_executable?
400
+ end
401
+
402
+ begin
403
+ apply_config_file
404
+ rescue StandardError => e
405
+ warn "YouPlot: #{e.message}"
305
406
  exit 1 if YouPlot.run_as_executable?
306
407
  end
307
408
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouPlot
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-19 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_plot
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.2.26
68
+ rubygems_version: 3.4.1
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: A command line tool for Unicode Plotting