ayadn 2.1 → 3.0

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.
@@ -13,7 +13,7 @@ module Ayadn
13
13
  def canceled
14
14
  say do
15
15
  puts "\n"
16
- @thor.say_status :canceled, "", :red
16
+ say_red :canceled, ""
17
17
  end
18
18
  end
19
19
 
@@ -34,51 +34,51 @@ module Ayadn
34
34
  end
35
35
 
36
36
  def deleting_post(post_id)
37
- @thor.say_status :deleting, "post #{post_id}", :yellow
37
+ say_yellow :deleting, "post #{post_id}"
38
38
  end
39
39
 
40
40
  def deleting_message(message_id)
41
- @thor.say_status :deleting, "message #{message_id}", :yellow
41
+ say_yellow :deleting, "message #{message_id}"
42
42
  end
43
43
 
44
44
  def unfollowing(username)
45
- @thor.say_status :unfollowing, username, :yellow
45
+ say_yellow :unfollowing, username
46
46
  end
47
47
 
48
48
  def following(username)
49
- @thor.say_status :following, username, :yellow
49
+ say_yellow :following, username
50
50
  end
51
51
 
52
52
  def unmuting(username)
53
- @thor.say_status :unmuting, username, :yellow
53
+ say_yellow :unmuting, username
54
54
  end
55
55
 
56
56
  def muting(username)
57
- @thor.say_status :muting, username, :yellow
57
+ say_yellow :muting, username
58
58
  end
59
59
 
60
60
  def unblocking(username)
61
- @thor.say_status :unblocking, username, :yellow
61
+ say_yellow :unblocking, username
62
62
  end
63
63
 
64
64
  def blocking(username)
65
- @thor.say_status :blocking, username, :yellow
65
+ say_yellow :blocking, username
66
66
  end
67
67
 
68
68
  def unreposting(post_id)
69
- @thor.say_status :unreposting, "post #{post_id}", :yellow
69
+ say_yellow :unreposting, "post #{post_id}"
70
70
  end
71
71
 
72
72
  def reposting(post_id)
73
- @thor.say_status :reposting, "post #{post_id}", :yellow
73
+ say_yellow :reposting, "post #{post_id}"
74
74
  end
75
75
 
76
76
  def unstarring(post_id)
77
- @thor.say_status :unstarring, "post #{post_id}", :yellow
77
+ say_yellow :unstarring, "post #{post_id}"
78
78
  end
79
79
 
80
80
  def starring(post_id)
81
- @thor.say_status :starring, "post #{post_id}", :yellow
81
+ say_yellow :starring, "post #{post_id}"
82
82
  end
83
83
 
84
84
  def not_deleted(post_id)
@@ -207,8 +207,8 @@ module Ayadn
207
207
 
208
208
  def error_missing_parameters
209
209
  say do
210
- @thor.say_status :error, "please submit valid items", :red
211
- @thor.say_status :info, "see `ayadn -sg` for a list of valid parameters and values", :cyan
210
+ say_error "please submit valid items"
211
+ say_info "see `ayadn -sg` for a list of valid parameters and values"
212
212
  end
213
213
  end
214
214
 
@@ -218,52 +218,52 @@ module Ayadn
218
218
 
219
219
  def writing
220
220
  puts "\n"
221
- @thor.say_status "author", "#{Settings.config[:identity][:handle]}", "cyan"
221
+ say_cyan :author, "#{Settings.config[:identity][:handle]}"
222
222
  puts "\n"
223
223
  end
224
224
 
225
225
  def yourmessage username = nil
226
226
  if username.nil?
227
- @thor.say_status "", "Your message:"
227
+ say_center "Your message:"
228
228
  else
229
- @thor.say_status "", "Your message to #{username}:"
229
+ say_center "Your message to #{username}:"
230
230
  end
231
231
  puts "\n\n"
232
232
  end
233
233
 
234
234
  def message_from(username)
235
235
  puts "\n"
236
- @thor.say_status "from", "#{Settings.config[:identity][:handle]}", "yellow"
237
- @thor.say_status "to", "#{username[0]}", "yellow"
236
+ say_yellow :from, "#{Settings.config[:identity][:handle]}"
237
+ say_yellow :to, "#{username[0]}"
238
238
  end
239
239
 
240
240
  def replying_to(post_id)
241
241
  puts "\n"
242
- @thor.say_status "replying", "to post #{post_id}", "yellow"
242
+ say_yellow :replying, "to post #{post_id}"
243
243
  end
244
244
 
245
245
  def readline
246
246
  say do
