rbtclk 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: 0ed5dee0180aa425d0ae3a2bbfdff9ee3ef61e96
4
- data.tar.gz: 99b3b7cf00641ed2e080a4269362d498129a72af
3
+ metadata.gz: c9ac4d391a7a069163edb5ad6d7cf7665fa7661f
4
+ data.tar.gz: 844aa7ff03d7a17910f27b2bdfd949e1cf3da53f
5
5
  SHA512:
6
- metadata.gz: eee3a10c5a55d8e154738ef4cb3e62453188633910083a4a6be97ce9c960d705bf86ea30dc032f5dc2ffcd3621b473b33b7f3cbb50d2f8623ecb81f400030d53
7
- data.tar.gz: 6f50e4c9d2d51a95c73990715b55782fea6a7568fce20c30c485bc0942f984af9d4a69f756779a582ed417b9211ecd32d1125efbe84b5a34d685d963a2cb0b6c
6
+ metadata.gz: d571c5777e34deff6a0d4a5f698d6c15c6558f0a40f1cc4f478b4a217a5b9fac2f3b140ea7e0aba5c9fc7cec73d322722791039f1a58b21fe8c3e48da7b6c1ef
7
+ data.tar.gz: 188060960d79102feeca8cac2093dc4b56e78a10e512cb060f3bc9ee23c81228838f2eff0378011d0c388420cdf7efe53e6e5c15b5300ed3b5fceb80db3a6352
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  .DS_Store
16
+ /vendor/bundle
data/README.md CHANGED
@@ -34,8 +34,7 @@ $ rbtclk
34
34
 
35
35
  ### Mode
36
36
 
37
- Now we support only clock mode and countup mode.
38
- Countdown timer mode is our future works.
37
+ This application supports some modes; clock, countup and countdown.
39
38
 
40
39
  #### Example
41
40
 
@@ -69,6 +68,21 @@ $ rbtclk -m countup
69
68
  #### #### ## #### #### ## ## ####
