Preliminary attempt at right_clip alignment

pull/1314/head
eudoxos 6 years ago
parent 1f5f17622e
commit eaa11e940a

@ -36,8 +36,9 @@ int main(int, char *[])
spdlog::debug("This message should be displayed..");
// Customize msg format for all loggers
spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v");
spdlog::info("This an info message with custom format");
spdlog::set_pattern("[%H:%M:%S %z] %>4B [%^%>3l%$] [thread %t] %>30v");
spdlog::debug("This an info message with custom format");
spdlog::info("Nicely aligned with the previous message");
spdlog::set_pattern("%+"); // back to default format
spdlog::set_level(spdlog::level::info);

@ -42,7 +42,14 @@ public:
if (padinfo_.width_ <= wrapped_size)
{
total_pad_ = 0;
if (padinfo_.side_ == padding_info::clip_right)
{
total_pad_ = (long)padinfo_.width_ - (long)wrapped_size;
}
else
{
total_pad_ = 0;
}
return;
}
@ -70,16 +77,23 @@ public:
}
private:
void pad_it(size_t count)
void pad_it(long count)
{
// count = std::min(count, spaces_.size());
assert(count <= spaces_.size());
fmt_helper::append_string_view(string_view_t(spaces_.data(), count), dest_);
if ( count >= 0 )
{
fmt_helper::append_string_view(string_view_t(spaces_.data(), count), dest_);
}
else
{
dest_.resize(dest_.size()+count);
}
}
const padding_info &padinfo_;
memory_buf_t &dest_;
size_t total_pad_;
long total_pad_;
string_view_t spaces_{" ", 64};
};
@ -1233,6 +1247,10 @@ SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_(std::stri
side = padding_info::center;
++it;
break;
case '>':
side = padding_info::clip_right;
++it;
break;
default:
side = details::padding_info::left;
break;

@ -25,7 +25,8 @@ struct padding_info
{
left,
right,
center
center,
clip_right,
};
padding_info() = default;

Loading…
Cancel
Save