1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-26 23:33:03 +00:00

fix interface for wallets list

This commit is contained in:
Adrien Waksberg 2017-02-21 21:05:28 +01:00
parent 35a4cd47e4
commit 4b6de3575a
3 changed files with 38 additions and 30 deletions

View file

@ -186,6 +186,7 @@ en:
port: "Port" port: "Port"
protocol: "Protocol" protocol: "Protocol"
server: "Server" server: "Server"
wallets: "Wallets"
warning: "Warning" warning: "Warning"
formats: formats:

View file

@ -186,6 +186,7 @@ fr:
port: "Port" port: "Port"
protocol: "Protocol" protocol: "Protocol"
server: "Serveur" server: "Serveur"
wallets: "Porte-feuilles"
warning: "Warning" warning: "Warning"
formats: formats:

View file

@ -114,27 +114,7 @@ class Cli
# List gpg keys in wallet # List gpg keys in wallet
def list_keys def list_keys
i = 1 table_list('keys', @mpw.list_keys)
length = 0
@mpw.list_keys.each do |key|
length = key.length if length < key.length
end
length += 7
puts "\n#{I18n.t('display.keys')}".red
print ' '
length.times { print '=' }
print "\n"
@mpw.list_keys.each do |key|
print " #{i}".cyan
(3 - i.to_s.length).times { print ' ' }
puts "| #{key}"
i += 1
end
print "\n"
end end
# Load config # Load config
@ -160,8 +140,33 @@ class Cli
exit 2 exit 2
end end
# Format list on a table
def table_list(title, list)
i = 1
length = 0
list.each do |item|
length = item.length if length < item.length
end
length += 7
puts "\n#{I18n.t("display.#{title}")}".red
print ' '
length.times { print '=' }
print "\n"
list.each do |item|
print " #{i}".cyan
(3 - i.to_s.length).times { print ' ' }
puts "| #{item}"
i += 1
end
print "\n"
end
# Format items on a table # Format items on a table
def table(items=[]) def table_items(items=[])
group = '.' group = '.'
i = 1 i = 1
length_total = 10 length_total = 10
@ -248,7 +253,7 @@ class Cli
if result.length == 0 if result.length == 0
puts I18n.t('display.nothing') puts I18n.t('display.nothing')
else else
table(result) table_items(result)
end end
end end
@ -334,11 +339,12 @@ class Cli
# List all wallets # List all wallets
def list_wallet def list_wallet
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") wallets = []
Dir.glob("#{@config.wallet_dir}/*.mpw").each do |f|
wallets.each do |wallet| wallets << File.basename(f, '.mpw')
puts File.basename(wallet, '.mpw')
end end
table_list('wallets', wallets)
end end
# Display the wallet # Display the wallet
@ -442,7 +448,7 @@ class Cli
if items.length == 0 if items.length == 0
puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
else else
table(items) if items.length > 1 table_items(items) if items.length > 1
item = get_item(items) item = get_item(items)
options = text_editor('update_form', item) options = text_editor('update_form', item)
@ -467,7 +473,7 @@ class Cli
if items.length == 0 if items.length == 0
puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
else else
table(items) table_items(items)
item = get_item(items) item = get_item(items)
confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s
@ -495,7 +501,7 @@ class Cli
if items.length == 0 if items.length == 0
puts I18n.t('display.nothing') puts I18n.t('display.nothing')
else else
table(items) table_items(items)
item = get_item(items) item = get_item(items)
clipboard(item, clipboard) clipboard(item, clipboard)