twterm 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: ebf7362652e3fa052f2a3baef88ad36f4e47c61f
4
- data.tar.gz: 3aad720b6c5dfe38566c661bc00a4cae10f97bc6
3
+ metadata.gz: 52ffcecd46a9f09aacf0db6c809ce6f5fe71e874
4
+ data.tar.gz: f1340022b9fd1628be5bba96839321d381fdc94d
5
5
  SHA512:
6
- metadata.gz: 484c292558b6abd51aff8fe22605805db5d3e1c7be6d2fb0a21b2168bdeeef98a9346d307ab90d6595de98b0dda090abc601586f4e5b3b5e8cb6492c48b37d2b
7
- data.tar.gz: 9f4978776a77a77eab70a64f4b3a1565a83b3230569b44dd13f52d0b823b6caed7d8fc4dafc0e10bd1199c8db535c0f605822ed4f496a60bba27aa9d31d2632d
6
+ metadata.gz: 3b0732ac89eb6cdf4fc7475f8a47bbcdca9906cba71bffb3cad63ccbbaa7b298a9000ba82efa1e6353e776e8bd41b833e8343b8c63db495333263bf2bed7917c
7
+ data.tar.gz: 0451fec8a057f15b113785797673117cb99ca13eb25b7605af87657eeb2ae7f6048fb3f4ab7740ebffa2a0bf7e45ab2254b605cc1fe39228aaf2681532f0f1e6
data/lib/twterm/app.rb CHANGED
@@ -2,7 +2,11 @@ module Twterm
2
2
  class App
3
3
  include Singleton
4
4
 
5
+ DATA_DIR = "#{ENV['HOME']}/.twterm"
6
+
5
7
  def initialize
8
+ Dir.mkdir(DATA_DIR, 700) unless File.directory?(DATA_DIR)
9
+
6
10
  Config.load
7
11
  Auth.authenticate_user if Config[:screen_name].nil?
8
12
 
data/lib/twterm/config.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Twterm
2
2
  module Config
3
- CONFIG_FILE = "#{ENV['HOME']}/.twterm.yml"
3
+ CONFIG_FILE = "#{App::DATA_DIR}/config"
4
4
 
5
5
  def [](key)
6
6
  @config[key]
@@ -0,0 +1,36 @@
1
+ module Twterm
2
+ module History
3
+ module Base
4
+ MAX_HISTORY_SIZE = 500
5
+
6
+ attr_reader :history
7
+
8
+ def initialize
9
+ unless File.exist?(history_file)
10
+ @history = []
11
+ return
12
+ end
13
+
14
+ @history = YAML.load(File.read(history_file)) || []
15
+ end
16
+
17
+ def add(hashtag)
18
+ @history.unshift(hashtag)
19
+ @history = @history.uniq.take(MAX_HISTORY_SIZE)
20
+ save
21
+ end
22
+
23
+ private
24
+
25
+ def save
26
+ File.open(history_file, 'w', 0600) do |f|
27
+ f.write @history.to_yaml
28
+ end
29
+ end
30
+
31
+ def history_file
32
+ fail NotImplementedError, 'history_file method must be implemented'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module Twterm
2
+ module History
3
+ class Hashtag
4
+ include Singleton, Base
5
+
6
+ private
7
+
8
+ def history_file
9
+ "#{App::DATA_DIR}/hashtags"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Twterm
2
+ module History
3
+ class ScreenName
4
+ include Singleton, Base
5
+
6
+ private
7
+
8
+ def history_file
9
+ "#{App::DATA_DIR}/screen_names"
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/twterm/status.rb CHANGED
@@ -42,6 +42,10 @@ module Twterm
42
42
 
43
43
  @touched_at = Time.now
44
44
 
45
+ tweet.hashtags.each do |hashtag|
46
+ History::Hashtag.instance.add(hashtag.text)
47
+ end
48
+
45
49
  @@instances[id] = self
46
50
  end
47
51
 
@@ -64,14 +68,17 @@ module Twterm
64
68
  end
65
69
 
66
70
  def favorite!
71
+ @favorite_count += 1
67
72
  @favorited = true
68
73
  end
69
74
 
70
75
  def unfavorite!
76
+ @favorite_count -= 1
71
77
  @favorited = false
72
78
  end
73
79
 
74
80
  def retweet!
81
+ @retweet_count += 1
75
82
  @retweeted = true
76
83
  end
77
84
 
@@ -48,10 +48,10 @@ module Twterm
48
48
  Thread.new do
49
49
  Notifier.instance.show_message('Loading lists ...')
50
50
  Client.current.lists do |lists|
51
- @@lists = lists
51
+ @@lists = lists.sort_by(&:full_name)
52
52
  show_lists
