https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
n

napperley

11/17/2021, 12:21 AM
Trying to translate
NewSettings.c_lflag &= ~( ICANON | ECHO );
(C language) to Kotlin, and have hit a brick wall 🧱 with the bit manipulation since there appears to be some bit manipulation operations that can't be done in Kotlin, unless there are some workarounds available. Below is the full C code I am trying to translate into Kotlin:
Copy code
#include <termios.h>
static struct termios OriginalSettings, NewSettings;
void terminal_setup()
{
    tcgetattr(STDIN_FILENO, &OriginalSettings);
    NewSettings = OriginalSettings;
    NewSettings.c_lflag &= ~( ICANON | ECHO );
    tcsetattr(STDIN_FILENO, TCSANOW, &NewSettings);
    printf("\e[?25l");
}
void terminal_reset()
{
    tcsetattr (STDIN_FILENO, TCSAFLUSH, &OriginalSettings);
}
m

mbonnin

11/17/2021, 7:37 AM
I'd do something like:
Copy code
val settings = alloc<termios>()
      settings.c_cflag = settings.c_cflag.and(ICANON.or(ECHO).inv().toULong())
That's modulo the
toULong()
not overflowing or so but it should work?