Skip to content

Commit

Permalink
Cache knowledge of Windows 10 to prevent calling it on every write .
Browse files Browse the repository at this point in the history
  • Loading branch information
amoldeshpande committed Nov 20, 2020
1 parent 2bbef8b commit f200a36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ testsuite.log
*.suo
*~
.vs/
win32/tcsh.manifest
win32/nt.const.h
win32/BSDLOGO.res
terminfo.txt
tcsh.map
Expand Down
5 changes: 5 additions & 0 deletions win32/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WORD get_attributes();

static WORD wNormalAttributes;

static BOOL nt_is_windows_10_or_greater = FALSE;

static int nt_is_raw;
//
Expand Down Expand Up @@ -105,6 +106,9 @@ void redo_console(void) {
void nt_term_cleanup(void) {
CloseHandle(ghstdout);
}
BOOL is_windows_10_or_greater() {
return nt_is_windows_10_or_greater ;
}
void nt_set_win10_vt_mode() {
if (IsWindows10OrGreater()) {
DWORD dwmode;
Expand All @@ -116,6 +120,7 @@ void nt_set_win10_vt_mode() {
return;
}
}
nt_is_windows_10_or_greater = TRUE;
}

void nt_term_init() {
Expand Down
4 changes: 2 additions & 2 deletions win32/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
extern void make_err_str(unsigned int ,char *,int ) ;
extern void generic_handler(int);
extern int console_write(HANDLE,unsigned char*,int);
extern BOOL is_windows_10_or_greater() ;

int consoleread(HANDLE , unsigned char * ,size_t ) ;

INPUT_RECORD girec[2048];

unsigned short __nt_want_vcode=0,__nt_vcode=0;
Expand Down Expand Up @@ -160,7 +160,7 @@ int nt_write(int fd, const unsigned char * buf, size_t howmany) {
ssize_t start = 0;
int rc,wrote = 0;

if (!isatty(fd) || (varval(STRcolor) == NULL) || IsWindows10OrGreater())
if (!isatty(fd) || (varval(STRcolor) == NULL) || is_windows_10_or_greater())
return nt_write_(fd, buf, howmany);

for (i = 0; i < howmany; i++) {
Expand Down

0 comments on commit f200a36

Please sign in to comment.