Skip to content

Commit

Permalink
dynamic column width in rs-enumerate-devices -s
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Dec 26, 2023
1 parent 3a634c9 commit f3a20ea
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions tools/enumerate-devices/rs-enumerate-devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,25 +418,37 @@ int main(int argc, char** argv) try

if (short_view || compact_view)
{
cout << left << setw(30) << "Device Name"
<< setw(20) << "Serial Number"
<< setw(20) << "Firmware Version"
<< endl;

auto dev_info = []( rs2::device dev, rs2_camera_info info )
{
if( dev.supports( info ) )
return dev.get_info( info );
return "N/A";
};

size_t w_name = 28;
size_t w_sn = 18;
for( auto i = 0u; i < devices.size(); ++i )
{
auto dev = devices[i];

w_name = std::max( strlen( dev_info( dev, RS2_CAMERA_INFO_NAME ) ), w_name );
w_sn = std::max( strlen( dev_info( dev, RS2_CAMERA_INFO_SERIAL_NUMBER ) ), w_sn );
}
w_name += 2;
w_sn += 2;

cout << left << setw(w_name) << "Device Name"
<< setw(w_sn) << "Serial Number"
<< "Firmware Version"
<< endl;

for (auto i = 0u; i < devices.size(); ++i)
{
auto dev = devices[i];

cout << left << setw(30) << dev_info(dev,RS2_CAMERA_INFO_NAME)
<< setw(20) << dev_info(dev,RS2_CAMERA_INFO_SERIAL_NUMBER)
<< setw(20) << dev_info(dev,RS2_CAMERA_INFO_FIRMWARE_VERSION)
cout << left << setw(w_name) << dev_info(dev,RS2_CAMERA_INFO_NAME)
<< setw(w_sn) << dev_info(dev,RS2_CAMERA_INFO_SERIAL_NUMBER)
<< dev_info(dev,RS2_CAMERA_INFO_FIRMWARE_VERSION)
<< endl;
}

Expand Down

0 comments on commit f3a20ea

Please sign in to comment.