//The core printing function, prints characters to the array, and sets colors inline int printstring(WINDOW *win, char *fmt) { char *buf; buf = strtok (fmt,"\n"); while (buf != NULL) { int size = strlen(buf); int j; for (j=0; j<size; j++) { win->line[win->cursory].chars[win->cursorx]=buf[j]; win->line[win->cursory].FG[win->cursorx]=win->FG; win->line[win->cursory].BG[win->cursorx]=win->BG; win->line[win->cursory].touched=true; addedchar(win); } buf = strtok (NULL, "\n"); if (buf != NULL) //{ newline(win); // } else //_windows[w].cursorx+=size; } win->draw=true; return 1; }
//The core printing function, prints characters to the array, and sets colors inline int printstring(WINDOW *win, char *fmt) { int size = strlen(fmt); int j; for (j=0; j<size; j++){ if (!(fmt[j]==10)){//check that this isnt a newline char if (win->cursorx <= win->width - 1 && win->cursory <= win->height - 1) { win->line[win->cursory].chars[win->cursorx]=fmt[j]; win->line[win->cursory].FG[win->cursorx]=win->FG; win->line[win->cursory].BG[win->cursorx]=win->BG; win->line[win->cursory].touched=true; addedchar(win); } else if (win->cursory <= win->height - 1) { // don't write outside the window, but don't abort if there are still lines to write. } else { return 0; //if we try and write anything outside the window, abort completely } } else // if the character is a newline, make sure to move down a line if (newline(win)==0){ return 0; } } win->draw=true; return 1; }
//The core printing function, prints characters to the array, and sets colors inline int printstring(WINDOW *win, char *fmt) { int size = strlen(fmt); if(size>0) { int j, i, p=win->cursorx; int x = (win->line[win->cursory].width_in_bytes==win->width)?win->cursorx:cursorx_to_position(win->line[win->cursory].chars, win->cursorx, &p); if(p!=x)//so we start inside a wide character, erase it for good { const char* ts = win->line[win->cursory].chars+p; int len = ANY_LENGTH; unsigned tc = UTF8_getch(&ts, &len); int tw = mk_wcwidth((wchar_t)tc); erease_utf8_by_cw(win->line[win->cursory].chars+p, tw, tw, win->width*4-p-1); x = p+tw-1; } for (j=0; j<size; j++){ if (!(fmt[j]==10)){//check that this isnt a newline char const char* utf8str = fmt+j; int len = ANY_LENGTH; unsigned ch = UTF8_getch(&utf8str, &len); int cw = mk_wcwidth((wchar_t)ch); len = ANY_LENGTH-len; if(cw<1) cw = 1; if(len<1) len = 1; if (win->cursorx+cw <= win->width && win->cursory <= win->height - 1) { win->line[win->cursory].width_in_bytes += erease_utf8_by_cw(win->line[win->cursory].chars+x, cw, len, win->width*4-x-1); for(i=0; i<len; i++) { win->line[win->cursory].chars[x+i]=fmt[j+i]; } for(i=0; i<cw; i++) { win->line[win->cursory].FG[win->cursorx]=win->FG; win->line[win->cursory].BG[win->cursorx]=win->BG; addedchar(win); } win->line[win->cursory].touched=true; j += len-1; x+=len; } else if (win->cursory <= win->height - 1) { // don't write outside the window, but don't abort if there are still lines to write. //j += len-1; //x+=len; } else { return 0; //if we try and write anything outside the window, abort completely } } else {// if the character is a newline, make sure to move down a line if (newline(win)==0){ return 0; } x = 0; } } } win->draw=true; return 1; }
//The core printing function, prints characters to the array, and sets colors inline int printstring(WINDOW *win, char *fmt) { int size = strlen(fmt); int j; for (j=0; j<size; j++){ if (!(fmt[j]==10)){//check for a newline character if (win->cursorx <= win->width - 1 && win->cursory <= win->height - 1) { win->line[win->cursory].chars[win->cursorx]=fmt[j]; win->line[win->cursory].FG[win->cursorx]=win->FG; win->line[win->cursory].BG[win->cursorx]=win->BG; win->line[win->cursory].touched=true; addedchar(win); } } else if (win->cursory >= win->height - 1) return 0; else newline(win); // if found, make sure to move down a line } win->draw=true; return 1; }
int waddch(WINDOW *win, const chtype ch) { char charcode; charcode=ch; switch (ch) { //LINE_NESW - X for on, O for off case 4194424: //#define LINE_XOXO 4194424 charcode=179; break; case 4194417: //#define LINE_OXOX 4194417 charcode=196; break; case 4194413: //#define LINE_XXOO 4194413 charcode=192; break; case 4194412: //#define LINE_OXXO 4194412 charcode=218; break; case 4194411: //#define LINE_OOXX 4194411 charcode=191; break; case 4194410: //#define LINE_XOOX 4194410 charcode=217; break; case 4194422: //#define LINE_XXOX 4194422 charcode=193; break; case 4194420: //#define LINE_XXXO 4194420 charcode=195; break; case 4194421: //#define LINE_XOXX 4194421 charcode=180; break; case 4194423: //#define LINE_OXXX 4194423 charcode=194; break; case 4194414: //#define LINE_XXXX 4194414 charcode=197; break; default: charcode = (char)ch; break; } int curx=win->cursorx; int cury=win->cursory; //if (win2 > -1){ win->line[cury].chars[curx]=charcode; win->line[cury].FG[curx]=win->FG; win->line[cury].BG[curx]=win->BG; win->draw=true; addedchar(win); return 1; // else{ // win2=win2+1; };
int waddch(WINDOW *win, const chtype ch) { char charcode; charcode=ch; switch (ch){ //LINE_NESW - X for on, O for off case LINE_XOXO: //#define LINE_XOXO 4194424 charcode=LINE_XOXO_C; break; case LINE_OXOX: //#define LINE_OXOX 4194417 charcode=LINE_OXOX_C; break; case LINE_XXOO: //#define LINE_XXOO 4194413 charcode=LINE_XXOO_C; break; case LINE_OXXO: //#define LINE_OXXO 4194412 charcode=LINE_OXXO_C; break; case LINE_OOXX: //#define LINE_OOXX 4194411 charcode=LINE_OOXX_C; break; case LINE_XOOX: //#define LINE_XOOX 4194410 charcode=LINE_XOOX_C; break; case LINE_XXOX: //#define LINE_XXOX 4194422 charcode=LINE_XXOX_C; break; case LINE_XXXO: //#define LINE_XXXO 4194420 charcode=LINE_XXXO_C; break; case LINE_XOXX: //#define LINE_XOXX 4194421 charcode=LINE_XOXX_C; break; case LINE_OXXX: //#define LINE_OXXX 4194423 charcode=LINE_OXXX_C; break; case LINE_XXXX: //#define LINE_XXXX 4194414 charcode=LINE_XXXX_C; break; default: charcode = (char)ch; break; } int cury=win->cursory; int p = win->cursorx; int curx=(win->line[cury].width_in_bytes==win->width)?win->cursorx:cursorx_to_position(win->line[cury].chars, win->cursorx, &p); if(curx!=p) { const char* ts = win->line[cury].chars+p; int len = ANY_LENGTH; unsigned tc = UTF8_getch(&ts, &len); int tw = mk_wcwidth((wchar_t)tc); win->line[cury].width_in_bytes += erease_utf8_by_cw(win->line[cury].chars+p, tw, tw, win->width*4-p-1); curx = p+tw-1; } else if(win->line[cury].width_in_bytes!=win->width) { win->line[cury].width_in_bytes += erease_utf8_by_cw(win->line[cury].chars+p, 1, 1, win->width*4-p-1); } //if (win2 > -1){ win->line[cury].chars[curx]=charcode; win->line[cury].FG[win->cursorx]=win->FG; win->line[cury].BG[win->cursorx]=win->BG; win->draw=true; addedchar(win); return 1; // else{ // win2=win2+1; }
//The core printing function, prints characters to the array, and sets colors inline int printstring(WINDOW *win, const std::string &text) { win->draw = true; int len = text.length(); if( len == 0 ) { return 1; } const char *fmt = text.c_str(); // avoid having an invalid cursorx, so that cur_cell will only return nullptr // when the bottom of the window has been reached. if( win->cursorx >= win->width ) { if( newline( win ) == 0 ) { return 0; } } if( win->cursory >= win->height || win->cursorx >= win->width ) { return 0; } if( win->cursorx > 0 && win->line[win->cursory].chars[win->cursorx].ch.empty() ) { // start inside a wide character, erase it for good win->line[win->cursory].chars[win->cursorx - 1].ch.assign(" "); } while( len > 0 ) { if( *fmt == '\n' ) { if( newline(win) == 0 ) { return 0; } fmt++; len--; continue; } cursecell *curcell = cur_cell( win ); if( curcell == nullptr ) { return 0; } const int dlen = fill(fmt, len, curcell->ch); if( dlen >= 1 ) { curcell->FG = win->FG; curcell->BG = win->BG; addedchar( win ); } if( dlen == 1 ) { // a wide character was converted to a narrow character leaving a null in the // following cell ~> clear it cursecell *seccell = cur_cell( win ); if (seccell && seccell->ch.empty()) { seccell->ch.assign(' ', 1); } } else if( dlen == 2 ) { // the second cell, per definition must be empty cursecell *seccell = cur_cell( win ); if( seccell == nullptr ) { // the previous cell was valid, this one is outside of the window // --> the previous was the last cell of the last line // --> there should not be a two-cell width character in the last cell curcell->ch.assign(' ', 1); return 0; } seccell->FG = win->FG; seccell->BG = win->BG; seccell->ch.erase(); addedchar( win ); // Have just written a wide-character into the last cell, it would not // display correctly if it was the last *cell* of a line if( win->cursorx == 1 ) { // So make that last cell a space, move the width // character in the first cell of the line seccell->ch = curcell->ch; curcell->ch.assign(1, ' '); // and make the second cell on the new line empty. addedchar( win ); cursecell *thicell = cur_cell( win ); if( thicell != nullptr ) { thicell->ch.erase(); } } } if( win->cursory >= win->height ) { return 0; } } return 1; }