mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
proof of concept support. sgr binary
This commit is contained in:
parent
64462a11ac
commit
3a79cbf469
@ -40,6 +40,7 @@ target_link_libraries(notcurses
|
|||||||
)
|
)
|
||||||
target_link_directories(notcurses
|
target_link_directories(notcurses
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
"${TERMINFO_LIBRARY_DIRS}"
|
||||||
"${AVFORMAT_LIBRARY_DIRS}"
|
"${AVFORMAT_LIBRARY_DIRS}"
|
||||||
"${SWSCALE_LIBRARY_DIRS}"
|
"${SWSCALE_LIBRARY_DIRS}"
|
||||||
)
|
)
|
||||||
@ -77,6 +78,22 @@ target_compile_definitions(notcurses-demo
|
|||||||
FORTIFY_SOURCE=2
|
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)
|
file(GLOB INPUTSRCS CONFIGURE_DEPENDS src/input/*.cpp)
|
||||||
add_executable(notcurses-input ${INPUTSRCS})
|
add_executable(notcurses-input ${INPUTSRCS})
|
||||||
target_include_directories(notcurses-input
|
target_include_directories(notcurses-input
|
||||||
|
60
src/poc/sgr.c
Normal file
60
src/poc/sgr.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <ncurses.h> // needed for some definitions, see terminfo(3ncurses)
|
||||||
|
#include <term.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <notcurses.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user