diff --git a/src/main.cpp b/src/main.cpp index 6bb97a6..584ae46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +#include #include #include #include @@ -216,8 +217,25 @@ int list_images_command(const std::filesystem::path& dir) { if (!images) { return 1; } + + std::vector refs; + refs.reserve(images->size()); + size_t max_len = 0; 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; }