Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Conversation

adsr
Copy link
Contributor

@adsr adsr commented Nov 5, 2023

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

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
Copy link
Contributor Author

adsr commented Nov 18, 2023

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
Copy link
Contributor Author

adsr commented Jul 31, 2024

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