From 965e7208ad8a22c2e203e94258ec1dc42ee531ef Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sat, 29 Jul 2017 01:36:05 +0200 Subject: Reuse HexDump in monitor-cmd --- src/monitor-cmd.cc | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'src/monitor-cmd.cc') diff --git a/src/monitor-cmd.cc b/src/monitor-cmd.cc index ba02703..8aa8b99 100644 --- a/src/monitor-cmd.cc +++ b/src/monitor-cmd.cc @@ -11,6 +11,8 @@ #include "args.hh" #include "buffer.hh" +#include "gui_hexdump.hh" +#include "gui_plainattrtext.hh" #include "io.hh" #include "ios_save.hh" #include "looper.hh" @@ -120,50 +122,14 @@ private: } out_ << "* Size: " << size << '\n'; if (size > 0) { - ios_save save(out_); - auto d = reinterpret_cast(data); - out_.flags(std::ios::hex); - out_.fill('0'); - for (size_t i = 0; i < size; i += 16) { - out_ << std::setw(8) << i << ' '; - unsigned j = 0; - for (; j < 8; ++j) { - auto k = i + j; - if (k >= size) break; - out_ << ' ' << std::setw(2) << static_cast(d[k]); - } - for (; j < 8; ++j) { - out_ << " "; - } - out_ << ' '; - for (; j < 16; ++j) { - auto k = i + j; - if (k >= size) break; - out_ << ' ' << std::setw(2) << static_cast(d[k]); - } - for (; j < 16; ++j) { - out_ << " "; - } - out_ << " |"; - j = 0; - for (; j < 16; ++j) { - auto k = i + j; - if (k >= size) break; - out_ << printable(data[k]); - } - for (; j < 16; ++j) { - out_ << ' '; - } - out_ << "|\n"; - } + std::unique_ptr text(PlainAttributedText::create()); + HexDump::write(text.get(), HexDump::ADDRESS | HexDump::CHARS + | HexDump::ASCII, data, 0, size); + out_ << text->text(); } out_ << std::endl; } - static char printable(char c) { - return (c & 0x80 || c < ' ' || c >= 0x7f) ? '.' : c; - } - std::ostream& out_; bool interleave_; Looper* looper_; -- cgit v1.2.3-70-g09d2