mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
implement ncplane_putwstr #9
This commit is contained in:
parent
2f9821ce39
commit
fd04c55d16
@ -263,11 +263,16 @@ cell_rgb_blue(uint32_t rgb){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
cell_set_fg(cell* c, unsigned r, unsigned g, unsigned b){
|
cell_rgb_set_fg(uint64_t* channels, unsigned r, unsigned g, unsigned b){
|
||||||
uint64_t rgb = (r & 0xffull) << 48u;
|
uint64_t rgb = (r & 0xffull) << 48u;
|
||||||
rgb |= (g & 0xffull) << 40u;
|
rgb |= (g & 0xffull) << 40u;
|
||||||
rgb |= (b & 0xffull) << 32u;
|
rgb |= (b & 0xffull) << 32u;
|
||||||
c->channels = (c->channels & 0x00ffffff00000000ull) | rgb;
|
*channels = (*channels & 0x00ffffff00000000ull) | rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
cell_set_fg(cell* c, unsigned r, unsigned g, unsigned b){
|
||||||
|
cell_rgb_set_fg(&c->channels, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -42,6 +43,21 @@ int main(void){
|
|||||||
if(notcurses_render(nc)){
|
if(notcurses_render(nc)){
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
sleep(1);
|
||||||
|
const wchar_t lstr[] = L"Wovon man nicht sprechen kann, darüber muss man schweigen.";
|
||||||
|
if(ncplane_cursor_move_yx(ncp, y / 2, (x - wcslen(lstr)) / 2)){
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if(ncplane_fg_rgb8(ncp, 255, 255, 255)){
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if(ncplane_putwstr(ncp, lstr) != (int)wcslen(lstr)){
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if(notcurses_render(nc)){
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
if(notcurses_stop(nc)){
|
if(notcurses_stop(nc)){
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ typedef struct ncplane {
|
|||||||
int lenx, leny; // size of the plane, [0..len{x,y}) is addressable
|
int lenx, leny; // size of the plane, [0..len{x,y}) is addressable
|
||||||
struct ncplane* z; // plane below us
|
struct ncplane* z; // plane below us
|
||||||
struct notcurses* nc; // our parent nc, kinda lame waste of memory FIXME
|
struct notcurses* nc; // our parent nc, kinda lame waste of memory FIXME
|
||||||
|
uint64_t channels; // colors when not provided an active style
|
||||||
} ncplane;
|
} ncplane;
|
||||||
|
|
||||||
typedef struct notcurses {
|
typedef struct notcurses {
|
||||||
@ -401,7 +402,7 @@ int ncplane_fg_rgb8(ncplane* n, int r, int g, int b){
|
|||||||
if(r < 0 || g < 0 || b < 0){
|
if(r < 0 || g < 0 || b < 0){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cell_set_fg(&n->fb[fbcellidx(n, n->y, n->x)], r, g, b);
|
cell_rgb_set_fg(&n->channels, r, g, b);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,7 +551,7 @@ int load_cell(cell* c, const wchar_t* wstr){
|
|||||||
int copied = 0;
|
int copied = 0;
|
||||||
do{
|
do{
|
||||||
if(copied == sizeof(c->cchar) / sizeof(*c->cchar)){
|
if(copied == sizeof(c->cchar) / sizeof(*c->cchar)){
|
||||||
if(!wcwidth(*wstr)){ // next one *must* be a spacing char
|
if(*wstr != L'\0' && wcwidth(*wstr) == 0){ // next one *must* be a spacer
|
||||||
return -1; // filled up the buffer
|
return -1; // filled up the buffer
|
||||||
}
|
}
|
||||||
break; // no terminator on cells which fill the array [shrug]
|
break; // no terminator on cells which fill the array [shrug]
|
||||||
@ -567,11 +568,17 @@ int ncplane_putwstr(ncplane* n, const wchar_t* wstr){
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
// FIXME speed up this blissfully naive solution
|
// FIXME speed up this blissfully naive solution
|
||||||
cell c;
|
cell c;
|
||||||
|
memset(&c, 0, sizeof(c));
|
||||||
|
uint32_t rgb = cell_fg_rgb(n->channels);
|
||||||
|
cell_set_fg(&c, cell_rgb_red(rgb), cell_rgb_green(rgb), cell_rgb_blue(rgb));
|
||||||
while(*wstr != L'\0'){
|
while(*wstr != L'\0'){
|
||||||
int wcs = load_cell(&c, wstr);
|
int wcs = load_cell(&c, wstr);
|
||||||
if(wcs <= 0){
|
if(wcs < 0){
|
||||||
return -ret;
|
return -ret;
|
||||||
}
|
}
|
||||||
|
if(wcs == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
wstr += wcs;
|
wstr += wcs;
|
||||||
if(ncplane_putwc(n, &c)){
|
if(ncplane_putwc(n, &c)){
|
||||||
return -ret;
|
return -ret;
|
||||||
|
@ -15,11 +15,16 @@ class NotcursesTest : public :: testing::Test {
|
|||||||
ASSERT_NE(nullptr, nc_);
|
ASSERT_NE(nullptr, nc_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TearDown() override {
|
||||||
|
if(nc_){
|
||||||
|
EXPECT_EQ(0, notcurses_stop(nc_));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct notcurses* nc_;
|
struct notcurses* nc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(NotcursesTest, BasicLifetime) {
|
TEST_F(NotcursesTest, BasicLifetime) {
|
||||||
EXPECT_EQ(0, notcurses_stop(nc_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NotcursesTest, TermDimensions) {
|
TEST_F(NotcursesTest, TermDimensions) {
|
||||||
@ -35,7 +40,6 @@ TEST_F(NotcursesTest, TermDimensions) {
|
|||||||
auto envx = std::stoi(strx, nullptr);
|
auto envx = std::stoi(strx, nullptr);
|
||||||
EXPECT_EQ(envx, x);
|
EXPECT_EQ(envx, x);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(0, notcurses_stop(nc_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NotcursesTest, ResizeSameSize) {
|
TEST_F(NotcursesTest, ResizeSameSize) {
|
||||||
@ -46,7 +50,6 @@ TEST_F(NotcursesTest, ResizeSameSize) {
|
|||||||
notcurses_term_dimyx(nc_, &newy, &newx);
|
notcurses_term_dimyx(nc_, &newy, &newx);
|
||||||
EXPECT_EQ(newx, x);
|
EXPECT_EQ(newx, x);
|
||||||
EXPECT_EQ(newy, y);
|
EXPECT_EQ(newy, y);
|
||||||
EXPECT_EQ(0, notcurses_stop(nc_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we should at least have WA_STANDOUT everywhere, i should think?
|
// we should at least have WA_STANDOUT everywhere, i should think?
|
||||||
|
Loading…
Reference in New Issue
Block a user