jott 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1639bd8ac86e7f5ef1bfb9cf52fc49178a531c07b4af9f27d12458735a58286c
4
- data.tar.gz: 3123edf823387da542d590cb9cebf2c894f9246092ba90ca952056b7c1c16831
3
+ metadata.gz: 15a02145f8225bff6c97da4548f68604183543c9bf88d74abcc434ed5f4528f9
4
+ data.tar.gz: ad5435b67e0448c20b687c6bf4d3210bdefe04c8a3e64ea44c15c4bc686a483e
5
5
  SHA512:
6
- metadata.gz: fd829bbef8f58064e3146dfcdf5170b07d25fe385b0857e01bd1515a8b682f0e3f5b6f21b0141ad32e122117366b1382f23bfd1b452fbf961bf414955de59050
7
- data.tar.gz: 3d5e921a5936491370bbb5f0c7eeaf722257c495b579365fc86979e57f858f8e18fec524e07c2eeaa361e362817e415c5094bf423f4b8bc49b748534bd4a62e6
6
+ metadata.gz: f2c973f1c9b1a88dfcf96254a23b0570790cc853904f428c2eefd81563a5148bfc1730baded8846f21911799c55a8e9895f33c360d2965f2e0576123ae3caebb
7
+ data.tar.gz: 5991c898d779b862a427afb538b0b115b96dab11672d7611a9c90cb433444a77c1afe71cc5e30a8707171070e72064001666ac6074fb89ff19497476d3abbf39
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jott (0.1.3)
4
+ jott (0.1.5)
5
5
  colorize
6
6
  sqlite3
7
7
  thor
@@ -14,10 +14,10 @@ GEM
14
14
  diff-lcs (1.5.0)
15
15
  json (2.6.3)
16
16
  parallel (1.22.1)
17
- parser (3.2.1.1)
17
+ parser (3.2.2.0)
18
18
  ast (~> 2.4.1)
19
19
  rainbow (3.1.1)
20
- regexp_parser (2.7.0)
20
+ regexp_parser (2.8.0)
21
21
  rexml (3.2.5)
22
22
  rspec (3.12.0)
23
23
  rspec-core (~> 3.12.0)
@@ -32,20 +32,20 @@ GEM
32
32
  diff-lcs (>= 1.2.0, < 2.0)
33
33
  rspec-support (~> 3.12.0)
34
34
  rspec-support (3.12.0)
35
- rubocop (1.48.1)
35
+ rubocop (1.50.2)
36
36
  json (~> 2.3)
37
37
  parallel (~> 1.10)
38
38
  parser (>= 3.2.0.0)
39
39
  rainbow (>= 2.2.2, < 4.0)
40
40
  regexp_parser (>= 1.8, < 3.0)
41
41
  rexml (>= 3.2.5, < 4.0)
42
- rubocop-ast (>= 1.26.0, < 2.0)
42
+ rubocop-ast (>= 1.28.0, < 2.0)
43
43
  ruby-progressbar (~> 1.7)
44
44
  unicode-display_width (>= 2.4.0, < 3.0)
45
- rubocop-ast (1.27.0)
45
+ rubocop-ast (1.28.0)
46
46
  parser (>= 3.2.1.0)
47
47
  ruby-progressbar (1.13.0)
48
- sqlite3 (1.6.1-x86_64-linux)
48
+ sqlite3 (1.6.2-x86_64-linux)
49
49
  thor (1.2.1)
50
50
  unicode-display_width (2.4.2)
