Can I use the System module for setting terminal attributes in a console app?

I'm teaching my kids how to program in Swift. One of the things that I thought would be fun in a roll-up-your-sleeves kind of way is to have them develop the compact Kilo text editor in Swift. The text editor is about 1,000 lines of C code and there is a fantastic step-by-step SnapToken tutorial to walk people through building their own text editor:

After having studied the code, I don't think it would be too hard for me to migrate it from C to Swift and thought that would be a fun project in and of itself.

It seems that all the code to covert the terminal from canonical mode to raw mode would require me to call C functions. I understand the general principles of doing that with bridging headers and wrappers. But, could I just use the new Swift System module to do it so that we can use idiomatic Swift?** Is there another way this could be done directly in Swift with no need to call C library functions/datatypes?

Appreciate anyone pointing me in the right direction. Thank you.

** We are developing on a Mac, so I understand that we have access to the System module.

I don't think Swift System currently supports this, so I think you'll have to call the C functions for now. You can get some idea of the APIs supported here.

1 Like

Ok. Thank you. I will review those APIs

Terms of Service

Privacy Policy

Cookie Policy