mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-19 12:59:30 +00:00
feat: replace host by url in table
This commit is contained in:
parent
a7a165bca9
commit
f91531b856
2 changed files with 32 additions and 12 deletions
|
@ -179,18 +179,21 @@ module MPW
|
||||||
data = { id: { length: 3, color: 'cyan' },
|
data = { id: { length: 3, color: 'cyan' },
|
||||||
host: { length: 9, color: 'yellow' },
|
host: { length: 9, color: 'yellow' },
|
||||||
user: { length: 7, color: 'green' },
|
user: { length: 7, color: 'green' },
|
||||||
protocol: { length: 9, color: 'white' },
|
|
||||||
port: { length: 5, color: 'white' },
|
|
||||||
otp: { length: 4, color: 'white' },
|
otp: { length: 4, color: 'white' },
|
||||||
comment: { length: 14, color: 'magenta' } }
|
comment: { length: 14, color: 'magenta' } }
|
||||||
|
|
||||||
items.each do |item|
|
items.each do |item|
|
||||||
data.each do |k, v|
|
data.each do |k, v|
|
||||||
next if k == :id || k == :otp
|
case k
|
||||||
|
when :id, :otp
|
||||||
|
next
|
||||||
|
when :host
|
||||||
|
v[:length] = item.url.length + 3 if item.url.length >= v[:length]
|
||||||
|
else
|
||||||
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
|
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
|
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
|
||||||
|
|
||||||
data.each_value { |v| length_total += v[:length] }
|
data.each_value { |v| length_total += v[:length] }
|
||||||
|
@ -231,17 +234,23 @@ module MPW
|
||||||
data.each do |k, v|
|
data.each do |k, v|
|
||||||
next if k == :id
|
next if k == :id
|
||||||
|
|
||||||
if k == :otp
|
|
||||||
print '| '
|
print '| '
|
||||||
|
|
||||||
|
case k
|
||||||
|
when :otp
|
||||||
item.otp ? (print ' X ') : 4.times { print ' ' }
|
item.otp ? (print ' X ') : 4.times { print ' ' }
|
||||||
|
|
||||||
next
|
when :host
|
||||||
end
|
print "#{item.protocol}://" if item.protocol
|
||||||
|
print item.host.send(v[:color])
|
||||||
|
print ":#{item.port}" if item.port
|
||||||
|
(v[:length] - item.url.to_s.length).times { print ' ' }
|
||||||
|
|
||||||
print '| '
|
else
|
||||||
print item.send(k.to_s).to_s.send(v[:color])
|
print item.send(k.to_s).to_s.send(v[:color])
|
||||||
(v[:length] - item.send(k.to_s).to_s.length).times { print ' ' }
|
(v[:length] - item.send(k.to_s).to_s.length).times { print ' ' }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
print "\n"
|
print "\n"
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
@ -81,6 +81,17 @@ module MPW
|
||||||
@last_edit = nil
|
@last_edit = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return data on url format
|
||||||
|
# @return [String] an url
|
||||||
|
def url
|
||||||
|
url = ''
|
||||||
|
url += "#{@protocol}://" if @protocol
|
||||||
|
url += @host
|
||||||
|
url += ":#{@port}" if @port
|
||||||
|
|
||||||
|
url
|
||||||
|
end
|
||||||
|
|
||||||
def empty?
|
def empty?
|
||||||
@id.to_s.empty?
|
@id.to_s.empty?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue