hello world
I think it would be nice and probably good for adoption to have some simple instructions showing in a very simple way how to write and compile a "hello world" program from start to finish. From not having notcurses installed in your computer (maybe that could be a link to comprehensive multiplatform instructions) to writing the code, compiling and running it. What do you think?
I realized today that for me, that I don't code in C, I had to figure out that in order to compile a notcurses program outside of the notcurses building process I can use the following command:
gcc source.c -o binary $(pkg-config --cflags --libs notcurses)
i think it sounds great, just don't see when i'll have time to do it
i think it sounds great, just don't see when i'll have time to do it
ok but there's no rush and it can be done simply at first. I could try to put something together and see when there's something where it could be shown...
I'm envisioning having series of unassuming didatic examples, that build on top of each other, step by step, like:
// example 00
//
// introduces:
// - notcurses initialization & stopping
// - text outputting
#include <notcurses/notcurses.h>
#include <unistd.h>
int main(void){
// initialize notcurses with default options
struct notcurses* nc = notcurses_core_init(NULL, NULL);
// write to the standard plane at the top right corner
ncplane_putstr_yx(notcurses_stdplane(nc), 0, 0, "hello world");
// render the standard pile
notcurses_render(nc);
sleep(1);
// stop notcurses
notcurses_stop(nc);
}
// example 01
//
// introduces:
// - notcurses options, CLI mode
// - error managing
#include <notcurses/notcurses.h>
int main(void){
// set the notcurses options
struct notcurses_options nopts = {
.flags =
NCOPTION_NO_ALTERNATE_SCREEN | // don't use the alternate screen
NCOPTION_SUPPRESS_BANNERS | // don't show version & performance info
NCOPTION_PRESERVE_CURSOR | // preserve the terminal cursor location
NCOPTION_NO_CLEAR_BITMAPS | // don't clear preexisting bitmaps
NCOPTION_DRAIN_INPUT // don't handle input
};
// initialize notcurses, checking for errors
struct notcurses* nc = notcurses_core_init(&nopts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}
// get a reference to the standard plane
struct ncplane* stdn = notcurses_stdplane(nc);
// write to the standard plane at the current cursor coordinates
ncplane_putstr_yx(stdn, -1, -1, "hello world");
// render the standard pile
notcurses_render(nc);
// stop notcurses, checking for errors
if (notcurses_stop(nc)) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
...
this would definitely be awesome
do you think it makes sense to create an examples/ or tutorial/ directory for these? or what do you think?
I made 3 so far, and a compiler script
Working on the libnotcurses-sys repository for the time being under the examples/c path.
duno why but the second example don't print the last character of the string... and do not clear the screen as the first example who work fine... (buffer not entirely flushed... use of \n\r solve the issue !)
any other way to flush buffer without \n\r ??
Also why the first example uses 0, 0 as coordinates but second one use -1, -1 (-1 means actual position on this axis) as '.')
thanks in advance for your precious time...