From f1e7b4a8e521f1fcbd7747670fda116636c79f4c Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 26 Nov 2019 07:50:51 -0500 Subject: [PATCH] demo: properly center wave on front page #50 --- src/bin/demo.c | 11 ++++++++--- src/bin/unicodeblocks.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bin/demo.c b/src/bin/demo.c index 6cd79bd23..a3628df5b 100644 --- a/src/bin/demo.c +++ b/src/bin/demo.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -150,11 +151,15 @@ int main(int argc, char** argv){ if(ncplane_putstr(ncp, str) != (int)strlen(str)){ goto err; } - const char bstr[] = "▏▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁▕"; - if(ncplane_cursor_move_yx(ncp, rows / 2 - 5, (cols - strlen(bstr) + 4) / 2)){ + const wchar_t wstr[] = L"▏▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁▕"; + char mbstr[128]; + if(wcstombs(mbstr, wstr, sizeof(mbstr)) <= 0){ goto err; } - if(ncplane_putstr(ncp, bstr) != (int)strlen(bstr)){ + if(ncplane_cursor_move_yx(ncp, rows / 2 - 5, (cols - wcslen(wstr) + 4) / 2)){ + goto err; + } + if(ncplane_putstr(ncp, mbstr) != (int)strlen(mbstr)){ goto err; } if(notcurses_render(nc)){ diff --git a/src/bin/unicodeblocks.c b/src/bin/unicodeblocks.c index 8b0a38fa2..4e9cba5a4 100644 --- a/src/bin/unicodeblocks.c +++ b/src/bin/unicodeblocks.c @@ -65,7 +65,6 @@ int unicodeblocks_demo(struct notcurses* nc){ return -1; } ncplane_fg_rgb8(n, 0xad, 0xd8, 0xe6); - ncplane_bg_rgb8(n, 0, 0, 0); if(ncplane_printf(n, "Unicode points %04x–%04x", blockstart, blockstart + BLOCKSIZE) <= 0){ return -1; } @@ -87,6 +86,7 @@ int unicodeblocks_demo(struct notcurses* nc){ memset(&ps, 0, sizeof(ps)); wchar_t w = blockstart + chunk * CHUNKSIZE + z; char utf8arr[MB_CUR_MAX + 1]; + // FIXME we can print wide ones here, just add an extra line if(wcwidth(w) == 1 && iswprint(w)){ int bwc = wcrtomb(utf8arr, w, &ps); if(bwc < 0){