shithub: orca

Download patch

ref: 8b9a95f9a22d820ce7a71646f8e9ea24096e7a64
parent: f0bf102bf431866912213e80e46983a31bd7e541
author: cancel <cancel@cancel.fm>
date: Sat Nov 24 23:51:01 EST 2018

Add test use of extended ncurses

--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
-basic_flags := -std=c99 -pipe -Wall -Wpedantic -Wextra -Werror=implicit-function-declaration
+basic_flags := -std=c99 -pipe -Wall -Wpedantic -Wextra -Werror=implicit-function-declaration -D_XOPEN_SOURCE_EXTENDED=1
 debug_flags := -DDEBUG -O0 -ggdb -feliminate-unused-debug-symbols
 sanitize_flags := -fsanitize=address -fsanitize=undefined
 # note: -fsanitize=leak not available on at least Mac 10.12
 release_flags := -DNDEBUG -O2 -s -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fpie -Wl,-pie
-library_flags := -lncurses
+library_flags := -lncursesw
 source_files := field.c main.c
 
 all: debug
--- a/field.c
+++ b/field.c
@@ -124,9 +124,11 @@
   f->buffer[y * f_width + x] = term;
 }
 
-void field_debug_draw(Field* f, int offset_y, int offset_x) {
+void field_debug_draw(WINDOW* win, Field* f, int offset_y, int offset_x) {
   enum { Line_buffer_count = 4096 };
-  chtype line_buffer[Line_buffer_count];
+  cchar_t line_buffer[Line_buffer_count];
+  wchar_t wcs[2];
+  wcs[1] = '\0';
   size_t f_height = f->height;
   size_t f_width = f->width;
   Term* f_buffer = f->buffer;
@@ -135,9 +137,10 @@
   for (size_t iy = 0; iy < f_height; ++iy) {
     Term* row_p = f_buffer + f_width * iy;
     for (size_t ix = 0; ix < f_width; ++ix) {
-      line_buffer[ix] = (chtype)row_p[ix];
+      wcs[0] = row_p[ix];
+      setcchar(line_buffer + ix, wcs, A_NORMAL, 0, NULL);
     }
     move(iy + offset_y, offset_x);
-    addchnstr(line_buffer, (int)f_width);
+    wadd_wchnstr(win, line_buffer, (int)f_width);
   }
 }
--- a/field.h
+++ b/field.h
@@ -17,4 +17,4 @@
                         Term fill_char);
 Term field_peek(Field* f, U32 y, U32 x);
 void field_poke(Field* f, U32 y, U32 x, Term term);
-void field_debug_draw(Field* f, int offset_y, int offset_x);
+void field_debug_draw(WINDOW* win, Field* f, int offset_y, int offset_x);
--- a/main.c
+++ b/main.c
@@ -71,12 +71,12 @@
     }
     field_fill_subrect(&field, 1, 1, field.height - 2, field.width - 2,
                        fill_char);
-    field_debug_draw(&field, 0, 0);
+    field_debug_draw(stdscr, &field, 0, 0);
     field_copy_subrect(&field, &field, 0, 0, 4, 4, 8, 8);
     field_copy_subrect(&field, &field, 0, 0, 0, 0, 0, 0);
-    field_debug_draw(&field, field.height + 1, 0);
+    field_debug_draw(stdscr, &field, field.height + 1, 0);
     field_copy_subrect(&field, &field, 6, 6, 9, 9, 30, 30);
-    field_debug_draw(&field, 0, field.width + 1);
+    field_debug_draw(stdscr, &field, 0, field.width + 1);
     refresh();
   }
   field_deinit(&field);