247
- @thor.say_status :next, "type your text", :cyan
248
- @thor.say_status :ok, "[CTRL+D] to validate", :cyan
249
- @thor.say_status :cancel, "[CTRL+C] to cancel", :cyan
247
+ say_cyan :next, "type your text"
248
+ say_cyan :ok, "[CTRL+D] to validate"
249
+ say_cyan :cancel, "[CTRL+C] to cancel"
250
250
  end
251
251
  end
252
252
 
253
253
  def reply
254
- @thor.say_status "max", "#{Settings.config[:post_max_length]} characters", "cyan"
254
+ say_cyan :max, "#{Settings.config[:post_max_length]} characters"
255
255
  end
256
256
 
257
257
  def post
258
- @thor.say_status "max", "#{Settings.config[:post_max_length]} characters", "cyan"
258
+ say_cyan :max, "#{Settings.config[:post_max_length]} characters"
259
259
  end
260
260
 
261
261
  def message
262
- @thor.say_status "max", "#{Settings.config[:message_max_length]} characters", "cyan"
262
+ say_cyan :max, "#{Settings.config[:message_max_length]} characters"
263
263
  end
264
264
 
265
265
  def valid_colors(colors_list)
266
- @thor.say_status "info", "valid colors:", "cyan"
266
+ say_cyan :info, "valid colors:"
267
267
  say { puts colors_list }
268
268
  end
269
269
 
@@ -301,8 +301,8 @@ module Ayadn
301
301
 
302
302
  def error_only_osx
303
303
  say do
304
- @thor.say_status :error, "this feature only works with iTunes by default", :red
305
- @thor.say_status :info, "if you've got a Last.fm account, use `ayadn -NP --lastfm` (short: `-l`)", :cyan
304
+ say_error "this feature only works with iTunes by default"
305
+ say_info "if you've got a Last.fm account, use `ayadn -NP --lastfm` (short: `-l`)"
306
306
  end
307
307
  end
308
308
 
@@ -312,8 +312,8 @@ module Ayadn
312
312
 
313
313
  def not_authorized
314
314
  say do
315
- @thor.say_status :error, "no user authorized", :red
316
- @thor.say_status :auth, "please run `ayadn -auth` to authorize an account", :yellow
315
+ say_error "no user authorized"
316
+ say_info "please run `ayadn -auth` to authorize an account"
317
317
  end
318
318
  end
319
319
 
@@ -323,8 +323,8 @@ module Ayadn
323
323
 
324
324
  def redirecting
325
325
  say do
326
- @thor.say_status :info, "post is a repost", :cyan
327
- @thor.say_status :action, "redirecting", :yellow
326
+ say_info "post is a repost"
327
+ say_yellow :action, "redirecting"
328
328
  end
329
329
  end
330
330
 
@@ -346,17 +346,17 @@ module Ayadn
346
346
 
347
347
  def auto
348
348
  say do
349
- @thor.say_status :info, "entering the auto posting mode", :cyan
350
- @thor.say_status :info, "each line you type (each time you hit ENTER) is automatically posted to ADN", :cyan
351
- @thor.say_status :info, "at any moment, starting now, hit CTRL+C to exit", :cyan
352
- @thor.say_status :info, "AUTO POSTING MODE ACTIVATED", :yellow
349
+ say_info "entering the auto posting mode"
350
+ say_info "each line you type (each time you hit ENTER) is automatically posted to ADN"
351
+ say_info "at any moment, starting now, hit CTRL+C to exit"
352
+ say_yellow :info, "AUTO POSTING MODE ACTIVATED"
353
353
  end
354
354
  end
355
355
 
356
356
  def threshold
357
357
  say do
358
- @thor.say_status :error, "please enter a value between 0.1 and 3.5", :red
359
- @thor.say_status :info, "example: 2.1", :green
358
+ say_error "please enter a value between 0.1 and 3.5"
359
+ say_green :info, "example: 2.1"
360
360
  end
361
361
  end
362
362
 
@@ -392,8 +392,8 @@ module Ayadn
392
392
  diff = size - max_size
393
393
  diff > 1 ? pl = "s" : pl = ""
394
394
  say do
395
- @thor.say_status :error, "text too long", :red
396
- @thor.say_status :info, "#{max_size} max: #{diff} character#{pl} to remove", :green
395
+ say_error "text too long"
396
+ say_green :info, "#{max_size} max: #{diff} character#{pl} to remove"
397
397
  end
398
398
  end
399
399
 
@@ -407,8 +407,8 @@ module Ayadn
407
407
 
408
408
  def no_curl
409
409
  say do
410
- @thor.say_status :error, "Ayadn needs 'curl' to upload files", :red
411
- @thor.say_status :next, "please install 'curl' (or check that it's properly declared in your $PATH)", :yellow
410
+ say_error "Ayadn needs 'curl' to upload files"
411
+ say_yellow :next, "please install 'curl' (or check that it's properly declared in your $PATH)"
412
412
  end
