diff --git a/CMakeLists.txt b/CMakeLists.txt index e166fd5a8..4d9392d62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ target_link_libraries(notcurses ) target_link_directories(notcurses PRIVATE + "${TERMINFO_LIBRARY_DIRS}" "${AVFORMAT_LIBRARY_DIRS}" "${SWSCALE_LIBRARY_DIRS}" ) @@ -77,6 +78,22 @@ target_compile_definitions(notcurses-demo FORTIFY_SOURCE=2 ) +# tiny proofs of concept, one binary per source file +file(GLOB POCSRCS CONFIGURE_DEPENDS src/poc/*.c) +foreach(f ${POCSRCS}) + get_filename_component(fe "${f}" NAME_WE) + add_executable(${fe} ${f}) + target_include_directories(${fe} + PRIVATE "${TERMINFO_INCLUDE_DIR}" + ) + target_link_libraries(${fe} + PRIVATE "${TERMINFO_LIBRARIES}" + ) + target_link_directories(${fe} + PRIVATE "${TERMINFO_LIBRARY_DIRS}" + ) +endforeach() + file(GLOB INPUTSRCS CONFIGURE_DEPENDS src/input/*.cpp) add_executable(notcurses-input ${INPUTSRCS}) target_include_directories(notcurses-input diff --git a/src/poc/sgr.c b/src/poc/sgr.c new file mode 100644 index 000000000..19fc431c2 --- /dev/null +++ b/src/poc/sgr.c @@ -0,0 +1,60 @@ +#include // needed for some definitions, see terminfo(3ncurses) +#include +#include +#include +#include +#include +#include + +static int +pivot_on(int pivot, int* sgrs, int sgrcount){ + assert(0 <= pivot); + assert(sgrcount > pivot); + int i; + for(i = 0 ; i < sgrcount ; ++i){ + printf("%c", sgrs[i] ? '1' : '0'); + } + putchar('\n'); + for(i = 8 ; i >= pivot ; --i){ + if(sgrs[i] == 0){ + sgrs[i] = 1; + int j; + for(j = i + 1 ; j < sgrcount ; ++j){ + sgrs[j] = 0; + } + return pivot; + } + } + return pivot - 1; +} + +int main(int argc, char** argv){ + setlocale(LC_ALL, NULL); + const char* sgr; + char** a; + if(setupterm(NULL, -1, NULL)){ + fprintf(stderr, "Error initializing terminal\n"); + return EXIT_FAILURE; + } + if((sgr = tigetstr("sgr")) == NULL || sgr == (char*)-1){ + fprintf(stderr, "Couldn't get terminfo entry for sgr\n"); + return EXIT_FAILURE; + } + int sgrs[9] = { 0 }; + int pivot = 8; + // generate all values + while(pivot >= 0){ + pivot = pivot_on(pivot, sgrs, 9); + int p = putp(tiparm(sgr, sgrs[0], sgrs[1], sgrs[2], sgrs[3], sgrs[4], + sgrs[5], sgrs[6], sgrs[7], sgrs[8])); + assert(OK == p); + for(a = argv ; *a ; ++a){ + if((p = printf("%s\n", *a)) < 0){ + return EXIT_FAILURE; + } + } + p = putp(tiparm(sgr, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + assert(OK == p); + } + return EXIT_SUCCESS; +}