Allow passing MaxChar to Rex::Ui::Text::Table cols

Passing MaxChar allows setting the maximum number of characters
printed within a specific column during the row_to_s method.
This does not affect CSV output nor truncate the actual data.
Meant for tidying up long console ouput.

Example: cleaned up cmd_creds to show proof and not maul tables
with unix session data.
bug/bundler_fix
RageLtMan 2013-07-10 20:00:40 -04:00
parent fca732d893
commit 987d6a671f
2 changed files with 21 additions and 8 deletions

View File

@ -794,11 +794,18 @@ class Db
# normalize
ports = port_ranges.flatten.uniq
svcs.flatten!
tbl_opts = {
'Header' => "Credentials",
'Columns' => [ 'host', 'port', 'user', 'pass', 'type', 'proof', 'active?' ]
}
tbl = Rex::Ui::Text::Table.new({
'Header' => "Credentials",
'Columns' => [ 'host', 'port', 'user', 'pass', 'type', 'active?' ],
})
tbl_opts.merge!(
'ColProps' => {
'pass' => { 'MaxChar' => 64 },
'proof' => { 'MaxChar' => 64 }
}
) if search_term.nil?
tbl = Rex::Ui::Text::Table.new(tbl_opts)
creds_returned = 0
# Now do the actual search
@ -828,8 +835,8 @@ class Db
end
row = [
cred.service.host.address, cred.service.port,
cred.user, cred.pass, cred.ptype,
(cred.active ? "true" : "false")
cred.user, cred.pass, cred.ptype, cred.proof,
cred.active.to_s
]
tbl << row
if mode == :delete

View File

@ -283,9 +283,15 @@ protected
if (last_cell)
line << pad(' ', last_cell.to_s, last_idx)
end
line << cell.to_s
# line << pad(' ', cell.to_s, idx)
last_cell = cell
# Limit wide cells
if colprops[idx]['MaxChar']
last_cell = cell.to_s[0..colprops[idx]['MaxChar'].to_i]
line << last_cell
else
line << cell.to_s
last_cell = cell
end
last_idx = idx
}