413
413
  end
414
414
 
@@ -434,8 +434,8 @@ module Ayadn
434
434
 
435
435
  def no_force(target)
436
436
  say do
437
- @thor.say_status :error, "'#{target}' can't be displayed (could be muted, blocked, in the Blacklist, etc)", :red
438
- @thor.say_status :info, "please use option '--force' ('-f') to try and display this content anyway", :cyan
437
+ say_error "'#{target}' can't be displayed (could be muted, blocked, in the Blacklist, etc)"
438
+ say_info "please use option '--force' ('-f') to try and display this content anyway"
439
439
  end
440
440
  end
441
441
 
@@ -449,15 +449,15 @@ module Ayadn
449
449
 
450
450
  def no_username
451
451
  say do
452
- @thor.say_status :error, "Ayadn couldn't get your username", :red
453
- @thor.say_status :next, "please try again", :yellow
452
+ say_error "Ayadn couldn't get your username"
453
+ say_yellow :next, "please try again"
454
454
  end
455
455
  end
456
456
 
457
- def has_to_migrate
457
+ def deprecated_ayadn
458
458
  say do
459
- @thor.say_status :upgrade, "Ayadn 1.x user data detected", :red
460
- @thor.say_status :migrate, "please run `ayadn migrate` to upgrade your account", :yellow
459
+ say_red :deprecated, "Ayadn 1.x user data detected"
460
+ say_yellow :warning, "please delete your old ayadn folder then try again"
461
461
  end
462
462
  end
463
463
 
@@ -471,7 +471,7 @@ module Ayadn
471
471
 
472
472
  def yourpost
473
473
  # info("", "Your post:")
474
- @thor.say_status nil, "Your post:"
474
+ say_center "Your post:"
475
475
  end
476
476
 
477
477
  def post_info
@@ -483,7 +483,7 @@ module Ayadn
483
483
  end
484
484
 
485
485
  def unread_from_channel(channel_id)
486
- @thor.say_status :info, "unread message(s) from channel #{channel_id}", :cyan
486
+ say_info "unread message(s) from channel #{channel_id}"
487
487
  puts "\n\n"
488
488
  end
489
489
 
@@ -500,9 +500,9 @@ module Ayadn
500
500
  end
501
501
  def version
502
502
  puts ayadn()
503
- @thor.say_status :version, "#{VERSION}", :green
504
- @thor.say_status :changelog, "https://github.com/ericdke/na/blob/master/CHANGELOG.md", :yellow
505
- @thor.say_status :docs, "https://github.com/ericdke/na/tree/master/doc", :yellow
503
+ say_green :version, "#{VERSION}"
504
+ say_yellow :changelog, "https://github.com/ericdke/na/blob/master/CHANGELOG.md"
505
+ say_yellow :docs, "https://github.com/ericdke/na/tree/master/doc"
506
506
  puts "\n\n"
507
507
  end
508
508
 
@@ -524,19 +524,19 @@ module Ayadn
524
524
 
525
525
  def itunes_store_track(store)
526
526
  puts "\n"
527
- @thor.say_status "next", "Ayadn will use these elements to insert album artwork and a link", :cyan
527
+ say_cyan :next, "Ayadn will use these elements to insert album artwork and a link"
528
528
  end
529
529
 
530
530
  def server_error(bool)
531
531
  if bool == true
532
532
  say do
533
- @thor.say_status :error, "Ayadn couldn't get the JSON reponse", :red
534
- @thor.say_status :next, "trying again in 10 seconds", :yellow
533
+ say_error "Ayadn couldn't get the JSON reponse"
534
+ say_yellow :next, "trying again in 10 seconds"
535
535
  end
536
536
  else
537
537
  say do
538
- @thor.say_status :error, "Ayadn couldn't get the JSON reponse", :red
539
- @thor.say_status :status, "Current command canceled after one retry", :yellow
538
+ say_error "Ayadn couldn't get the JSON reponse"
539
+ say_yellow :status, "Current command canceled after one retry"
540
540
  end
541
541
  end
542
542
  end
@@ -545,7 +545,7 @@ module Ayadn
545
545
 
546
546
  def info(status, message, color = nil)
547
547
  if color.nil?
548
- lamb = lambda { @thor.say_status(status.to_sym, message.to_s) }
548
+ lamb = lambda { say_nocolor(status.to_sym, message.to_s) }
549
549
  else
550
550
  lamb = lambda { @thor.say_status(status.to_sym, message.to_s, color.to_sym) }
