Class: Leeloo::Terminal

Inherits:
Ascii show all
Defined in:
lib/leeloo/output.rb

Instance Method Summary collapse

Methods inherited from Ascii

#render_footprint, #render_name_and_secret, #render_secret, #render_text

Methods inherited from Output

#render_footprint, #render_name_and_secret, #render_secret, #render_share, #render_text

Instance Method Details

#render_keys(keys) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/leeloo/output.rb', line 93

def render_keys keys
    rows = []
    keys.each do |key|
        splitted = key.split('::')
        is_present = '*' if splitted[1] == 'true'
        rows << [splitted[0], is_present]
    end
    puts TTY::Table.new(header: ['Email', 'Selected'], rows: rows).render(:ascii)
end

#render_preferences(preferences) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/leeloo/output.rb', line 77

def render_preferences preferences
    rows = []
    default_keystore = preferences.default
    preferences.keystores.each do |keystore|
        is_default = '*' if keystore.name == default_keystore
        rows << [keystore.name, keystore.path, is_default ]
      end
      puts TTY::Table.new(header: ['Name', 'Path', 'Default'], rows: rows).render(:ascii)
end

#render_secrets(secrets) ⇒ Object



87
88
89
90
91
# File 'lib/leeloo/output.rb', line 87

def render_secrets secrets
    hash = {'Password Store' => []}
    secrets.sort_by(&:name).each { |secret| sort(hash['Password Store'], secret.name) }
    puts TTY::Tree.new(hash).render
end

#sort(array, element) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/leeloo/output.rb', line 103

def sort array, element
    if element
        e = element.split("/", 2)
        if e.length > 1
            found = false
            array.each do |a|
                if a.is_a? Hash
                    if a[e.first]
                        found = true
                        sort(a[e.first], e.last)
                        break
                    end
                end
            end

            unless found
                array << { e.first => sort([], e.last) }
            end
        else
            array << e.last
        end
    end
    array
end