Align --list-images output on a tab stop
Pad each name:tag with enough tabs (not spaces) to reach one 8-column tab stop past the longest entry in the list, so filenames line up regardless of how much shorter other names/tags are. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+19
-1
@@ -14,6 +14,7 @@
|
|||||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@@ -216,8 +217,25 @@ int list_images_command(const std::filesystem::path& dir) {
|
|||||||
if (!images) {
|
if (!images) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> refs;
|
||||||
|
refs.reserve(images->size());
|
||||||
|
size_t max_len = 0;
|
||||||
for (const auto& ref : *images) {
|
for (const auto& ref : *images) {
|
||||||
fmt::print("{}:{}\t{}\n", ref.name, ref.tag, ref.path.filename().string());
|
refs.push_back(fmt::format("{}:{}", ref.name, ref.tag));
|
||||||
|
max_len = std::max(max_len, refs.back().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pad each entry with tabs (not spaces) so filenames line up on an 8-column tab
|
||||||
|
// stop past the longest name:tag, however long that is.
|
||||||
|
constexpr size_t kTabWidth = 8;
|
||||||
|
size_t target_tabs = max_len / kTabWidth + 1;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < images->size(); ++i) {
|
||||||
|
size_t tabs_used = refs[i].size() / kTabWidth;
|
||||||
|
size_t tabs_needed = target_tabs > tabs_used ? target_tabs - tabs_used : 1;
|
||||||
|
fmt::print("{}{}{}\n", refs[i], std::string(tabs_needed, '\t'),
|
||||||
|
(*images)[i].path.filename().string());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user