551
551
  end
@@ -560,5 +560,57 @@ module Ayadn
560
560
  puts "\n"
561
561
  end
562
562
 
563
+ def say_center(message)
564
+ @thor.say_status nil, message
565
+ end
566
+
567
+ def say_nocolor(tag, message)
568
+ @thor.say_status tag, message
569
+ end
570
+
571
+ def say_error(message)
572
+ @thor.say_status :error, message, :red
573
+ end
574
+
575
+ def say_info(message)
576
+ @thor.say_status :info, message, :cyan
577
+ end
578
+
579
+ def say_green(tag, message)
580
+ @thor.say_status tag, message, :green
581
+ end
582
+
583
+ def say_blue(tag, message)
584
+ @thor.say_status tag, message, :blue
585
+ end
586
+
587
+ def say_cyan(tag, message)
588
+ @thor.say_status tag, message, :cyan
589
+ end
590
+
591
+ def say_red(tag, message)
592
+ @thor.say_status tag, message, :red
593
+ end
594
+
595
+ def say_yellow(tag, message)
596
+ @thor.say_status tag, message, :yellow
597
+ end
598
+
599
+ def say_end
600
+ say { say_green :done, "end of diagnostics" }
601
+ end
602
+
603
+ def say_header(message)
604
+ say { say_info message }
605
+ end
606
+
607
+ def say_text(text)
608
+ say { puts text }
609
+ end
610
+
611
+ def say_trace(message)
612
+ @thor.say_status :message, message, :yell
613
+ end
614
+
563
615
  end
564
616
  end
@@ -3,6 +3,8 @@ module Ayadn
3
3
 
4
4
  class Stream
5
5
 
6
+ require_relative("scroll")
7
+
6
8
  def initialize api, view, workers
7
9
  @api = api
8
10
  @view = view
@@ -3,13 +3,20 @@ module Ayadn
3
3
  class Switch
4
4
 
5
5
  def initialize
6
- @thor = Thor::Shell::Color.new # local statuses
7
- @status = Status.new # global statuses + utils
8
- @acc_db = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite")
6
+ @status = Status.new
7
+ begin
8
+ @acc_db = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite")
9
+ rescue Amalgalite::SQLite3::Error => e
10
+ @status.not_authorized
11
+ exit
12
+ rescue => e
13
+ raise e
14
+ end
9
15
  end
10
16
 
11
17
  def list
12
18
  puts "\n"
19
+ please if @acc_db.blank?
13
20
  accounts = Databases.all_accounts(@acc_db)
14
21
  please if accounts.empty?
15
22
  accounts.sort_by! { |acc| acc[0] }
@@ -39,28 +46,29 @@ module Ayadn
39
46
  exit
40
47
  end
41
48
  username = Workers.new.remove_arobase_if_present([user.first])[0]
49
+ please if @acc_db.blank?
42
50
  accounts = Databases.all_accounts(@acc_db)
43
51
  please if accounts.empty?
44
52
  active = accounts.select { |acc| acc[4] == 1 }[0]
45
53
  active_user = active[0]
46
54
  if username == active_user
47
55
  @status.say do
48
- @thor.say_status :done, "already authorized with username @#{username}", :green
56
+ @status.say_green :done, "already authorized with username @#{username}"
49
57
  end
50
58
  exit
51
59
  end
52
60
  flag = accounts.select { |acc| acc[0] == username }.flatten
53
61
  if flag.empty?
54
62
  @status.say do
55
- @thor.say_status :error, "@#{username} isn't in the database", :red
56
- @thor.say_status :next, "please run `ayadn -auth` to authorize this account", :yellow
63
+ @status.say_error "@#{username} isn't in the database"
64
+ @status.say_yellow :next, "please run `ayadn -auth` to authorize this account"
57
65
  end
58
66
  exit
59
67
  else
60
68
  @status.say do
61
- @thor.say_status :switching, "from @#{active_user} to @#{username}", :cyan
69
+ @status.say_cyan :switching, "from @#{active_user} to @#{username}"
62
70
  Databases.set_active_account(@acc_db, username)
63
- @thor.say_status :done, "@#{username} is now the active account", :green
71
+ @status.say_green :done, "@#{username} is now the active account"
64
72
  end
65
73
  exit
66
74
  end
@@ -69,9 +77,8 @@ module Ayadn
69
77
  private
70
78
 
71
79
  def please
72
- @status.say do
73
- @thor.say_status :error, "please run `ayadn -auth` to authorize an account", :red
74
- end
80
+ @status.say_info "please run `ayadn -auth` to authorize an account"
81
+ puts
75
82
  exit
76
83
  end
77
84
  end