suiren 24.04.04 → 24.04.09

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
  SHA256:
3
- metadata.gz: 4e1c34467b9eba28fb90e1b2f3fa60073451aee64cbca79eca0c2141211a6ab3
4
- data.tar.gz: 1cbb52b6fad8385d65f8085b3241b4ef85a284951567ae89f0442763dedde7e7
3
+ metadata.gz: 32116deb0430edc9dc55077ec2dcf2b38252d90059086de70b802079c4505e26
4
+ data.tar.gz: 667d73a2f4f00fc2312c2e1a82d674326f651eb9a8bef3839dbde0de43572228
5
5
  SHA512:
6
- metadata.gz: 14026c13c6760ab4e56470b7e48870ec363e7caa05662f26ad6c6f65058fd9841bf00c5164c1cce7484c6e329d2dd745760a3586427693bdab450957d28ba4f3
7
- data.tar.gz: 138a553254a7a0a3ba1a8cdca10e6ff201843a7f9a1fcbd6c05731318860d71a94170acac0772b63418d37b6f9298af295b50c68d81b185c54f3065c86b747cc
6
+ metadata.gz: ec9ec5fe1df6bd20b5f58c8e91f5c3afad7006a4e91acfa48298b2dbf5c9755775e8242876378d212645975474b18a141d5a0692e84257c03c76e52eda05079a
7
+ data.tar.gz: 8ff2761781314d54cfc0d0ba55783e9169b495ab87dca7981c691526ea923566db14d5d7dee6808c8efaa77f8c1e050766fafacfc84a4a50b40bb27ccc708be7
data/README.en_US.md ADDED
@@ -0,0 +1,60 @@
1
+
2
+
3
+
4
+ # suiren
5
+ suiren is a command-line tool for displaying HTTP requests.
6
+
7
+ ## Installation
8
+ ### Install the gem
9
+
10
+ ```bash
11
+ gem install suiren
12
+ ```
13
+
14
+ ### Add to your package
15
+ ```bash
16
+ bundle add suiren
17
+ ```
18
+
19
+ ## Usage
20
+ suiren supports both Japanese and English.
21
+
22
+ To run it in Japanese, use:
23
+
24
+ ```bash
25
+ LANG=ja_JP.UTF-8 suiren
26
+ ```
27
+
28
+ To run it in English, use:
29
+
30
+ ```bash
31
+ LANG= suiren
32
+ ```
33
+
34
+ To run it in Taiwanese, use:
35
+
36
+ ```bash
37
+ LANG=zh_TW.UTF-8 suiren
38
+ ```
39
+
40
+ System Language Override.
41
+
42
+ ### See how to use
43
+ ```bash
44
+ $ suiren -h
45
+ Usage: suiren [options]
46
+ -V, --version Display Version Information
47
+ --license Display License Information
48
+ --bind-address [Bind Address]
49
+ Set Bind Address
50
+ -p, --port [Port] Port Number
51
+ -c, --content [Content] Set Content to Reply
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Himeyama/suiren.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/README.md CHANGED
@@ -1,35 +1,59 @@
1
- # Suiren
1
+ # suiren (睡蓮)
2
+ suiren はコマンドを HTTP リクエストを表示するコマンドです。
2
3
 
3
- TODO: Delete this and the text below, and describe your gem
4
+ ![image](https://github.com/Himeyama/suiren/assets/39254183/7d373c5a-8bc9-4f15-ae79-c49333f5e649)
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/suiren`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ ## インストールについて
7
+ ### gem のインストール
6
8
 
7
- ## Installation
9
+ ```bash
10
+ gem install suiren
11
+ ```
8
12
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
13
+ ### パッケージに追加
14
+ ```bash
15
+ bundle add suiren
16
+ ```
10
17
 
11
- Install the gem and add to the application's Gemfile by executing:
18
+ ## 使用法
19
+ suiren は日本語と英語と台湾語に対応しています。
12
20
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ 日本語で使用する場合:
14
22
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
23
+ ```bash
24
+ LANG=ja_JP.UTF-8 suiren
25
+ ```
16
26
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
27
+ 英語で使用する場合:
18
28
 
