Skip to content

Commit

Permalink
[markdown] add support for github alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
tstack committed May 17, 2024
1 parent 54b391e commit 8d8467d
Show file tree
Hide file tree
Showing 21 changed files with 1,555 additions and 102 deletions.
1 change: 1 addition & 0 deletions src/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_library(
strnatcmp.h
time_util.hh
types.hh
wcwidth9.h

../third-party/xxHash/xxhash.h
../third-party/xxHash/xxhash.c
Expand Down
3 changes: 2 additions & 1 deletion src/base/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ noinst_HEADERS = \
string_util.hh \
strnatcmp.h \
time_util.hh \
types.hh
types.hh \
wcwidth9.h

libbase_a_SOURCES = \
ansi_scrubber.cc \
Expand Down
2 changes: 1 addition & 1 deletion src/base/attr_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ attr_line_t::erase(size_t pos, size_t len)
attr_line_t&
attr_line_t::pad_to(ssize_t size)
{
const auto curr_len = this->utf8_length_or_length();
const auto curr_len = this->column_width();

if (curr_len < size) {
this->append((size - curr_len), ' ');
Expand Down
19 changes: 15 additions & 4 deletions src/base/intern_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <string.h>

#include "config.h"
#include "fmt/ostream.h"
#include "pcrepp/pcre2pp.hh"
#include "ww898/cp_utf8.hpp"
#include "xxHash/xxhash.h"
Expand Down Expand Up @@ -416,9 +417,14 @@ string_fragment::sub_cell_range(int cell_start, int cell_end) const
cell_index += 1;
} while (cell_index % 8);
break;
default:
cell_index += wcwidth(read_res.unwrap());
default: {
auto wcw_res = wcwidth(read_res.unwrap());
if (wcw_res < 0) {
wcw_res = 1;
}
cell_index += wcw_res;
break;
}
}
}
}
Expand Down Expand Up @@ -456,9 +462,14 @@ string_fragment::column_width() const
retval += 1;
} while (retval % 8);
break;
default:
retval += wcwidth(read_res.unwrap());
default: {
auto wcw_res = wcwidth(read_res.unwrap());
if (wcw_res < 0) {
wcw_res = 1;
}
retval += wcw_res;
break;
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/base/intern_string.tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,17 @@ World!)");
CHECK(all_sf2 == "Hello,\nWorld!");
}
}

TEST_CASE("string_fragment::column_width")
{
{
const auto sf = string_fragment::from_const("Key(s)\n");

CHECK(7 == sf.column_width());
}
{
const auto sf = string_fragment::from_const("\u26a0");

CHECK(1 == sf.column_width());
}
}
7 changes: 6 additions & 1 deletion src/base/lnav.console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ println(FILE* file, const attr_line_t& al)
default:
break;
}
} else if (attr.sa_type == &VC_ROLE) {
} else if (attr.sa_type == &VC_ROLE
|| attr.sa_type == &VC_ROLE_FG)
{
auto saw = string_attr_wrapper<role_t>(&attr);
auto role = saw.get();

Expand Down Expand Up @@ -441,6 +443,9 @@ println(FILE* file, const attr_line_t& al)
line_style |= fmt::emphasis::bold
| fmt::fg(fmt::terminal_color::green);
break;
case role_t::VCR_FOOTNOTE_BORDER:
line_style |= fmt::fg(fmt::terminal_color::blue);
break;
case role_t::VCR_INFO:
case role_t::VCR_STATUS:
line_style |= fmt::emphasis::bold
Expand Down
7 changes: 7 additions & 0 deletions src/base/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "config.h"
#include "is_utf8.hh"
#include "lnav_log.hh"
#include "wcwidth9.h"

void
scrub_to_utf8(char* buffer, size_t length)
Expand Down Expand Up @@ -422,3 +423,9 @@ quote(string_fragment str)

} // namespace pcre2pp
} // namespace lnav

int
wcwidth(wchar_t wc)
{
return wcwidth9(wc);
}
Loading

0 comments on commit 8d8467d

Please sign in to comment.