mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
move outfp out of notcurses_options #130
This commit is contained in:
parent
21c4a9a2eb
commit
1821867e35
@ -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}"
|
||||
|
11
README.md
11
README.md
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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){
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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_{};
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user