19
- ## Usage
29
+ ```bash
30
+ LANG= suiren
31
+ ```
20
32
 
21
- TODO: Write usage instructions here
33
+ 台湾語で使用する場合:
22
34
 
23
- ## Development
35
+ ```bash
36
+ LANG=zh_TW.UTF-8 bundle exec suiren
37
+ ```
24
38
 
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+ システムの言語が優先されます。
26
40
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+ ### 使い方を見る
42
+ ```bash
43
+ $ suiren -h
44
+ Usage: suiren [options]
45
+ -V, --version バージョン情報を表示します
46
+ --license ライセンス情報を表示します
47
+ --bind-address [Bind Address]
48
+ Bind アドレスを設定します
49
+ -p, --port [Port] ポート番号
50
+ -c, --content [Content] 返信するコンテンツを設定します
51
+ ```
28
52
 
29
- ## Contributing
53
+ ## 貢献
30
54
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/suiren.
55
+ バグレポートとプルリクエストは https://GitHub.com/Himeyama/suiren で行うことができます。
32
56
 
33
- ## License
57
+ ## ライセンス
34
58
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
+ この gem は、[MIT ライセンス](https://opensource.org/licenses/MIT) の条件の下でオープンソースとして利用できます。
data/README.zh_TW.md ADDED
@@ -0,0 +1,56 @@
1
+ # suiren
2
+ suiren 是一個用於顯示 HTTP 請求的命令行工具。
3
+
4
+ ## 安裝
5
+ ### 安裝 gem
6
+
7
+ ```bash
8
+ gem install suiren
9
+ ```
10
+
11
+ ### 添加到您的專案
12
+ ```bash
13
+ bundle add suiren
14
+ ```
15
+
16
+ ## 使用方法
17
+ suiren 支援台灣語和日語和英語。
18
+
19
+ 要在台灣語中運行,請使用:
20
+
21
+ ```bash
22
+ LANG=zh_TW.UTF-8 suiren
23
+ ```
24
+
25
+ 要在日語中運行,請使用:
26
+
27
+ ```bash
28
+ LANG=ja_JP.UTF-8 suiren
29
+ ```
30
+
31
+ 要在英語中運行,請使用:
32
+
33
+ ```bash
34
+ LANG= suiren
35
+ ```
36
+
37
+ 系統語言覆蓋。
38
+
39
+ ### 查看如何使用
40
+ ```bash
41
+ $ suiren -h
42
+ Usage: suiren [options]
43
+ -V, --version 顯示版本資訊
44
+ --license 顯示許可證資訊
45
+ --bind-address [Bind Address]
46
+ 設定綁定地址
47
+ -p, --port [Port] 埠號
48
+ -c, --content [Content] 設定回覆內容
49
+ ```
50
+
51
+ ## 貢獻
52
+
53
+ 歡迎在 GitHub 上報告錯誤和提交拉取請求: https://github.com/Himeyama/suiren
54
+
55
+ ## 許可證
56
+ 該 gem 可根據 [MIT 許可證](https://opensource.org/licenses/MIT) 作為開源軟件使用。
data/exe/suiren CHANGED
@@ -4,60 +4,39 @@
4
4
  require "suiren"
5
5
  require "optparse"
6
6
 
7
- @i18n = {
8
- "en": {
9
- "port": "Port number",
10
- "version_info": "Displays version information",
11
- "license_info": "Displays license information",
12
- "bind_addr": "Set the bind address",
13
- "content": "Set the content to reply to"
14
- },
15
- "ja": {
16
- "port": "ポート番号",
17
- "version_info": "バージョン情報を表示します",
18
- "license_info": "ライセンス情報を表示します",
19
- "bind_addr": "Bind アドレスを設定します",
20
- "content": "返信するコンテンツを設定します"
21
- }
22
- }
23
-
24
- def i18n(tag)
25
- lang = :en
26
- lang = :ja if ENV["LANG"].downcase.include?("ja")
27
- @i18n[lang][tag]
28
- end
7
+ Suiren::Suiren.init_i18n
29
8
 
30
9
  opt = OptionParser.new
31
10
  bind_addr = "localhost"
32
11
  port = 8080
33
12
  content = String.new
34
13
 
35
- opt.on("-V", "--version", i18n(:version_info)) do |_v|
14
+ opt.on("-V", "--version", I18n.t("version_info")) do |_v|
36
15
  puts("#{File.basename($PROGRAM_NAME)} (#{Suiren::VERSION})")
37
16
  exit(true)
38
17
  end
39
18
 
40
- opt.on("--license", i18n(:license_info)) do |_v|
19
+ opt.on("--license", I18n.t("license_info")) do |_v|
41
20
  puts(Suiren::COPYRIGHT)
42
21
  exit(true)
43
22
  end
44
23
 
45
- opt.on("--bind-address [Bind Address]", i18n(:bind_addr)) do |addr|
24
+ opt.on("--bind-address [Bind Address]", I18n.t("bind_addr")) do |addr|
46
25
  bind_addr = addr
47
26
  end
48
27
 
49
- opt.on("-p [Port]", "--port", i18n(:port)) do |p|
28
+ opt.on("-p [Port]", "--port", I18n.t("port")) do |p|
50
29
  port = p.to_i
51
30
  end
52
31
 
53
- opt.on("-c [Content]", "--content", i18n(:content)) do |cont|
32
+ opt.on("-c [Content]", "--content", I18n.t("content")) do |cont|
54
33
  content = cont
55
34
  end
56
35
 
57
36
  begin
58
37
  opt.parse!(ARGV)
59
38
  rescue OptionParser::InvalidOption
60
- warn(comment(:option_not_appropriate))
39
+ warn(I18n.t("option_not_appropriate"))
61
40
  exit(false)
62
41
  end
63
42
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Suiren
4
- VERSION = "24.04.04"
4
+ VERSION = "24.04.09"
5
5
 
6
6
  COPYRIGHT = <<~COPYRIGHT_TEXT
7
7
  The MIT License (MIT)
data/lib/suiren.rb CHANGED
@@ -4,14 +4,31 @@ require_relative "suiren/version"
4
4
  require "socket"
5
5
  require "json"
6
6
  require "stringio"
7
+ require "io/console/size"
8
+ require "i18n"
7
9
 
8
10
  module Suiren
9
11
  class Error < StandardError; end
10
12
 
11
13
  class Suiren # rubocop:disable Style/Documentation
14
+ def self.init_i18n
15
+ I18n.load_path = ["#{__dir__}/translation.yml"]
16
+ I18n.locale = :en
17
+ I18n.locale = :ja if ENV["LANG"].downcase =~ /^ja/
18
+ I18n.locale = :zh_TW if ENV["LANG"].downcase =~ /^zh_tw/
19
+ end
20
+
12
21
  def initialize(host, port, content: "") # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
13
- server = TCPServer.new(host, port)
14
- puts("サーバーが http://#{host}:#{port} で実行中です\n\n")
22
+ self.class.init_i18n
23
+
24
+ begin
25
+ server = TCPServer.new(host, port)
26
+ rescue Errno::EADDRINUSE
27
+ warn("\e[31;1m#{I18n.t("address_already")}\e[0m")
28
+ exit(false)
29
+ end
30
+
31
+ puts(format("#{I18n.t("server_running")}\n\n", host, port))
15
32
  uplen = 0
16
33
 
17
34
  loop do # rubocop:disable Metrics/BlockLength
@@ -31,21 +48,26 @@ module Suiren
31
48
  headers = {}
32
49
  keys = []
33
50
 
34
- puts("[#{time}]")
51
+ puts("\e[36m#{I18n.t("teception_time")}: \e[36;1m#{time}\e[0m")
52
+
35
53
  while (line = io.gets)
36
54
  break if line.strip.empty?
37
55
 
38
56
  match = line.match(/^(.+):\s(.+)$/)
39
57
  break unless match
40
58
 
41
- key = match[1]
59
+ key = match[1].chomp
42
60
  keys.append(key)
43
- value = match[2]
61
+ value = match[2].chomp
44
62
  max_key_len = key.size if max_key_len < key.size
45
63
  max_value_len = value.size if max_value_len < value.size
46
64
  headers[key.strip] = value.strip
47
65
  end
48
66
 
67
+ _height, width = IO.console_size
68
+ max_value_len_window = width - max_key_len - 7 # 2 列目の長さ (ウィンドウ制限)
69
+ max_value_len = max_value_len_window if max_value_len > max_value_len_window
70
+
49
71
  request_line_format = "%-#{max_key_len + max_value_len + 3}s"
50
72
  puts "+#{"-" * (max_key_len + max_value_len + 5)}+"
51
73
  puts "| #{request_line_format % request_line.chop} |"
@@ -54,10 +76,14 @@ module Suiren
54
76
  border = "+#{"-" * (max_key_len + 2)}+#{"-" * (max_value_len + 2)}+"
55
77
  puts border
56
78
  keys.each do |key| # rubocop:disable Lint/ShadowingOuterLocalVariable
57
- puts "| #{key_format % key} | #{value_format % headers[key]} |"
79
+ keys_line = headers[key].scan(/.{1,#{max_value_len}}/)
80
+ keys_line.each.with_index do |value_line, i|
81
+ puts "| #{key_format % (i.eql?(0) ? key : "")} | #{value_format % value_line} |"
82
+ end
83
+ # puts "| #{key_format % key} | #{value_format % headers[key]} |"
58
84
  end
59
85
  puts "#{border}\n"
60
- body = "#{io.read}\n"
86
+ body = "#{io.read}\n\n"
61
87
  puts body
62
88
  uplen = headers.size + 5 + body.lines.size
63
89
 
@@ -0,0 +1,27 @@
1
+ ja:
2
+ teception_time: 受信時刻
3
+ server_running: サーバーが http://%s:%d で実行中です
4
+ address_already: アドレスが既に使用されています
5
+ port: ポート番号
6
+ version_info: バージョン情報を表示します
7
+ license_info: ライセンス情報を表示します
8
+ bind_addr: Bind アドレスを設定します
9
+ content: 返信するコンテンツを設定します
10
+ en:
11
+ teception_time: Reception Time
12
+ server_running: Server is running at http://%s:%d
13
+ address_already: Address is already in use
14
+ port: Port Number
15
+ version_info: Display Version Information
16
+ license_info: Display License Information
17
+ bind_addr: Set Bind Address
18
+ content: Set Content to Reply
19
+ zh_TW:
20
+ teception_time: 接收時間
21
+ server_running: 伺服器正在 http://%s:%d 運行
22
+ address_already: 地址已在使用中
23
+ port: 埠號
24
+ version_info: 顯示版本資訊
25
+ license_info: 顯示許可證資訊
26
+ bind_addr: 設定綁定地址
27
+ content: 設定回覆內容
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suiren
3
3
  version: !ruby/object:Gem::Version
4
- version: 24.04.04
4
+ version: 24.04.09
5
5
  platform: ruby
6
6
  authors:
7
7
  - MURATA Mitsuharu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-03 00:00:00.000000000 Z
11
+ date: 2024-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,11 +62,14 @@ extra_rdoc_files: []
48
62
  files:
49
63
  - ".rubocop.yml"
50
64
  - LICENSE.txt
65
+ - README.en_US.md
51
66
  - README.md
67
+ - README.zh_TW.md
52
68
  - Rakefile
53
69
  - exe/suiren
54
70
  - lib/suiren.rb
55
71
  - lib/suiren/version.rb
72
+ - lib/translation.yml
56
73
  - sig/botan.rbs
57
74
  homepage: https://github.com/Himeyama/suiren
58
75
  licenses: