demo: properly center wave on front page #50

This commit is contained in:
nick black 2019-11-26 07:50:51 -05:00 committed by Nick Black
parent 02a3b25ae0
commit f1e7b4a8e5
2 changed files with 9 additions and 4 deletions

View File

@ -1,3 +1,4 @@
#include <wchar.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
@ -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)){

View File

@ -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){