51
51
 
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # Jott
1
+ ![E8BFE9C9-1977-478D-92AD-5509D48835EC](https://user-images.githubusercontent.com/19267892/235329218-9b7d9721-9414-4341-8dd6-b91fe39d3204.png)
2
+
3
+
4
+ [![Test](https://github.com/seita1996/jott/actions/workflows/test.yml/badge.svg)](https://github.com/seita1996/jott/actions/workflows/test.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ ![Gem](https://img.shields.io/gem/dt/jott?color=orange)
2
7
 
3
8
  A CLI application that allows you to create small memos.
4
9
  It can be installed as a Ruby Gem, and you can create, delete and display memos with the jott command.
@@ -14,7 +19,12 @@ $ gem install jott
14
19
  Create a new memo
15
20
 
16
21
  ```
17
- $ jott add 'This is first memo'
22
+ $ jott add This is first memo
23
+
24
+ or
25
+
26
+ $ jott add
27
+ -> open your editor
18
28
  ```
19
29
 
20
30
  List memos
@@ -23,6 +33,22 @@ List memos
23
33
  $ jott ls
24
34
  ```
25
35
 
36
+ Edit the memo
37
+
38
+ ```
39
+ $ jott edit 1 This is updated memo
40
+
41
+ or
42
+
43
+ $ jott edit 1
44
+ -> open your editor
45
+
46
+ or
47
+
48
+ $ jott edit
49
+ -> open your editor (last memo)
50
+ ```
51
+
26
52
  Delete the memo
27
53
 
28
54
  ```
@@ -35,6 +61,18 @@ Clear all memos
35
61
  $ jott clear
36
62
  ```
37
63
 
64
+ Set the editor
65
+
66
+ ```
67
+ $ jott set-editor vim
68
+ ```
69
+
70
+ Check config
71
+
72
+ ```
73
+ $ jott config
74
+ ```
75
+
38
76
  ## Development
39
77
 
40
78
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/jott.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  # spec.description = "TODO: Write a longer description or delete this line."
13
13
  spec.homepage = "https://rubygems.org/gems/jott"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
15
+ spec.required_ruby_version = ">= 3.1"
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
18
 
data/lib/jott/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'colorize'
2
+ require 'tempfile'
2
3
  require 'thor'
4
+ require_relative 'config'
3
5
  require_relative 'memo'
4
6
  require_relative 'version'
5
7
 
@@ -12,7 +14,21 @@ class CLI < Thor
12
14
  end
13
15
 
14
16
  desc "add", "Add a new memo"
15
- def add(text)
17
+ def add(*str)
18
+ if str.empty? # open text editor
19
+ tempfile = Tempfile.new
20
+ system(editor, tempfile.path)
21
+ text = File.read(tempfile.path)
22
+ tempfile.unlink
23
+ else # add memo from command line
24
+ text = str.join(" ")
25
+ end
26
+
27
+ if text.chomp == ""
28
+ puts "Please enter text.".colorize(:red)
29
+ exit
30
+ end
31
+
16
32
  title = text[0, 30]
17
33
  Memo.new.create(title:, body: text)
18
34
  puts "Added new memo: #{title}".colorize(:green)
@@ -24,6 +40,35 @@ class CLI < Thor
24
40
  puts "Deleted the memo: #{id}".colorize(:green)
25
41
  end
26
42
 
43
+ desc "edit", "open the memo with text editor and update"
44
+ def edit(*args)
45
+ id = args.first
46
+ id = Memo.new.last[0][0] if id.nil?
47
+ str = args[1..-1]
48
+ memo = Memo.new.find(id)
49
+
50
+ if str.nil? || str.empty? # open text editor
51
+ tempfile = Tempfile.new
52
+ File.open(tempfile.path, "w") do |f|
53
+ f.puts memo[0][2]
54
+ end
55
+ system(editor, tempfile.path)
56
+ text = File.read(tempfile.path)
57
+ tempfile.unlink
58
+ else # add memo from command line
59
+ text = str.join(" ")
60
+ end
61
+
62
+ if text.chomp == ""
63
+ puts "Please enter text.".colorize(:red)
64
+ exit
65
+ end
66
+
67
+ title = text[0, 30]
68
+ Memo.new.update(id: id, title: title, body: text)
69
+ puts "Edited the memo: #{id}".colorize(:green)
70
+ end
71
+
27
72
  desc "list", "list all memos"
28
73
  def ls
29
74
  memos = Memo.new.all
@@ -32,10 +77,33 @@ class CLI < Thor
32
77
  end
33
78
  end
34
79
 
80
+ desc "show", "show memo ID"
81
+ def show(id)
82
+ memo = Memo.new.find(id)
83
+ puts "#{memo[0][2]}"
84
+ end
85
+
86
+ desc "set-editor", "Set the default editor"
87
+ def set_editor(editor)
88
+ Config.new.set_editor(editor)
89
+ puts "Set editor: #{editor}".colorize(:green)
90
+ end
91
+
92
+ desc "config", "Show the current configuration"
93
+ def config
94
+ puts "editor: #{editor}"
95
+ end
96
+
35
97
  desc "version", "show version"
36
98
  def version
37
99
  puts "jott version #{Jott::VERSION}"
38
100
  end
101
+
102
+ private
103
+
104
+ def editor
105
+ Config.new.editor
106
+ end
39
107
  end
40
108
 
41
109
  CLI.start(ARGV)
@@ -0,0 +1,29 @@
1
+ class Config
2
+ attr_reader :editor
3
+
4
+ def initialize
5
+ @file_path = File.join("#{File.dirname(__FILE__)}", "jott.config")
6
+ unless File.exist?(@file_path)
7
+ File.new(@file_path, "w")
8
+ end
9
+ @editor = get_editor
10
+ end
11
+
12
+ def get_editor
13
+ File.open(@file_path, "r") do |file|
14
+ file.each_line do |line|
15
+ if line.include?("editor")
16
+ return line.split(":")[1].strip
17
+ end
18
+ end
19
+ end
20
+ return "vi"
21
+ end
22
+
23
+ def set_editor(editor)
24
+ File.open(@file_path, "w") do |file|
25
+ file.puts "editor: #{editor}"
26
+ end
27
+ @editor = editor
28
+ end
29
+ end
data/lib/jott/memo.rb CHANGED
@@ -19,6 +19,7 @@ class Memo
19
19
  end
20
20
 
21
21
  def create(title:, body:)
22
+ title = title.gsub(/\n/, "")
22
23
  @db.execute("INSERT INTO memos(title, body) VALUES (?, ?)", [title, body])
23
24
  end
24
25
 
@@ -26,7 +27,16 @@ class Memo
26
27
  @db.execute("DELETE FROM memos WHERE id = ?", id)
27
28
  end
28
29
 
30
+ def find(id)
31
+ @db.execute("SELECT * FROM memos WHERE id = ?", id)
32
+ end
33
+
29
34
  def last
30
35
  @db.execute("SELECT max(id), * FROM memos")
31
36
  end
37
+
38
+ def update(id:, title:, body:)
39
+ title = title.gsub(/\n/, "")
40
+ @db.execute("UPDATE memos SET title = ?, body = ? WHERE id = ?", [title, body, id])
41
+ end
32
42
  end
data/lib/jott/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jott
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jott
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - seita1996
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -91,6 +91,7 @@ files:
91
91
  - ".editorconfig"
92
92
  - ".rspec"
93
93
  - ".rubocop.yml"
94
+ - ".ruby-version"
94
95
  - CHANGELOG.md
95
96
  - CODE_OF_CONDUCT.md
96
97
  - Gemfile
@@ -102,6 +103,7 @@ files:
102
103
  - jott.gemspec
103
104
  - lib/jott.rb
104
105
  - lib/jott/cli.rb
106
+ - lib/jott/config.rb
105
107
  - lib/jott/memo.rb
106
108
  - lib/jott/version.rb
107
109
  - sig/jott.rbs
@@ -119,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
121
  requirements:
120
122
  - - ">="
121
123
  - !ruby/object:Gem::Version
122
- version: 2.6.0
124
+ version: '3.1'
123
125
  required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  requirements:
125
127
  - - ">="
126
128
  - !ruby/object:Gem::Version
127
129
  version: '0'
128
130
  requirements: []
129
- rubygems_version: 3.4.6
131
+ rubygems_version: 3.4.10
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: CLI application for a little note