8 Commits

Author SHA1 Message Date
kojix2
19f05e57ac v0.4.4 2022-08-02 17:05:30 +09:00
kojix2
f11fd6babb Consistent variable names 2022-08-02 16:58:48 +09:00
kojix2
9d69c4322c Make configuration files available (#30) 2022-07-31 22:37:50 +09:00
kojix2
41c0d37a13 Friendly error messages 2022-05-25 16:24:13 +09:00
kojix2
a1dcc532ea Friendly error messages 2022-05-25 16:03:33 +09:00
kojix2
523700348c Create doc.yml 2022-03-24 18:47:41 +09:00
kojix2
e34ab2b097 Update README.md
Do you need commit rights to my repository?
Do you want to get admin rights and take over the project?
If so, please feel free to contact kojix2.
2022-02-13 13:05:13 +09:00
kojix2
f8fe010d27 Add Ruby3.1 to CI (#29) 2021-12-30 11:54:15 +09:00
6 changed files with 115 additions and 7 deletions

View File

@@ -6,8 +6,8 @@ jobs:
runs-on: ${{ matrix.os }}-latest runs-on: ${{ matrix.os }}-latest
strategy: strategy:
matrix: matrix:
os: ['ubuntu', 'macos'] os: [ 'ubuntu', 'macos' ]
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ] ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1' ]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1

23
.github/workflows/doc.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: doc
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Generate document
run: gem install -N yard && yard doc
- name: Publish Documentation on GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc

View File

@@ -241,6 +241,10 @@ bundle exec rake install # Installation from source code
bundle exec exe/uplot # Run youplot (Try out the edited code) bundle exec exe/uplot # Run youplot (Try out the edited code)
``` ```
Do you need commit rights to my repository?
Do you want to get admin rights and take over the project?
If so, please feel free to contact us.
### Acknowledgements ### Acknowledgements
* [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation * [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation

View File

@@ -40,6 +40,24 @@ module YouPlot
return return
end end
# config command
if @command == :config
if ENV['MYYOUPLOTRC']
puts "config file : #{ENV['MYYOUPLOTRC']}"
puts parser.config.inspect
else
puts <<~EOS
You don't have a config file. The default config file paths are:
./.youplot.yml, ./.youplotrc, ~/.youplot.yml, ~/.youplotrc
You can specify a config file with the environment variable MYYOUPLOTRC.
File format is YAML. For example:
width : 40
height : 20
EOS
end
return
end
# progressive mode # progressive mode
if options[:progressive] if options[:progressive]
stop = false stop = false
@@ -63,9 +81,15 @@ module YouPlot
# normal mode # normal mode
else else
# Sometimes the input file does not end with a newline code. # Sometimes the input file does not end with a newline code.
while (input = Kernel.gets(nil)) begin
begin
input = Kernel.gets(nil)
rescue Errno::ENOENT => e
warn e.message
next
end
main(input) main(input)
end end until input
end end
end end
@@ -135,7 +159,12 @@ module YouPlot
rescue CSV::MalformedCSVError => e rescue CSV::MalformedCSVError => e
warn 'Failed to parse the text. ' warn 'Failed to parse the text. '
warn 'Please try to set the correct character encoding with --encoding option.' warn 'Please try to set the correct character encoding with --encoding option.'
raise e warn e.backtrace.grep(/youplot/).first
exit 1
rescue ArgumentError => e
warn 'Failed to parse the text. '
warn e.backtrace.grep(/youplot/).first
exit 1
end end
data data

View File

@@ -9,7 +9,8 @@ module YouPlot
class Error < StandardError; end class Error < StandardError; end
attr_reader :command, :options, :params, attr_reader :command, :options, :params,
:main_parser, :sub_parser :main_parser, :sub_parser,
:config_file, :config
def initialize def initialize
@command = nil @command = nil
@@ -28,6 +29,55 @@ module YouPlot
) )
@params = Parameters.new @params = Parameters.new
if @config_file = find_config_file
ENV['MYYOUPLOTRC'] = @config_file
@config = read_config_file(config_file)
configure(config)
end
end
def candidate_paths
paths = []
paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
paths << '.youplot.yml'
paths << '.youplotrc'
paths << File.join(ENV['HOME'], '.youplotrc') if ENV['HOME']
paths << File.join(ENV['HOME'], '.youplot.yml') if ENV['HOME']
paths
end
def find_config_file
config_file_path = nil
candidate_paths.each do |file|
path = File.expand_path(file)
if File.exist?(path)
config_file_path = path
break
end
end
config_file_path
end
def read_config_file(path)
require 'yaml'
YAML.load_file(path)
end
def configure(config)
option_members = @options.members
param_members = @params.members
# It would be more useful to be able to configure by plot type
config.each do |k, v|
k = k.to_sym
if option_members.include?(k)
@options[k] = v
elsif param_members.include?(k)
@params[k] = v
else
raise Error, "Unknown option/param: #{k}"
end
end
end end
def create_base_parser def create_base_parser
@@ -277,6 +327,8 @@ module YouPlot
options[:color_names] = v options[:color_names] = v
end end
when :config
else else
error_message = "uplot: unrecognized command '#{command}'" error_message = "uplot: unrecognized command '#{command}'"
if YouPlot.run_as_executable? if YouPlot.run_as_executable?

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module YouPlot module YouPlot
VERSION = '0.4.3' VERSION = '0.4.4'
end end