rbnotes 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +5 -1
- data/lib/rbnotes/commands.rb +2 -0
- data/lib/rbnotes/commands/list.rb +54 -16
- data/lib/rbnotes/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c8725b48ee7e4048c6689227e519e27490e604463f84822211b0bad0bf8849
|
4
|
+
data.tar.gz: 71ef7e862a20d309c2c8fb29dc54ddacd42f6c3ab1f2eefd2e1dfb17e6ca8b2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3310eae55fd1bc5e5b8a9b83a0ba5ae7f76e3d953a8a94f62fb7aabd9952ff03f868328e4b1e978b9c80a9c9b3563b676fc10eb776dbb47051bb1026fcad765
|
7
|
+
data.tar.gz: 36e328b4a3a6fe64f52c52f31050c46b372f91e2f768420b235c1ed811908634e80197aa7cf358cc87e434f57cba61fcbefa76a0aa61633e119d70f3502a9997
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
## [Unreleased]
|
8
8
|
Nothing to record here.
|
9
9
|
|
10
|
+
## [0.2.2] - 2020-10-27
|
11
|
+
###
|
12
|
+
- Add feature to accept a timestamp pattern in `list` command. (#22)
|
13
|
+
|
10
14
|
## [0.2.1] - 2020-10-25
|
11
15
|
### Added
|
12
16
|
- Add feature to load the configuration from an external file.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbnotes (0.2.
|
4
|
+
rbnotes (0.2.2)
|
5
5
|
textrepo (~> 0.4)
|
6
6
|
unicode-display_width (~> 1.7)
|
7
7
|
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
minitest (5.14.2)
|
12
12
|
rake (13.0.1)
|
13
|
-
textrepo (0.4.
|
13
|
+
textrepo (0.4.3)
|
14
14
|
unicode-display_width (1.7.0)
|
15
15
|
|
16
16
|
PLATFORMS
|
data/README.md
CHANGED
@@ -9,13 +9,17 @@ Rbnotes is a simple utility to write a note in the single repository.
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'rbnotes
|
12
|
+
gem 'rbnotes'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
17
|
$ bundle install
|
18
18
|
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rbnotes
|
22
|
+
|
19
23
|
## Usage
|
20
24
|
|
21
25
|
General syntax is:
|
data/lib/rbnotes/commands.rb
CHANGED
@@ -31,6 +31,8 @@ module Rbnotes
|
|
31
31
|
usage: rbnotes [command] [args]
|
32
32
|
|
33
33
|
command:
|
34
|
+
add : create a new note
|
35
|
+
update STAMP : edit the note with external editor
|
34
36
|
import FILE : import a FILE into the repository
|
35
37
|
list NUM : list NUM notes
|
36
38
|
show STAMP : show the note specified with STAMP
|
@@ -2,42 +2,78 @@ require "unicode/display_width"
|
|
2
2
|
require "io/console/size"
|
3
3
|
|
4
4
|
module Rbnotes
|
5
|
+
##
|
6
|
+
# Defines `list` command for `rbnotes`. See the document of execute
|
7
|
+
# method to know about the behavior of this command.
|
8
|
+
|
5
9
|
class Commands::List < Commands::Command
|
10
|
+
|
11
|
+
##
|
12
|
+
# Shows the list of notes in the repository. The only argument is
|
13
|
+
# optional. If it passed, it must be an timestamp pattern. A
|
14
|
+
# timestamp is an instance of Textrepo::Timestamp class. A
|
15
|
+
# timestamp pattern is a string which would match several
|
16
|
+
# Timestamp objects.
|
17
|
+
#
|
18
|
+
# Here is
|
19
|
+
# several examples of timestamp patterns.
|
20
|
+
#
|
21
|
+
# "20201027093600_012": a complete string to represent a timestamp
|
22
|
+
# - this pattern would match exactly one Timestamp object
|
23
|
+
#
|
24
|
+
# "20201027": specifies year and date
|
25
|
+
# - all Timestamps those have the same year and date would match
|
26
|
+
#
|
27
|
+
# "2020": specifies year only
|
28
|
+
# - all Timestamps those have the same year would match
|
29
|
+
#
|
30
|
+
# "1027": specifies date only
|
31
|
+
# - all Timestamps those have the same date would match, even if
|
32
|
+
# they have the different year.
|
33
|
+
#
|
34
|
+
# :call-seq:
|
35
|
+
# execute(Array, Rbnotes::Conf or Hash) -> nil
|
36
|
+
|
6
37
|
def execute(args, conf)
|
7
|
-
|
8
|
-
max = (args.shift || @row - 3).to_i
|
38
|
+
pattern = args.shift # `nil` is acceptable
|
9
39
|
|
10
40
|
@repo = Textrepo.init(conf)
|
11
|
-
|
12
|
-
|
13
|
-
|
41
|
+
# newer stamp shoud be above
|
42
|
+
stamps = @repo.entries(pattern).sort{|a, b| b <=> a}
|
43
|
+
stamps.each { |timestamp|
|
44
|
+
puts make_headline(timestamp)
|
14
45
|
}
|
15
46
|
end
|
16
47
|
|
48
|
+
# :stopdoc:
|
49
|
+
|
17
50
|
private
|
18
51
|
TIMESTAMP_STR_MAX_WIDTH = "yyyymoddhhmiss_sfx".size
|
52
|
+
|
53
|
+
##
|
19
54
|
# Makes a headline with the timestamp and subject of the notes, it
|
20
55
|
# looks like as follows:
|
21
56
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
57
|
+
# |<------------------ console column size --------------------->|
|
58
|
+
# +-- timestamp ---+ +--- subject (the 1st line of each note) --+
|
59
|
+
# | | | |
|
60
|
+
# 20101010001000_123: # I love Macintosh. [EOL]
|
61
|
+
# 20100909090909_999: # This is very very long long loooong subje[EOL]
|
62
|
+
# ++
|
63
|
+
# ^--- delimiter (2 characters)
|
29
64
|
#
|
30
65
|
# The subject part will truncate when it is long.
|
31
|
-
def make_headline(timestamp_str)
|
32
66
|
|
67
|
+
def make_headline(timestamp)
|
68
|
+
_, column = IO.console_size
|
33
69
|
delimiter = ": "
|
34
|
-
subject_width =
|
70
|
+
subject_width = column - TIMESTAMP_STR_MAX_WIDTH - delimiter.size - 1
|
35
71
|
|
36
|
-
subject = @repo.read(
|
72
|
+
subject = @repo.read(timestamp)[0]
|
37
73
|
prefix = '# '
|
38
74
|
subject = prefix + subject.lstrip if subject[0, 2] != prefix
|
39
75
|
|
40
|
-
ts_part = "#{
|
76
|
+
ts_part = "#{timestamp.to_s} "[0..(TIMESTAMP_STR_MAX_WIDTH - 1)]
|
41
77
|
sj_part = truncate_str(subject, subject_width)
|
42
78
|
|
43
79
|
ts_part + delimiter + sj_part
|
@@ -53,5 +89,7 @@ module Rbnotes
|
|
53
89
|
}
|
54
90
|
result
|
55
91
|
end
|
92
|
+
|
93
|
+
# :startdoc:
|
56
94
|
end
|
57
95
|
end
|
data/lib/rbnotes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbnotes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: textrepo
|