Skip to content

Add experimental support for Windows Console (proof of concept) - #58

Closed
adsr wants to merge 1 commit into
masterfrom
windows
Closed

Add experimental support for Windows Console (proof of concept)#58
adsr wants to merge 1 commit into
masterfrom
windows

Conversation

@adsr

@adsr adsr commented Nov 5, 2023

Copy link
Copy Markdown
Contributor

This has come up once or twice as there aren't many good libraries for writing cross-platform terminal applications. To my surprise, recent versions of Windows Console support xterm-like caps if you put the console in a special mode. Initializing the console, reading and writing to it, and handling resize events are different but everything else is the same.

wcwidth isn't available, so everything is assumed to occupy 1 column.

I haven't tested anything besides the keyboard demo, which seems to work just fine.

The ifdefs ugly up the code a lot, so I'm hesitant to actually merge this. I may attempt to code-gen a separate artifact termbox2-win.h or something. Feedback welcome.

this has come up once or twice as there aren't many good libraries
for writing cross-platform terminal applications. to my surprise,
recent windows versions support xterm-like caps if you put the
console in a special mode. initializing the console, reading and
writing to it, and handling resize events are different but
everything else is the same.

`wcwidth` isn't available, so everything is assumed to occupy 1
column.

i haven't tested anything besides the keyboard demo, which seems to
work just fine.
@adsr adsr changed the title Add experimental support for windows (proof of concept) Add experimental support for Windows Console (proof of concept) Nov 5, 2023
@fenugrec

Copy link
Copy Markdown

agreed that's a lot of ifdefs. This would no longer be a single-header library if you split out platform-dependant stuff and then conditionally #include the right one.

I may attempt to code-gen a separate artifact termbox2-win.h

How would you do that ?
I guess at its simplest one could break up the whole file into chunks, i.e. termbox2-header.in, termbox-common.in, termbox-win_bits.in, termbox-unix_bits.in , and a dumb concatenation script (run on a pre-commit hook , so this repo has a versioned copy of both constructed headers ?)

@adsr

adsr commented Nov 18, 2023

Copy link
Copy Markdown
Contributor Author

Hi, thanks for looking at this. Yeah maybe something like that. Alternatively we can abstract the platform-dependent stuff into function table, one for POSIX, one for Windows. The extra layer would make the code slightly harder to read, but it would cut down on the number of ifdefs to maybe 2 or 3 and wouldn't introduce any new source files or codegen in the repo.

I'm also separately trying to see how many of the ifdefs are really necessary. For example I tried converting the stdio HANDLEs into plain fds using _open_osfhandle to see if read/write would work. It didn't. I could be doing something wrong though. I'll keep messing with it.

@adsr

adsr commented Jul 31, 2024

Copy link
Copy Markdown
Contributor Author

Closing in favor of another draft PR #66

@adsr adsr closed this Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants