diff --git a/src/demo/mojibake.c b/src/demo/mojibake.c index 173d252e2..6c40f9a0c 100644 --- a/src/demo/mojibake.c +++ b/src/demo/mojibake.c @@ -1,20 +1,39 @@ #include "demo.h" static struct ncplane* -unicode52(struct ncplane* std, int y){ - const int ROWS = 25; - struct ncplane* n = ncplane_aligned(std, ROWS, 64, y, NCALIGN_CENTER, NULL); +mojiplane(struct ncplane* title, int y, int rows, const char* summary){ + struct ncplane* n = ncplane_aligned(title, rows, 64, y, NCALIGN_CENTER, NULL); if(ncplane_perimeter_rounded(n, 0, 0, 0) < 0){ ncplane_destroy(n); return NULL; } uint64_t channels = 0; channels_set_bg(&channels, 0x0); - if(ncplane_set_base(n, " ", 0, channels) < 0 || ncplane_set_fg(n, 0x40d040) - || ncplane_set_bg(n, 0)){ + if(ncplane_set_fg(n, 0x40d0d0) || ncplane_set_bg(n, 0)){ + ncplane_destroy(n); + return NULL; + } + const int x = ncplane_align(n, NCALIGN_RIGHT, strlen(summary) + 2); + if(ncplane_putstr_yx(n, rows - 1, x, summary) < 0){ + ncplane_destroy(n); + return NULL; + } + if(ncplane_set_base(n, " ", 0, channels) < 0 || ncplane_set_fg(n, 0x40d040)){ ncplane_destroy(n); return NULL; } + ncplane_move_below(n, title); + return n; +} + +static struct ncplane* +unicode52(struct ncplane* title, int y){ + const char SUMMARY[] = "[Unicode 6.0 (2010), 608 codepoints]"; + const int ROWS = 25; + struct ncplane* n = mojiplane(title, y, ROWS, SUMMARY); + if(n == NULL){ + return NULL; + } ncplane_putstr_yx(n, 1, 1, "๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜๐Ÿ˜†๐Ÿ˜…๐Ÿ˜‚๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‡๐Ÿ˜๐Ÿ˜˜๐Ÿ˜š๐Ÿ˜‹๐Ÿ˜œ๐Ÿ˜๐Ÿ˜๐Ÿ˜ถ๐Ÿ˜๐Ÿ˜’๐Ÿ˜Œ๐Ÿ˜”๐Ÿ˜ช๐Ÿ˜ท๐Ÿ˜ต๐Ÿ˜Ž๐Ÿ˜ฒ๐Ÿ˜ณ๐Ÿ˜จ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜ข๐Ÿ˜ญ"); ncplane_putstr_yx(n, 2, 1, "๐Ÿ˜ฑ๐Ÿ˜–๐Ÿ˜ฃ๐Ÿ˜ž๐Ÿ˜“๐Ÿ˜ฉ๐Ÿ˜ซ๐Ÿ˜ค๐Ÿ˜ก๐Ÿ˜ ๐Ÿ˜ˆ๐Ÿ‘ฟ๐Ÿ’€๐Ÿ’ฉ๐Ÿ‘น๐Ÿ‘บ๐Ÿ‘ป๐Ÿ‘ฝ๐Ÿ‘พ๐Ÿ˜บ๐Ÿ˜ธ๐Ÿ˜น๐Ÿ˜ป๐Ÿ˜ผ๐Ÿ˜ฝ๐Ÿ™€๐Ÿ˜ฟ๐Ÿ˜พ๐Ÿ™ˆ๐Ÿ™‰๐Ÿ™Š๐Ÿ’‹"); ncplane_putstr_yx(n, 3, 1, "๐Ÿ’Œ๐Ÿ’˜๐Ÿ’๐Ÿ’–๐Ÿ’—๐Ÿ’“๐Ÿ’ž๐Ÿ’•๐Ÿ’Ÿ๐Ÿ’”๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ๐Ÿ’ฏ๐Ÿ’ข๐Ÿ’ฅ๐Ÿ’ซ๐Ÿ’ฆ๐Ÿ’จ๐Ÿ’ฃ๐Ÿ’ฌ๐Ÿ’ญ๐Ÿ’ค๐Ÿ‘‹โœ‹๐Ÿ‘Œ๐Ÿ‘ˆ๐Ÿ‘‰๐Ÿ‘†๐Ÿ‘‡๐Ÿ‘"); @@ -38,10 +57,28 @@ unicode52(struct ncplane* std, int y){ ncplane_putstr_yx(n, 21, 1, "โญ\ufe0fโฎ\ufe0fโซ๐Ÿ”ฝโฌ๐ŸŽฆ๐Ÿ”…๐Ÿ”†๐Ÿ“ถ๐Ÿ“ณ๐Ÿ“ดโž•โž–โž—โ“โ”โ•๐Ÿ’ฑ๐Ÿ’ฒ๐Ÿ”ฑ๐Ÿ“›๐Ÿ”ฐโœ…โŒโŽโžฐโžฟ๐Ÿ”Ÿ๐Ÿ” ๐Ÿ”ก๐Ÿ”ข"); ncplane_putstr_yx(n, 22, 1, "โฏ\ufe0f๐Ÿ”ฃ๐Ÿ”ค๐Ÿ…ฐ๐Ÿ†Ž๐Ÿ…ฑ๐Ÿ†‘๐Ÿ†’๐Ÿ†“๐Ÿ†”๐Ÿ†•๐Ÿ†–๐Ÿ…พ๐Ÿ†—๐Ÿ†˜๐Ÿ†™๐Ÿ†š๐Ÿˆ๐Ÿˆ‚๐Ÿˆท๐Ÿˆถ๐Ÿ‰๐Ÿˆน๐Ÿˆฒ๐Ÿ‰‘๐Ÿˆธ๐Ÿˆด๐Ÿˆณ๐Ÿˆบ๐Ÿˆต๐Ÿ”ด๐Ÿ”ต๐Ÿ”ถ๐Ÿ”ท"); ncplane_putstr_yx(n, 23, 1, "๐Ÿ”ธ๐Ÿ”น๐Ÿ”บ๐Ÿ”ป๐Ÿ’ ๐Ÿ”˜๐Ÿ”ณ๐Ÿ”ฒ๐Ÿ๐Ÿšฉ๐ŸŽŒโ›งโ›คโ›ขโ›ฆโ›ฅ"); - const char SUMMARY[] = "[Unicode 6.0 (2010), 608 codepoints]"; - ncplane_set_fg(n, 0x40d0d0); - const int x = ncplane_align(n, NCALIGN_RIGHT, strlen(SUMMARY) + 2); - ncplane_putstr_yx(n, ROWS - 1, x, SUMMARY); + return n; +} + +static struct ncplane* +unicode13(struct ncplane* title, int y){ + const char SUMMARY[] = "[Unicode 13.0 (2010), 56 codepoints]"; + const int ROWS = 4; + struct ncplane* n = mojiplane(title, y, ROWS, SUMMARY); + if(n == NULL){ + return NULL; + } + ncplane_putstr_yx(n, 1, 1, "\xf0\x9f\xa5\xb2\xf0\x9f\xa5\xb8\xf0\x9f\xa4\x8c" + "\xf0\x9f\xab\x80\xf0\x9f\xab\x81\xf0\x9f\xa5\xb7" + "\xf0\x9f\xab\x82\xf0\x9f\xa6\xac\xf0\x9f\xa6\xa3" + "\xf0\x9f\xa6\xab\xf0\x9f\xa6\xa4\xf0\x9f\xaa\xb6" + "\xf0\x9f\xa6\xad\xf0\x9f\xaa\xb2\xf0\x9f\xaa\xb3" + "\xf0\x9f\xaa\xb0\xf0\x9f\xaa\xb1\xf0\x9f\xaa\xb4" + "\xf0\x9f\xab\x90\xf0\x9f\xab\x92\xf0\x9f\xab\x91" + "\xf0\x9f\xab\x93\xf0\x9f\xab\x94\xf0\x9f\xab\x95" + "\xf0\x9f\xab\x96\xf0\x9f\xa7\x8b\xf0\x9f\xaa\xa8" + "\xf0\x9f\xaa\xb5\xf0\x9f\x9b\x96\xf0\x9f\x9b\xbb" + "\xf0\x9f\x9b\xbc\xf0\x9f\xaa\x84"); return n; } @@ -84,7 +121,8 @@ int mojibake_demo(struct notcurses* nc){ return -1; } struct ncplane* planes[] = { - unicode52(std, dimy - 1), + unicode52(title, dimy - 1), + unicode13(title, dimy + 1), }; // scroll the various planes up from the bottom. none are onscreen save the // first, which starts at the bottom. each time one clears, we bring the @@ -94,12 +132,14 @@ int mojibake_demo(struct notcurses* nc){ struct timespec stepdelay; // two seconds onscreen per plane at standard (1s) delay timespec_div(&demodelay, dimy / 2, &stepdelay); - ncplane_move_below(planes[0], title); do{ unsigned u = topmost; do{ int y, x, leny; ncplane_yx(planes[u], &y, &x); + if(y >= dimy){ + break; + } if(ncplane_move_yx(planes[u], y - 1, x)){ goto err; } @@ -108,7 +148,11 @@ int mojibake_demo(struct notcurses* nc){ ++topmost; } if(leny + y + 1 == dimy - 1){ - // FIXME bring next one on + if(u + 1 < sizeof(planes) / sizeof(*planes)){ + if(ncplane_move_yx(planes[u + 1], dimy - 1, x)){ + goto err; + } + } } ++u; }while(u < sizeof(planes) / sizeof(*planes));