53
53
  update_scrollbar_length
54
- @window.refresh
54
+ @window.refresh if TabManager.instance.current_tab == self
55
55
  end
56
56
  end if @@lists.nil?
57
57
 
@@ -26,7 +26,7 @@ module Twterm
26
26
  input_thread = Thread.new do
27
27
  close_screen
28
28
  puts "\ninput search query"
29
- query = readline('input query > ').strip
29
+ query = (readline('input query > ') || '').strip
30
30
  resetter.call
31
31
 
32
32
  tab = query.nil? || query.empty? ? Tab::New::Start.new : Tab::SearchTab.new(query)
@@ -26,7 +26,7 @@ module Twterm
26
26
  input_thread = Thread.new do
27
27
  close_screen
28
28
  puts "\nSearch user"
29
- screen_name = readline('> @').strip
29
+ screen_name = (readline('> @') || '').strip
30
30
  resetter.call
31
31
 
32
32
  Client.current.show_user(screen_name) do |user|
@@ -23,12 +23,42 @@ module Twterm
23
23
 
24
24
  thread = Thread.new do
25
25
  close_screen
26
+
26
27
  if @in_reply_to.nil?
27
28
  puts "\nCompose new tweet:"
28
29
  else
29
30
  puts "\nReply to @#{@in_reply_to.user.screen_name}'s tweet: \"#{@in_reply_to.text}\""
30
31
  end
31
- @status = readline(@in_reply_to.nil? ? '> ' : " @#{in_reply_to.user.screen_name} ", true)
32
+
33
+ Readline.completion_append_character = ' '
34
+ Readline.basic_word_break_characters = " \t\n\"\\'`$><=;|&{("
35
+ Readline.completion_proc = proc do |str|
36
+ if str.start_with?('#')
37
+ History::Hashtag.instance.history
38
+ .map { |tag| "##{tag}" }
39
+ .select { |tag| tag.downcase.start_with?(str.downcase) }
40
+ elsif str.start_with?('@')
41
+ History::ScreenName.instance.history
42
+ .map { |name| "@#{name}" }
43
+ .select! { |name| name.downcase.start_with?(str.downcase) }
44
+ else
45
+ []
46
+ end
47
+ end
48
+
49
+ loop do
50
+ msg = @in_reply_to.nil? || !@status.empty? ? '> ' : "> @#{in_reply_to.user.screen_name} "
51
+ line = (readline(msg, true) || '').strip
52
+ break if line.empty?
53
+
54
+ if line.end_with?('\\')
55
+ @status << line.chop.lstrip + "\n"
56
+ else
57
+ @status << line
58
+ break
59
+ end
60
+ end
61
+
32
62
  resetter.call
33
63
  post
34
64
  end
@@ -44,7 +74,7 @@ module Twterm
44
74
  end
45
75
 
46
76
  def post
47
- return if @status.nil?
77
+ return if @status.nil? || @status.empty?
48
78
 
49
79
  Client.current.post(@status, @in_reply_to)
50
80
  clear
data/lib/twterm/user.rb CHANGED
@@ -34,6 +34,9 @@ module Twterm
34
34
  @statuses_count = user.statuses_count
35
35
  @friends_count = user.friends_count
36
36
  @followers_count = user.followers_count
37
+
38
+ History::ScreenName.instance.add(user.screen_name)
39
+
37
40
  self
38
41
  end
39
42
  end
@@ -1,3 +1,3 @@
1
1
  module Twterm
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
data/lib/twterm.rb CHANGED
@@ -17,6 +17,9 @@ require 'twterm/auth'
17
17
  require 'twterm/client'
18
18
  require 'twterm/color_manager'
19
19
  require 'twterm/config'
20
+ require 'twterm/history/base'
21
+ require 'twterm/history/hashtag'
22
+ require 'twterm/history/screen_name'
20
23
  require 'twterm/list'
21
24
  require 'twterm/notification/base'
22
25
  require 'twterm/notification/message'
@@ -47,6 +50,6 @@ require 'twterm/version'
47
50
 
48
51
  module Twterm
49
52
  class Conf
50
- REQUIRE_VERSION = '1.0.2'
53
+ REQUIRE_VERSION = '1.0.4'
51
54
  end
52
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twterm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Kameoka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -129,6 +129,9 @@ files:
129
129
  - lib/twterm/client.rb
130
130
  - lib/twterm/color_manager.rb
131
131
  - lib/twterm/config.rb
132
+ - lib/twterm/history/base.rb
133
+ - lib/twterm/history/hashtag.rb
134
+ - lib/twterm/history/screen_name.rb
132
135
  - lib/twterm/list.rb
133
136
  - lib/twterm/notification/base.rb
134
137
  - lib/twterm/notification/error.rb