rbtclk 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/rbtclk.rb +29 -4
- data/lib/rbtclk/clock.rb +9 -1
- data/lib/rbtclk/color_code.rb +10 -0
- data/lib/rbtclk/countup_timer.rb +13 -3
- data/lib/rbtclk/version.rb +1 -1
- data/spec/rbtclk/color_code_spec.rb +18 -0
- data/spec/rbtclk_spec.rb +48 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36989cdcf0479af2abae38d31b549887c9458794
|
4
|
+
data.tar.gz: 1c9439e5978b46deb1803ea01fe47210116d2505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93b1399d2fae3bb8e757145d7a0648f42f2ec8d645dbf9d88c6f7c001458368c96a4ef815e4bf4914d3fc0628e2e9a2f500f9647786af85334276c26716fff04
|
7
|
+
data.tar.gz: e0d5e06c5eff70e2a69e51f06ca91b73181390bf67ae4050de09bd047fcac42be490e6d52425ed1d6e625eedc9003b5908bace4bebed01bdfeebfba4678e870a
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A light-weight timer application that can run in terminal emulators :rabbit:
|
4
4
|
|
5
|
+
![screenshot](https://raw.github.com/wiki/mozamimy/rbtclk/images/screenshot.gif)
|
6
|
+
|
5
7
|
## Requirement
|
6
8
|
|
7
9
|
- Ruby 2.0 or later.
|
@@ -135,6 +137,18 @@ $ rbtclk --format "* %H:%M *"
|
|
135
137
|
# # ## #### ## #### #### # #
|
136
138
|
```
|
137
139
|
|
140
|
+
### Enable color
|
141
|
+
|
142
|
+
Rbtclk can show clock with ANSI colors.
|
143
|
+
Black(default), red, green, yellow, blue, magenta, cyan and white are available.
|
144
|
+
|
145
|
+
#### Example
|
146
|
+
|
147
|
+
```shell
|
148
|
+
$ rbtclk -c magenta
|
149
|
+
$ rbtclk --color magenta
|
150
|
+
```
|
151
|
+
|
138
152
|
## Progress Report
|
139
153
|
|
140
154
|
- [x] Clock
|
data/lib/rbtclk.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require "curses"
|
2
1
|
require "optparse"
|
3
2
|
require "rbtclk/version"
|
4
3
|
require "rbtclk/clock"
|
@@ -13,16 +12,31 @@ module Rbtclk
|
|
13
12
|
opt.on("--mode MODE") { |m| params[:mode] = m }
|
14
13
|
opt.on("--format FORMAT") { |f| params[:format] = f }
|
15
14
|
opt.on("--font FONT") { |f| params[:font] = f }
|
15
|
+
opt.on("--version") { |v| params[:version] = v }
|
16
|
+
opt.on("--color COLOR") { |c| params[:color] = c }
|
16
17
|
|
17
18
|
opt.parse!(args)
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
+
if params[:version]
|
22
|
+
puts Rbtclk::VERSION
|
23
|
+
exit
|
24
|
+
else
|
25
|
+
display_clock(params)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def display_clock(params)
|
30
|
+
params = fill(params)
|
31
|
+
|
32
|
+
case params[:mode]
|
21
33
|
when "clock"
|
22
|
-
|
34
|
+
remove_extra_params(params)
|
35
|
+
timer = Clock.new(params)
|
23
36
|
timer.show
|
24
37
|
when "countup"
|
25
|
-
|
38
|
+
remove_extra_params(params)
|
39
|
+
timer = CountupTimer.new(params)
|
26
40
|
timer.show
|
27
41
|
else
|
28
42
|
warn "#{params[:mode]} mode is not supported."
|
@@ -30,5 +44,16 @@ module Rbtclk
|
|
30
44
|
exit(1)
|
31
45
|
end
|
32
46
|
end
|
47
|
+
|
48
|
+
def fill(params)
|
49
|
+
{mode: params[:mode] || "clock",
|
50
|
+
font: params[:font] || "clb8x8",
|
51
|
+
format: params[:format] || "%X",
|
52
|
+
color: params[:color] || "black"}
|
53
|
+
end
|
54
|
+
|
55
|
+
def remove_extra_params(params)
|
56
|
+
params.delete(:mode)
|
57
|
+
end
|
33
58
|
end
|
34
59
|
end
|
data/lib/rbtclk/clock.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
require "artii"
|
2
2
|
require "curses"
|
3
|
+
require "rbtclk/color_code"
|
3
4
|
|
4
5
|
module Rbtclk
|
5
6
|
class Clock
|
6
|
-
|
7
|
+
include ColorCode
|
8
|
+
|
9
|
+
def initialize(font: "clb8x8", format: "%X", color: "black")
|
7
10
|
@artii = Artii::Base.new(font: font)
|
8
11
|
@format = format
|
12
|
+
@color = color
|
9
13
|
end
|
10
14
|
|
11
15
|
def show
|
12
16
|
Curses.init_screen
|
17
|
+
Curses.start_color
|
18
|
+
Curses.use_default_colors
|
19
|
+
Curses.init_pair(1, translate(@color), -1)
|
13
20
|
Curses.curs_set(0)
|
14
21
|
|
15
22
|
begin
|
@@ -41,6 +48,7 @@ module Rbtclk
|
|
41
48
|
def refresh
|
42
49
|
Curses.clear
|
43
50
|
Curses.setpos(0, 0)
|
51
|
+
Curses.attron(Curses.color_pair(1))
|
44
52
|
Curses.addstr(@artii.asciify(Time.now.strftime(@format)))
|
45
53
|
Curses.refresh
|
46
54
|
end
|
data/lib/rbtclk/countup_timer.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
require "artii"
|
2
2
|
require "curses"
|
3
3
|
require "time"
|
4
|
+
require "rbtclk/color_code"
|
4
5
|
|
5
6
|
module Rbtclk
|
6
7
|
class CountupTimer
|
7
|
-
|
8
|
-
|
8
|
+
include ColorCode
|
9
|
+
|
10
|
+
def initialize(font: "clb8x8", format: "%X", color: "black")
|
11
|
+
@artii = Artii::Base.new(font: font)
|
9
12
|
@format = format
|
13
|
+
@color = color
|
10
14
|
end
|
11
15
|
|
12
16
|
def show
|
13
17
|
Curses.init_screen
|
18
|
+
Curses.start_color
|
19
|
+
Curses.use_default_colors
|
20
|
+
Curses.init_pair(1, translate(@color), -1)
|
14
21
|
Curses.curs_set(0)
|
22
|
+
|
15
23
|
@start_time = Time.now
|
16
24
|
|
17
25
|
begin
|
@@ -26,7 +34,8 @@ module Rbtclk
|
|
26
34
|
loop do
|
27
35
|
case Curses.getch
|
28
36
|
when "q"
|
29
|
-
|
37
|
+
Thread.kill(view_thread)
|
38
|
+
Thread.kill(input_thread)
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
@@ -42,6 +51,7 @@ module Rbtclk
|
|
42
51
|
def refresh
|
43
52
|
Curses.clear
|
44
53
|
Curses.setpos(0, 0)
|
54
|
+
Curses.attron(Curses.color_pair(1))
|
45
55
|
Curses.addstr(@artii.asciify((Time.parse("1/1") + (Time.now - @start_time)).strftime(@format)))
|
46
56
|
Curses.refresh
|
47
57
|
end
|
data/lib/rbtclk/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "curses"
|
3
|
+
|
4
|
+
RSpec.describe Rbtclk::ColorCode do
|
5
|
+
include Rbtclk::ColorCode
|
6
|
+
|
7
|
+
describe "#translate" do
|
8
|
+
context "the argument is string" do
|
9
|
+
subject { translate("magenta") }
|
10
|
+
it { expect(subject).to eq Curses::COLOR_MAGENTA }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "the argument is symbol" do
|
14
|
+
subject { translate(:magenta) }
|
15
|
+
it { expect(subject).to eq Curses::COLOR_MAGENTA }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/rbtclk_spec.rb
CHANGED
@@ -1,5 +1,52 @@
|
|
1
1
|
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)"
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#display_clock" do
|
9
|
+
pending "this is pending bcause on the issue#3 (https://github.com/mozamimy/rbtclk/issues/3)"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "methods related with params" do
|
13
|
+
let(:filled_params) do
|
14
|
+
{mode: "clock",
|
15
|
+
font: "clb8x8",
|
16
|
+
format: "%X",
|
17
|
+
color: "black"}
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#fill" do
|
21
|
+
context "there are no blank elements in the argument" do
|
22
|
+
subject { Rbtclk.fill(filled_params) }
|
23
|
+
it { expect(subject).to eq filled_params }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "there in a blank element in the argument" do
|
27
|
+
let(:not_filled_params) do
|
28
|
+
{mode: "clock",
|
29
|
+
font: "clb8x8",
|
30
|
+
format: "%X"}
|
31
|
+
end
|
32
|
+
|
33
|
+
subject { Rbtclk.fill(not_filled_params) }
|
34
|
+
it { expect(subject).to eq filled_params }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#remove_extra_params" do
|
39
|
+
let(:params_that_has_no_mode) do
|
40
|
+
filled_params.delete(:mode)
|
41
|
+
filled_params
|
42
|
+
end
|
43
|
+
|
44
|
+
context "params contains :mode value" do
|
45
|
+
specify ":mode value is removed" do
|
46
|
+
Rbtclk.remove_extra_params(filled_params)
|
47
|
+
expect(filled_params).to eq params_that_has_no_mode
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
5
52
|
end
|
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,9 +126,11 @@ files:
|
|
126
126
|
- bin/rbtclk
|
127
127
|
- lib/rbtclk.rb
|
128
128
|
- lib/rbtclk/clock.rb
|
129
|
+
- lib/rbtclk/color_code.rb
|
129
130
|
- lib/rbtclk/countup_timer.rb
|
130
131
|
- lib/rbtclk/version.rb
|
131
132
|
- rbtclk.gemspec
|
133
|
+
- spec/rbtclk/color_code_spec.rb
|
132
134
|
- spec/rbtclk_spec.rb
|
133
135
|
- spec/spec_helper.rb
|
134
136
|
homepage: http://quellencode.org/
|
@@ -156,5 +158,6 @@ signing_key:
|
|
156
158
|
specification_version: 4
|
157
159
|
summary: A light-weight timer application that can run in terminal emulators.
|
158
160
|
test_files:
|
161
|
+
- spec/rbtclk/color_code_spec.rb
|
159
162
|
- spec/rbtclk_spec.rb
|
160
163
|
- spec/spec_helper.rb
|