lib/ayadn/view.rb in ayadn-1.8.2 vs lib/ayadn/view.rb in ayadn-2.0
- old
+ new
@@ -2,10 +2,12 @@
module Ayadn
class View
def initialize
@workers = Workers.new
+ @thor = Thor::Shell::Basic.new
+ @status = Status.new
end
def show_cursor
puts "\e[?25h"
end
@@ -56,27 +58,27 @@
users_list, table = @workers.build_starred_list(list, target)
puts @workers.build_users_list(users_list, table)
puts "\n"
end
- def show_list_followings(list, target)
- puts @workers.build_followings_list(list, target)
+ def show_list_followings(list, target, options = {})
+ puts @workers.build_followings_list(list, target, options)
puts "\n"
end
- def show_list_followers(list, target)
- puts @workers.build_followers_list(list, target)
+ def show_list_followers(list, target, options = {})
+ puts @workers.build_followers_list(list, target, options)
puts "\n"
end
- def show_list_muted(list)
- puts @workers.build_muted_list(list)
+ def show_list_muted(list, options = {})
+ puts @workers.build_muted_list(list, options)
puts "\n"
end
- def show_list_blocked(list)
- puts @workers.build_blocked_list(list)
+ def show_list_blocked(list, options = {})
+ puts @workers.build_blocked_list(list, options)
puts "\n"
end
def show_interactions(stream)
#puts "\n"
@@ -87,17 +89,20 @@
puts build_files_list(list)
end
def show_settings
table = Terminal::Table.new do |t|
- t.style = { :width => Settings.options[:formats][:table][:width], border_x: ' ', border_i: ' ', border_y: ' ' }
+ if Settings.options[:formats][:table][:borders] == true
+ t.style = { :width => Settings.options[:formats][:table][:width], border_x: '—', border_i: '+', border_y: '|' }
+ else
+ t.style = { :width => Settings.options[:formats][:table][:width], border_x: ' ', border_i: ' ', border_y: ' ' }
+ end
t.title = "Current Ayadn settings".color(:cyan)
t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ]
@iter = 0
opts = Settings.options.dup
opts.each do |k,v|
- v.delete_if {|ke,_| ke == :deleted || ke == :annotations} # don't show immutable values
v.each do |x,y|
t << :separator if @iter >= 1 && Settings.options[:timeline][:compact] == false
unless y.is_a?(Hash)
t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), y.to_s.color(:green) ]
else
@@ -109,24 +114,33 @@
end
end
end
clear_screen()
puts table
+ puts "\n"
end
def show_userinfos(content, token, show_ranks = false)
+ if Settings.options[:timeline][:compact] == true
+ padding = "\n"
+ view = "\n"
+ else
+ padding = "\n\n"
+ view = ""
+ end
+
if content['name']
- view = "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name])
+ view << "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name])
else
- view = "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
+ view << "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
end
- view << "\n\nUsername\t\t".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:id])
+ view << "#{padding}Username\t\t".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
- view << "\n\nID\t\t\t".color(:cyan) + content['id'].color(Settings.options[:colors][:username])
+ view << "#{padding}ID\t\t\t".color(:cyan) + content['id'].color(Settings.options[:colors][:id])
- view << "\n\nURL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.options[:colors][:link])
+ view << "#{padding}URL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.options[:colors][:link])
unless content['verified_domain'].nil?
if content['verified_domain'] =~ (/http/ || /https/)
domain = content['verified_domain']
else
@@ -134,41 +148,41 @@
end
view << "\nVerified domain\t\t".color(:cyan) + domain.color(Settings.options[:colors][:link])
end
- view << "\n\nAccount creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(:green)
- view << "\n\nTimeZone\t\t".color(:cyan) + content['timezone'].color(:green)
- view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(:green)
+ view << "#{padding}Account creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(Settings.options[:colors][:excerpt])
+ view << "#{padding}TimeZone\t\t".color(:cyan) + content['timezone'].color(Settings.options[:colors][:excerpt])
+ view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(Settings.options[:colors][:excerpt])
- view << "\n\nPosts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(:green)
+ view << "#{padding}Posts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(Settings.options[:colors][:excerpt])
unless show_ranks == false
# this is ok for one user, but do not call this in a loop
# do call them all at once instead if many
ranks = NiceRank.new.get_posts_day([content['id'].to_i])
unless ranks.empty?
- view << "\n\nPosts/day\t\t".color(:cyan) + ranks[0][:posts_day].to_s.color(:green)
+ view << "#{padding}Posts/day\t\t".color(:cyan) + ranks[0][:posts_day].to_s.color(Settings.options[:colors][:excerpt])
end
end
- view << "\n\nFollowing\t\t".color(:cyan) + content['counts']['following'].to_s.color(:green)
- view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(:green)
+ view << "#{padding}Following\t\t".color(:cyan) + content['counts']['following'].to_s.color(Settings.options[:colors][:excerpt])
+ view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(Settings.options[:colors][:excerpt])
if content['username'] == Settings.config[:identity][:username] && !token.nil?
- view << "\n\nStorage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(:red)
- view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(:green)
+ view << "#{padding}Storage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(Settings.options[:colors][:excerpt])
+ view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(Settings.options[:colors][:excerpt])
end
#view << "\nStars\t\t\t".color(:cyan) + content['counts']['stars'].to_s.color(:yellow)
unless content['username'] == Settings.config[:identity][:username]
if content['you_follow']
- view << "\n\nYou follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
+ view << "#{padding}You follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
else
- view << "\n\nYou don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
+ view << "#{padding}You don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
end
if content['follows_you']
view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " follows you".color(:cyan)
else
view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " doesn't follow you".color(:cyan)
@@ -180,11 +194,11 @@
view << "\nYou blocked " + "@#{content['username']}".color(Settings.options[:colors][:username])
end
end
unless content['annotations'].empty?
- view << "\n"
+ view << "\n" unless Settings.options[:timeline][:compact] == true
end
content['annotations'].each do |anno|
case anno['type']
when "net.app.core.directory.blog"
view << "\nBlog\t\t\t".color(:cyan) + "#{anno['value']['url']}".color(Settings.options[:colors][:link])
@@ -194,36 +208,62 @@
view << "\nBirthday\t\t".color(:cyan) + "#{anno['value']['birthday']}".color(:green)
end
end
- #view << "\n\nAvatar URL\t\t".color(:cyan) + content['avatar_image']['url']
+ #view << "#{padding}Avatar URL\t\t".color(:cyan) + content['avatar_image']['url']
if content['description']
- view << "\n\n#{content['description']['text']}\n".color(:magenta) + "\n\n"
+ mentions = content['description']['entities']['mentions'].map {|m| "@#{m['name']}"}
+ hashtags = content['description']['entities']['hashtags'].map {|m| m['name']}
+ view << "#{padding}#{@workers.colorize_text(content['description']['text'], mentions, hashtags)}\n"
+ view << "\n" unless Settings.options[:timeline][:compact] == true
end
+ view << "\n" if Settings.options[:timeline][:compact] == true
+
puts view
end
def show_channels(resp, options = {})
view = ""
bucket = @workers.build_channels(resp['data'], options)
bucket.reverse.each do |ch|
- view << "\n"
- ch_alias = false
- Databases.aliases.each do |k,v|
- if v == "#{ch.id}"
- ch_alias = k
- break
+ if options[:broadcasts]
+ next if ch.type != "net.app.core.broadcast"
+ end
+ if options[:"no-broadcasts"]
+ next if ch.type == "net.app.core.broadcast"
+ end
+ if options[:messages]
+ next if ch.type != "net.app.core.pm"
+ end
+ if options[:"no-messages"]
+ next if ch.type == "net.app.core.pm"
+ end
+ if options[:patter]
+ next if ch.type != "net.patter-app.room"
+ end
+ if options[:"no-patter"]
+ next if ch.type == "net.patter-app.room"
+ end
+ if options[:other]
+ case ch.type
+ when "net.app.core.pm", "net.app.core.broadcast", "net.patter-app.room"
+ next
end
end
+ if options[:"no-other"]
+ next if ch.type != "net.app.core.pm" || ch.type != "net.app.core.broadcast" || ch.type != "net.patter-app.room"
+ end
+ view << "\n"
view << "ID: ".color(:cyan)
view << "#{ch.id}".color(Settings.options[:colors][:id])
view << "\n"
- if ch_alias
+ ch_alias = Databases.get_alias_from_id(ch.id)
+ unless ch_alias.nil?
view << "Alias: ".color(:cyan)
view << "#{ch_alias}".color(Settings.options[:colors][:username])
view << "\n"
end
view << "Messages: ".color(:cyan)
@@ -239,11 +279,11 @@
view << "Writers: ".color(:cyan)
view << "#{ch.writers}".color(Settings.options[:colors][:name])
view << "\n"
end
view << "Type: ".color(:cyan)
- view << "#{ch.type}".color(Settings.options[:colors][:id])
+ view << "#{ch.type}".color(Settings.options[:colors][:index])
view << "\n"
if ch.type == "net.patter-app.room"
ann = ch.annotations.select {|a| a['type'] == "net.patter-app.settings"}
view << "Name: ".color(:cyan)
view << "#{ann[0]['value']['name']}".color(Settings.options[:colors][:link])
@@ -282,12 +322,15 @@
view << ann[0]['value']['content']
view << "\n"
end
view << "\n\n"
end
- view << "\nYour account is currently linked to #{bucket.length} channels.\n\n".color(:green) unless options[:channels] || options[:id]
puts view
+ unless options[:channels] || options[:id]
+ @status.info("info", "your account is currently linked to #{bucket.length} channels", "cyan")
+ puts "\n"
+ end
end
def render(stream, options = {}, niceranks = {})
unless options[:raw]
get(stream['data'], options, niceranks)
@@ -308,77 +351,77 @@
def clear_screen
puts "\e[H\e[2J"
end
def page msg
- clear_screen
+ # clear_screen
+ puts "\n"
puts msg
puts "\n"
end
def winsize
IO.console.winsize
end
def show_links(links)
- links.each {|l| puts "#{l}\n".color(Settings.options[:colors][:link])}
+ links.each {|l| puts "#{l}".color(Settings.options[:colors][:link])}
end
def all_hashtag_links(stream, hashtag)
clear_screen()
- puts "Links from posts containing hashtag '##{hashtag}': \n".color(:cyan)
+ @status.info("info", "links from posts containing hashtag '##{hashtag}':", "cyan")
links = @workers.links_from_posts(stream)
links.uniq!
show_links(links)
@workers.save_links(links, "hashtag", hashtag)
end
def all_search_links(stream, words)
clear_screen()
- puts "Links from posts containing word(s) '#{words}': \n".color(:cyan)
+ @status.info("info", "links from posts containing word(s) '#{words}':", "cyan")
links = @workers.links_from_posts(stream)
links.uniq!
show_links(links)
@workers.save_links(links, "search", words)
end
def all_stars_links(stream)
clear_screen()
- puts "Links from your starred posts: \n".color(:cyan)
+ @status.info("info", "links from your starred posts:", "cyan")
links = @workers.links_from_posts(stream)
links.uniq!
show_links(links)
@workers.save_links(links, 'starred')
end
def infos(stream, token)
- clear_screen()
show_userinfos(stream, token, true)
end
def downloading(options = {})
unless options[:raw]
clear_screen()
- print Status.downloading
+ @status.downloading
end
end
- def list(what, list, target)
+ def list(what, list, target, options = {})
clear_screen()
case what
when :whoreposted
show_list_reposted(list, target)
when :whostarred
show_list_starred(list, target)
when :followings
- show_list_followings(list, target)
+ show_list_followings(list, target, options)
when :followers
- show_list_followers(list, target)
+ show_list_followers(list, target, options)
when :muted
- show_list_muted(list)
+ show_list_muted(list, options)
when :blocked
- show_list_blocked(list)
+ show_list_blocked(list, options)
end
end
def big_separator
"----------\n\n\n"
@@ -386,25 +429,29 @@
private
def get_broadcast_alias_from_id(event_id)
al = Databases.get_alias_from_id(event_id)
- al.nil? ? event_id : al
+ if al.nil? || al.empty?
+ return event_id
+ else
+ return al
+ end
end
def filter_nicerank posts, options
if options[:filter] == true # if this option is true in Action (it's only for global, actually)
if Settings.options[:nicerank][:filter] == true
filtered = {}
posts.each do |id,content|
- if Settings.options[:nicerank][:filter_unranked] == true
+ if Settings.options[:nicerank][:unranked] == true
next if content[:nicerank] == false
end
unless content[:nicerank] == false
next if content[:nicerank] < Settings.options[:nicerank][:threshold]
- next if content[:is_human] == false
- next if content[:real_person] == false
+ next if content[:is_human] == 0
+ next if content[:real_person] == 0
end
filtered[id] = content
end
return filtered
end
@@ -508,11 +555,15 @@
when "welcome"
inter << "App.net ".color(:cyan)
inter << "welcomed ".color(:green)
inter << "you!".color(:yellow)
end
- inter << "\n\n"
+ if Settings.options[:timeline][:compact] == true
+ inter << "\n"
+ else
+ inter << "\n\n"
+ end
end
inter
end
def build_files_list(list)
@@ -587,22 +638,30 @@
end
def build_header(content)
header = ""
header << content[:handle].color(Settings.options[:colors][:username])
- if Settings.options[:timeline][:show_real_name]
+ if Settings.options[:timeline][:name]
header << " "
header << content[:name].color(Settings.options[:colors][:name])
end
- if Settings.options[:timeline][:show_date]
+ if Settings.options[:timeline][:date]
header << " "
- header << content[:date].color(Settings.options[:colors][:date])
+ if Settings.global[:scrolling] == false
+ header << content[:date].color(Settings.options[:colors][:date])
+ else
+ if Settings.options[:scroll][:date] == false
+ header << content[:date_short].color(Settings.options[:colors][:date])
+ else
+ header << content[:date].color(Settings.options[:colors][:date])
+ end
+ end
end
- if Settings.options[:timeline][:show_source]
+ if Settings.options[:timeline][:source]
header << " "
header << "[#{content[:source_name]}]".color(Settings.options[:colors][:source])
end
- if Settings.options[:timeline][:show_symbols]
+ if Settings.options[:timeline][:symbols]
header << " <".color(Settings.options[:colors][:symbols]) if content[:is_reply]
header << " #{content[:num_stars]}*".color(Settings.options[:colors][:symbols]) if content[:is_starred]
header << " #{content[:num_reposts]}x".color(Settings.options[:colors][:symbols]) if content[:num_reposts] > 0
header << " >".color(Settings.options[:colors][:symbols]) if content[:num_replies] > 0
end