move outfp out of notcurses_options #130

This commit is contained in:
nick black 2019-12-12 07:59:48 -05:00
parent 21c4a9a2eb
commit 1821867e35
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
13 changed files with 45 additions and 36 deletions

View File

@ -87,7 +87,7 @@ foreach(f ${POCSRCS})
PRIVATE include "${TERMINFO_INCLUDE_DIR}"
)
target_link_libraries(${fe}
PRIVATE "${TERMINFO_LIBRARIES}"
PRIVATE notcurses "${TERMINFO_LIBRARIES}"
)
target_link_directories(${fe}
PRIVATE "${TERMINFO_LIBRARY_DIRS}"

View File

@ -118,10 +118,6 @@ typedef struct notcurses_options {
// the environment variable TERM is used. Failure to open the terminal
// definition will result in failure to initialize notcurses.
const char* termtype;
// An open FILE* for this terminal, on which we will generate output. If
// not attached to a sufficiently capable terminal, notcurses will refuse
// to start. You'll usually want stdout.
FILE* outfp;
// If smcup/rmcup capabilities are indicated, notcurses defaults to making
// use of the "alternate screen". This flag inhibits use of smcup/rmcup.
bool inhibit_alternate_screen;
@ -140,9 +136,10 @@ typedef struct notcurses_options {
FILE* renderfp;
} notcurses_options;
// Initialize a notcurses context, corresponding to a connected terminal.
// Returns NULL on error, including any failure to initialize terminfo.
struct notcurses* notcurses_init(const notcurses_options* opts);
// Initialize a notcurses context on the connected terminal at 'fp'. 'fp' must
// be a tty. You'll usually want stdout. Returns NULL on error, including any
// failure to initialize terminfo.
API struct notcurses* notcurses_init(const notcurses_options* opts, FILE* fp);
// Destroy a notcurses context.
int notcurses_stop(struct notcurses* nc);

View File

@ -102,10 +102,6 @@ typedef struct notcurses_options {
// the environment variable TERM is used. Failure to open the terminal
// definition will result in failure to initialize notcurses.
const char* termtype;
// An open FILE* for this terminal, on which we will generate output. If
// not attached to a sufficiently capable terminal, notcurses will refuse
// to start. You'll usually want stdout.
FILE* outfp;
// If smcup/rmcup capabilities are indicated, notcurses defaults to making
// use of the "alternate screen". This flag inhibits use of smcup/rmcup.
bool inhibit_alternate_screen;
@ -124,9 +120,10 @@ typedef struct notcurses_options {
FILE* renderfp;
} notcurses_options;
// Initialize a notcurses context, corresponding to a connected terminal.
// Returns NULL on error, including any failure to initialize terminfo.
API struct notcurses* notcurses_init(const notcurses_options* opts);
// Initialize a notcurses context on the connected terminal at 'fp'. 'fp' must
// be a tty. You'll usually want stdout. Returns NULL on error, including any
// failure to initialize terminfo.
API struct notcurses* notcurses_init(const notcurses_options* opts, FILE* fp);
// Destroy a notcurses context.
API int notcurses_stop(struct notcurses* nc);

View File

@ -157,7 +157,6 @@ static const char*
handle_opts(int argc, char** argv, notcurses_options* opts){
int c;
memset(opts, 0, sizeof(*opts));
opts->outfp = stdout;
while((c = getopt(argc, argv, "hkd:f:")) != EOF){
switch(c){
case 'h':
@ -210,7 +209,7 @@ int main(int argc, char** argv){
}
demos = DEFAULT_DEMO;
}
if((nc = notcurses_init(&nopts)) == NULL){
if((nc = notcurses_init(&nopts, stdout)) == NULL){
return EXIT_FAILURE;
}
if((ncp = notcurses_stdplane(nc)) == NULL){

View File

@ -56,8 +56,7 @@ int main(void){
return EXIT_FAILURE;
}
notcurses_options opts{};
opts.outfp = stdout;
if((nc = notcurses_init(&opts)) == nullptr){
if((nc = notcurses_init(&opts, stdout)) == nullptr){
return EXIT_FAILURE;;
}
struct ncplane* n = notcurses_stdplane(nc);

View File

@ -647,7 +647,7 @@ make_nonblocking(FILE* fp){
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
notcurses* notcurses_init(const notcurses_options* opts){
notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
const char* encoding = nl_langinfo(CODESET);
if(encoding == NULL || strcmp(encoding, "UTF-8")){
fprintf(stderr, "Encoding (\"%s\") wasn't UTF-8, refusing to start\n",
@ -666,7 +666,7 @@ notcurses* notcurses_init(const notcurses_options* opts){
memset(&ret->stats, 0, sizeof(ret->stats));
ret->stats.render_min_ns = 1ul << 62u;
ret->stats.render_min_bytes = 1ul << 62u;
ret->ttyfp = opts->outfp;
ret->ttyfp = outfp;
ret->renderfp = opts->renderfp;
ret->inputescapes = NULL;
ret->ttyinfp = stdin; // FIXME
@ -678,7 +678,7 @@ notcurses* notcurses_init(const notcurses_options* opts){
ret->inputbuf_valid_starts = 0;
ret->inputbuf_write_at = 0;
if((ret->ttyfd = fileno(ret->ttyfp)) < 0){
fprintf(stderr, "No file descriptor was available in opts->outfp\n");
fprintf(stderr, "No file descriptor was available in outfp %p\n", outfp);
free(ret);
return NULL;
}

View File

@ -51,8 +51,7 @@ int main(int argc, char** argv){
usage(std::cerr, argv[0], EXIT_FAILURE);
}
notcurses_options opts{};
opts.outfp = stdout;
auto nc = notcurses_init(&opts);
auto nc = notcurses_init(&opts, stdout);
if(nc == nullptr){
return EXIT_FAILURE;
}

View File

@ -11,8 +11,9 @@ class CellTest : public :: testing::Test {
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.outfp = fopen("/dev/tty", "wb");
nc_ = notcurses_init(&nopts);
outfp_ = fopen("/dev/tty", "wb");
ASSERT_NE(nullptr, outfp_);
nc_ = notcurses_init(&nopts, outfp_);
ASSERT_NE(nullptr, nc_);
n_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n_);
@ -22,10 +23,12 @@ class CellTest : public :: testing::Test {
if(nc_){
EXPECT_EQ(0, notcurses_stop(nc_));
}
fclose(outfp_);
}
struct notcurses* nc_{};
struct ncplane* n_{};
FILE* outfp_{};
};
TEST_F(CellTest, SetItalic) {

View File

@ -11,8 +11,9 @@ class FadeTest : public :: testing::Test {
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.outfp = fopen("/dev/tty", "wb");
nc_ = notcurses_init(&nopts);
outfp_ = fopen("/dev/tty", "wb");
ASSERT_NE(nullptr, outfp_);
nc_ = notcurses_init(&nopts, outfp_);
ASSERT_NE(nullptr, nc_);
n_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n_);
@ -40,10 +41,12 @@ class FadeTest : public :: testing::Test {
if(nc_){
EXPECT_EQ(0, notcurses_stop(nc_));
}
fclose(outfp_);
}
struct notcurses* nc_{};
struct ncplane* n_{};
FILE* outfp_{};
};
TEST_F(FadeTest, FadeOut) {

View File

@ -10,8 +10,9 @@ class LibavTest : public :: testing::Test {
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.outfp = fopen("/dev/tty", "wb");
nc_ = notcurses_init(&nopts);
outfp_ = fopen("/dev/tty", "wb");
ASSERT_NE(nullptr, outfp_);
nc_ = notcurses_init(&nopts, outfp_);
ASSERT_NE(nullptr, nc_);
ncp_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, ncp_);
@ -21,10 +22,12 @@ class LibavTest : public :: testing::Test {
if(nc_){
EXPECT_EQ(0, notcurses_stop(nc_));
}
fclose(outfp_);
}
notcurses* nc_{};
ncplane* ncp_{};
FILE* outfp_{};
};
TEST_F(LibavTest, LoadImage) {

View File

@ -11,8 +11,9 @@ class NcplaneTest : public :: testing::Test {
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.outfp = fopen("/dev/tty", "wb");
nc_ = notcurses_init(&nopts);
outfp_ = fopen("/dev/tty", "wb");
ASSERT_NE(nullptr, outfp_);
nc_ = notcurses_init(&nopts, outfp_);
ASSERT_NE(nullptr, nc_);
n_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n_);
@ -23,10 +24,12 @@ class NcplaneTest : public :: testing::Test {
if(nc_){
EXPECT_EQ(0, notcurses_stop(nc_));
}
fclose(outfp_);
}
struct notcurses* nc_{};
struct ncplane* n_{};
FILE* outfp_{};
};
// Starting position ought be 0, 0 (the origin)

View File

@ -13,8 +13,9 @@ class NotcursesTest : public :: testing::Test {
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.outfp = fopen("/dev/tty", "wb");
nc_ = notcurses_init(&nopts);
outfp_ = fopen("/dev/tty", "wb");
ASSERT_NE(nullptr, outfp_);
nc_ = notcurses_init(&nopts, outfp_);
ASSERT_NE(nullptr, nc_);
}
@ -22,9 +23,11 @@ class NotcursesTest : public :: testing::Test {
if(nc_){
EXPECT_EQ(0, notcurses_stop(nc_));
}
fclose(outfp_);
}
struct notcurses* nc_{};
FILE* outfp_{};
};
TEST_F(NotcursesTest, NotcursesVersionString) {

View File

@ -10,8 +10,9 @@ class PanelReelTest : public :: testing::Test {
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.outfp = fopen("/dev/tty", "wb");
nc_ = notcurses_init(&nopts);
outfp_ = fopen("/dev/tty", "wb");
ASSERT_NE(nullptr, outfp_);
nc_ = notcurses_init(&nopts, outfp_);
ASSERT_NE(nullptr, nc_);
n_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n_);
@ -22,10 +23,12 @@ class PanelReelTest : public :: testing::Test {
if(nc_){
EXPECT_EQ(0, notcurses_stop(nc_));
}
fclose(outfp_);
}
struct notcurses* nc_{};
struct ncplane* n_{};
FILE* outfp_{};
};