70
69
  ```
71
70
 
71
+ ```shell
72
+ $ rbtclk --mode countdown --time 90
73
+ $ rbtclk -m countdown --time 90
74
+ ```
75
+
76
+ ```
77
+ #### #### #### ## #### ####
78
+ ## ## ## ## ## ## ## ### ## ## ## ## ##
79
+ ## ## ## ## ## ## ## ## ## ## ## ##
80
+ ## ## ## ## ## ## ## ### ## ##
81
+ ## ## ## ## ## ## ## ## ## ##
82
+ ## ## ## ## ## ## ## ## ## ## ## ## ##
83
+ #### #### ## #### ## ## #### ####
84
+ ```
85
+
72
86
  ### Change font
73
87
 
74
88
  This application depends on artii library (https://github.com/miketierney/artii).
@@ -153,7 +167,10 @@ $ rbtclk --color magenta
153
167
 
154
168
  - [x] Clock
155
169
  - [x] Countup Timer
156
- - [ ] Countdown Timer
170
+ - [x] Countdown Timer
171
+ - [ ] Configuration by ~/.rbtclk
172
+ - [ ] Sound
173
+ - [ ] Refactoring
157
174
 
158
175
  ## Code Status
159
176
 
@@ -0,0 +1,82 @@
1
+ # Rbtclk
2
+ # Copyright (c) 2014 Moza USANE
3
+ # This software is released under the MIT License.
4
+ # http://opensource.org/licenses/mit-license.php
5
+
6
+ require "artii"
7
+ require "curses"
8
+ require "rbtclk/color_code"
9
+
10
+ module Rbtclk
11
+ class CountdownTimer
12
+ include ColorCode
13
+
14
+ def initialize(font: "clb8x8", format: "%X", color: "black", time: 180)
15
+ @artii = Artii::Base.new(font: font)
16
+ @format = format
17
+ @color = color
18
+ @time = time.to_i
19
+ @elapsed = 0
20
+ end
21
+
22
+ def show
23
+ Curses.init_screen
24
+ Curses.start_color
25
+ Curses.use_default_colors
26
+ Curses.init_pair(1, translate(@color), -1)
27
+ Curses.init_pair(2, translate("magenta"), translate("black"))
28
+ Curses.curs_set(0)
29
+
30
+ @start_time = Time.now + 1
31
+
32
+ begin
33
+ view_thread = Thread.new do
34
+ while @elapsed < @time
35
+ refresh
36
+ @elapsed += 1
37
+ sleep 1
38
+ end
39
+
40
+ toggle_marker = true
41
+ loop do
42
+ blink(toggle_marker)
43
+ is_even = !is_even
44
+ sleep 1
45
+ end
46
+ end
47
+
48
+ input_thread = Thread.new do
49
+ loop do
50
+ case Curses.getch
51
+ when "q"
52
+ Thread.kill(view_thread)
53
+ Thread.kill(input_thread)
54
+ end
55
+ end
56
+ end
57
+
58
+ view_thread.join
59
+ input_thread.join
60
+ ensure
61
+ Curses.close_screen
62
+ end
63
+ end
64
+
65
+ private
66
+ def refresh
67
+ Curses.clear
68
+ Curses.setpos(0, 0)
69
+ Curses.attron(Curses.color_pair(1))
70
+ Curses.addstr(@artii.asciify((Time.parse("1/1") + ((@start_time + @time) - Time.now)).strftime(@format)))
71
+ Curses.refresh
72
+ end
73
+
74
+ def blink(toggle_marker)
75
+ Curses.clear
76
+ Curses.setpos(0, 0)
77
+ Curses.attron(Curses.color_pair(2))
78
+ Curses.addstr(@artii.asciify(Time.parse("1/1").strftime(@format))) if toggle_marker
79
+ Curses.refresh
80
+ end
81
+ end
82
+ end
@@ -4,5 +4,5 @@
4
4
  # http://opensource.org/licenses/mit-license.php
5
5
 
6
6
  module Rbtclk
7
- VERSION = "0.2.1"
7
+ VERSION = "0.3.0"
8
8
  end
data/lib/rbtclk.rb CHANGED
@@ -7,6 +7,7 @@ require "optparse"
7
7
  require "rbtclk/version"
8
8
  require "rbtclk/clock"
9
9
  require "rbtclk/countup_timer"
10
+ require "rbtclk/countdown_timer"
10
11
 
11
12
  module Rbtclk
12
13
  class << self
@@ -19,13 +20,13 @@ module Rbtclk
19
20
  opt.on("--font FONT") { |f| params[:font] = f }
20
21
  opt.on("--version") { |v| params[:version] = v }
21
22
  opt.on("--color COLOR") { |c| params[:color] = c }
23
+ opt.on("--time TIME") { |t| params[:time] = t }
22
24
 
23
25
  opt.parse!(args)
24
26
  end
25
27
 
26
28
  if params[:version]
27
29
  puts Rbtclk::VERSION
28
- exit
29
30
  else
30
31
  display_clock(params)
31
32
  end
@@ -43,6 +44,10 @@ module Rbtclk
43
44
  remove_extra_params(params)
44
45
  timer = CountupTimer.new(params)
45
46
  timer.show
47
+ when "countdown"
48
+ remove_extra_params(params)
49
+ timer = CountdownTimer.new(params)
50
+ timer.show
46
51
  else
47
52
  warn "#{params[:mode]} mode is not supported."
48
53
  warn "You can use [clock]."
@@ -54,7 +59,8 @@ module Rbtclk
54
59
  {mode: params[:mode] || "clock",
55
60
  font: params[:font] || "clb8x8",
56
61
  format: params[:format] || "%X",
57
- color: params[:color] || "black"}
62
+ color: params[:color] || "black",
63
+ time: params[:time] || "180"}
58
64
  end
59
65
 
60
66
  def remove_extra_params(params)
data/rbtclk.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec"
23
23
  spec.add_development_dependency "timecop"
24
- spec.add_development_dependency "ariete"
24
+ spec.add_development_dependency "ariete", "~> 1.0.0"
25
25
  spec.add_dependency "artii"
26
26
  spec.add_dependency "curses"
27
27
  end
data/spec/rbtclk_spec.rb CHANGED
@@ -2,19 +2,33 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Rbtclk do
4
4
  describe "#run" do
5
- pending "this is pending bcause on the issue#3 (https://github.com/mozamimy/rbtclk/issues/3)"
5
+ context "clock/countdown/countup modes" do
6
+ pending "this is pending bcause on the issue#3 (https://github.com/mozamimy/rbtclk/issues/3)"
7
+ end
8
+
9
+ context "-v is given as an option" do
10
+ subject { -> { Rbtclk.run(["-v"]) } }
11
+ it { expect(subject).to be_output "#{Rbtclk::VERSION}\n" }
12
+ end
13
+
14
+ context "--version is given as an option" do
15
+ subject { -> { Rbtclk.run(["--version"]) } }
16
+ it { expect(subject).to be_output "#{Rbtclk::VERSION}\n" }
17
+ end
6
18
  end
7
19
 
8
20
  describe "#display_clock" do
9
21
  pending "this is pending bcause on the issue#3 (https://github.com/mozamimy/rbtclk/issues/3)"
10
22
  end
11
23
 
24
+
12
25
  describe "methods related with params" do
13
26
  let(:filled_params) do
14
27
  {mode: "clock",
15
28
  font: "clb8x8",
16
29
  format: "%X",
17
- color: "black"}
30
+ color: "black",
31
+ time: "180"}
18
32
  end
19
33
 
20
34
  describe "#fill" do
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,3 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'rbtclk'
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "rbtclk"
3
+ require "ariete"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtclk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moza USANE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: ariete
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.0.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: artii
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +127,7 @@ files:
127
127
  - lib/rbtclk.rb
128
128
  - lib/rbtclk/clock.rb
129
129
  - lib/rbtclk/color_code.rb
130
+ - lib/rbtclk/countdown_timer.rb
130
131
  - lib/rbtclk/countup_timer.rb
131
132
  - lib/rbtclk/version.rb
132
133
  - rbtclk.gemspec
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.2.2
157
+ rubygems_version: 2.4.3
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: A light-weight timer application that can run in terminal emulators.