summaryrefslogtreecommitdiff
path: root/src/monitor-cmd.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-07-29 01:36:05 +0200
committerJoel Klinghed <the_jk@yahoo.com>2017-07-29 01:36:05 +0200
commit965e7208ad8a22c2e203e94258ec1dc42ee531ef (patch)
tree6787b732ca77975ab0e966d0a18f1f14c104a2c6 /src/monitor-cmd.cc
parentee34164a6c1c4f905332cfcfef938a0ccb48333b (diff)
Reuse HexDump in monitor-cmd
Diffstat (limited to 'src/monitor-cmd.cc')
-rw-r--r--src/monitor-cmd.cc46
1 files changed, 6 insertions, 40 deletions
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<uint8_t const*>(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<int>(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<int>(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<PlainAttributedText> 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_;