mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-08 01:10:23 +00:00
This commit is contained in:
parent
76f2a3d374
commit
81a31c2a4b
@ -41,7 +41,6 @@ typedef struct fetched_info {
|
||||
const char* shell; // getenv("SHELL")
|
||||
char* term; // notcurses_detected_terminal(), heap-alloced
|
||||
char* lang; // getenv("LANG")
|
||||
int dimy, dimx; // extracted from xrandr
|
||||
char* cpu_model; // FIXME don't handle hetero setups yet
|
||||
int core_count;
|
||||
// if there is no other logo found, fall back to a logo filched from neofetch
|
||||
@ -75,6 +74,25 @@ fetch_env_vars(struct notcurses* nc, fetched_info* fi){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if nothing else is available, use a generic architecture based on compile
|
||||
static const char*
|
||||
fallback_cpuinfo(void){
|
||||
#if defined(__amd64__) || defined(_M_AMD64)
|
||||
return "amd64";
|
||||
#elif defined(__aarch64__)
|
||||
return "aarch64";
|
||||
#elif defined(__arm__)
|
||||
return "arm";
|
||||
#elif defined(__i386__) || defined(_M_IX86)
|
||||
return "i386";
|
||||
#elif defined(__ia64__)
|
||||
return "ia64";
|
||||
#else
|
||||
#warning "unknown target architecture"
|
||||
return "unknown";
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
fetch_bsd_cpuinfo(fetched_info* fi){
|
||||
#if defined(__linux__) || defined(__gnu_hurd__) || defined(__MINGW64__)
|
||||
@ -171,49 +189,6 @@ fetch_cpu_info(fetched_info* fi){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char*
|
||||
pipe_getline(const char* cmdline){
|
||||
FILE* p = popen(cmdline, "re");
|
||||
if(p == NULL){
|
||||
fprintf(stderr, "Error running %s (%s)\n", cmdline, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
char* buf = malloc(BUFSIZ); // gatesv("BUFSIZ bytes is enough for anyone")
|
||||
if(fgets(buf, BUFSIZ, p) == NULL){
|
||||
//fprintf(stderr, "Error reading from %s (%s)\n", cmdline, strerror(errno));
|
||||
pclose(p);
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
// FIXME read any remaining junk so as to stave off SIGPIPEs?
|
||||
if(pclose(p)){
|
||||
fprintf(stderr, "Error closing pipe (%s)\n", strerror(errno));
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int
|
||||
fetch_x_props(fetched_info* fi){
|
||||
char* xrandr = pipe_getline("xrandr --current 2>/dev/null");
|
||||
if(xrandr == NULL){
|
||||
return -1;
|
||||
}
|
||||
char* randrcurrent = strstr(xrandr, " current ");
|
||||
if(randrcurrent == NULL){
|
||||
free(xrandr);
|
||||
return -1;
|
||||
}
|
||||
randrcurrent += strlen(" current ");
|
||||
if(sscanf(randrcurrent, "%d x %d", &fi->dimx, &fi->dimy) != 2){
|
||||
free(xrandr);
|
||||
return -1;
|
||||
}
|
||||
free(xrandr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
// Given a filename, check for its existence in the directories specified by
|
||||
// https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html.
|
||||
@ -559,15 +534,11 @@ infoplane_notcurses(struct notcurses* nc, const fetched_info* fi, int planeheigh
|
||||
}else{
|
||||
ncplane_printf_aligned(infop, 4, NCALIGN_LEFT, " TERM: %s", fi->term);
|
||||
}
|
||||
ncplane_printf_aligned(infop, 4, NCALIGN_RIGHT, "Screen0: %dx%d ", fi->dimx, fi->dimy);
|
||||
ncplane_printf_aligned(infop, 5, NCALIGN_LEFT, " LANG: %s", fi->lang);
|
||||
#ifndef __MINGW64__
|
||||
ncplane_printf_aligned(infop, 5, NCALIGN_RIGHT, "UID: %ju ", (uintmax_t)getuid());
|
||||
#else
|
||||
ncplane_printf_aligned(infop, 5, NCALIGN_RIGHT, "UID: %s ", "FIXME"); // FIXME
|
||||
#endif
|
||||
ncplane_printf_aligned(infop, 4, NCALIGN_RIGHT, " LANG: %s", fi->lang);
|
||||
ncplane_set_styles(infop, NCSTYLE_ITALIC | NCSTYLE_BOLD);
|
||||
ncplane_printf_aligned(infop, 6, NCALIGN_CENTER, "%s (%d cores)", fi->cpu_model, fi->core_count);
|
||||
ncplane_printf_aligned(infop, 6, NCALIGN_CENTER, "%s (%d cores)",
|
||||
fi->cpu_model ? fi->cpu_model : fallback_cpuinfo(),
|
||||
fi->core_count);
|
||||
nccell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
|
||||
nccell ll = CELL_TRIVIAL_INITIALIZER, lr = CELL_TRIVIAL_INITIALIZER;
|
||||
nccell hl = CELL_TRIVIAL_INITIALIZER, vl = CELL_TRIVIAL_INITIALIZER;
|
||||
@ -757,9 +728,6 @@ ncneofetch(struct notcurses* nc){
|
||||
fi.hostname = notcurses_hostname();
|
||||
fi.username = notcurses_accountname();
|
||||
fetch_env_vars(nc, &fi);
|
||||
if(kern != NCNEO_XNU && kern != NCNEO_WINDOWS){
|
||||
fetch_x_props(&fi);
|
||||
}
|
||||
if(kern == NCNEO_LINUX){
|
||||
fetch_cpu_info(&fi);
|
||||
}else if(kern == NCNEO_WINDOWS){
|
||||
|
@ -158,7 +158,7 @@ int fbcon_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
|
||||
}
|
||||
|
||||
int fbcon_draw(const tinfo* ti, sprixel* s, int y, int x){
|
||||
logdebug("id %lu dest %d/%d\n", s->id, y, x);
|
||||
logdebug("id %" PRIu32 " dest %d/%d\n", s->id, y, x);
|
||||
int wrote = 0;
|
||||
for(unsigned l = 0 ; l < (unsigned)s->pixy && l + y * ti->cellpixy < ti->pixy ; ++l){
|
||||
// FIXME pixel size isn't necessarily 4B, line isn't necessarily psize*pixx
|
||||
|
@ -130,7 +130,7 @@ TEST_CASE("Reels") {
|
||||
// create a reel, but don't explicitly destroy it, thus testing the
|
||||
// context shutdown cleanup path
|
||||
SUBCASE("ImplicitDestroy") {
|
||||
ncreel_options r = { };
|
||||
ncreel_options r{};
|
||||
struct ncreel* nr = ncreel_create(n_, &r);
|
||||
REQUIRE(nr);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
@ -140,7 +140,7 @@ TEST_CASE("Reels") {
|
||||
// refused by the second (and testing that error path). this ought result in
|
||||
// the shared plane (and thus the original widget) also being destroyed.
|
||||
SUBCASE("RefuseBoundStandardPlane") {
|
||||
ncreel_options r = { };
|
||||
ncreel_options r{};
|
||||
struct ncreel* nr = ncreel_create(n_, &r);
|
||||
REQUIRE(nr);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
@ -156,7 +156,7 @@ TEST_CASE("Reels") {
|
||||
nopts.cols = ncplane_dim_x(n_);
|
||||
auto ncp = ncplane_create(n_, &nopts);
|
||||
REQUIRE(nullptr != ncp);
|
||||
ncreel_options r = { };
|
||||
ncreel_options r{};
|
||||
struct ncreel* nr = ncreel_create(ncp, &r);
|
||||
REQUIRE(nr);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
@ -166,7 +166,7 @@ TEST_CASE("Reels") {
|
||||
}
|
||||
|
||||
SUBCASE("InitLinear") {
|
||||
ncreel_options r = { };
|
||||
ncreel_options r{};
|
||||
struct ncreel* nr = ncreel_create(n_, &r);
|
||||
REQUIRE(nr);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
|
Loading…
Reference in New Issue
Block a user