Do not use ncurses on Windows

Instead, we just assume that on Windows, we always have color-capable terminals.
This commit is contained in:
Thomas Jensen 2023-11-04 09:36:16 +01:00
parent ba40638946
commit 94de53c6f0
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
3 changed files with 24 additions and 11 deletions

View File

@ -121,7 +121,7 @@ $(LIBUNISTRING_DIR)/lib/.libs/libunistring.a: vendor/libunistring-$(LIBUNISTRING
cd $(LIBUNISTRING_DIR) ; ./configure --enable-static ; $(MAKE)
vendor/libncurses-$(LIBNCURSES_VERSION).tar.gz: | vendor
curl -L http://invisible-mirror.net/archives/ncurses/ncurses-$(LIBNCURSES_VERSION).tar.gz --output $@
curl -L https://invisible-mirror.net/archives/ncurses/ncurses-$(LIBNCURSES_VERSION).tar.gz --output $@
$(LIBNCURSES_DIR)/lib/libncurses.a: vendor/libncurses-$(LIBNCURSES_VERSION).tar.gz
tar -C vendor -xzf vendor/libncurses-$(LIBNCURSES_VERSION).tar.gz

View File

@ -72,7 +72,7 @@ boxes.static: $(ALL_OBJ) | check_dir
if [ "$(STRIP)" = "true" ] ; then strip $(BOXES_EXECUTABLE_NAME) ; fi
boxes.exe: $(ALL_OBJ) | check_dir
$(CC) $(LDFLAGS) $^ -o $@ -lkernel32 -l:libunistring.a -l:libpcre2-32.a -l:libiconv.a -l:libncurses.a
$(CC) $(LDFLAGS) $^ -o $@ -lkernel32 -l:libunistring.a -l:libpcre2-32.a -l:libiconv.a
if [ "$(STRIP)" = "true" ] ; then strip $@ ; fi
@ -91,8 +91,8 @@ flags_static:
echo $(filter-out boxes.o,$(ALL_OBJ)) > $(OUT_DIR)/modules.txt
flags_win32:
$(eval CFLAGS := -Os -s -m32 -I. -I$(SRC_DIR) -I$(LIBNCURSES_WIN_INCLUDE) -Wall -W $(CFLAGS_ADDTL))
$(eval LDFLAGS := $(LDFLAGS) -s -m32)
$(eval CFLAGS := -Os -s -m32 -I. -I$(SRC_DIR) -Wall -W $(CFLAGS_ADDTL))
$(eval LDFLAGS := $(LDFLAGS) -s -m32 $(LDFLAGS_ADDTL))
$(eval BOXES_EXECUTABLE_NAME := boxes.exe)
$(eval ALL_OBJ := $(GEN_SRC:.c=.o) $(ORIG_NORM:.c=.o))
echo $(filter-out boxes.o,$(ALL_OBJ)) > $(OUT_DIR)/modules.txt

View File

@ -15,7 +15,9 @@
#include "config.h"
#ifndef __MINGW32__
#include <ncurses.h>
#endif
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
@ -400,19 +402,30 @@ static void handle_remove_box()
/* These two functions are actually declared in term.h, but for some reason, that can't be included. */
extern NCURSES_EXPORT(int) setupterm (NCURSES_CONST char *, int, int *);
extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *);
#ifndef __MINGW32__
/* These two functions are actually declared in term.h, but for some reason, that can't be included. */
extern NCURSES_EXPORT(int) setupterm(NCURSES_CONST char *, int, int *);
extern NCURSES_EXPORT(int) tigetnum(NCURSES_CONST char *);
#endif
static int terminal_has_colors()
{
int result = 0;
char *termtype = getenv("TERM");
if (termtype != NULL && setupterm(termtype, STDOUT_FILENO, NULL) == OK && tigetnum("colors") >= 8) {
result = 1;
}
#ifdef __MINGW32__
result = 1; /* On Windows, we always assume color capability. */
UNUSED(termtype);
#else
if (termtype != NULL && setupterm(termtype, STDOUT_FILENO, NULL) == OK && tigetnum("colors") >= 8) {
result = 1;
}
#endif
#if defined(DEBUG)
int num_colors = result ? tigetnum("colors") : 0;
#ifdef __MINGW32__
int num_colors = 1;
#else
int num_colors = result ? tigetnum("colors") : 0;
#endif
fprintf(stderr, "Terminal \"%s\" %s colors (number of colors = %d).\n", termtype != NULL ? termtype : "(null)",
result ? "has" : "does NOT have", num_colors);
#endif