pub fn disable_custom_mode() {
    if unsafe { TTYFD } == 0 {
        return;
    }


    // Set tty settings to our saved original values
    let ret: i32;
    unsafe {
        asm!("syscall",
            in("rax") 16, // SYS_IOCTL
            in("rdi") TTYFD,
            in("rsi") TCSETS,
            in("rdx") &TTYTERMIOS as *const Termios,
            out("rcx") _,
            out("r11") _,
            lateout("rax") ret,
        );
    }

    assert!(!ret.is_negative(), "SYS_IOCTL TCSETS returned an error: {}", ret);

    // Close the tty fd
    let ret: i32;
    unsafe {
        asm!("syscall",
            in("rax") 3, // SYS_CLOSE
            in("rdi") TTYFD,
            out("rcx") _,
            out("r11") _,
            lateout("rax") ret,
        );
    }

    assert!(!ret.is_negative(), "SYS_CLOSE returned an error: {}", ret);

    unsafe {
        TTYFD = 0;
    }

    let data = "\x1b[2J\x1b[?1049l\x1b[?25h";
    unsafe {
        asm!("syscall",
            in("rax") 1, // SYS_WRITE
            in("rdi") 1,
            in("rsi") data.as_ptr(),
            in("rdx") data.len(),
            out("rcx") _,
            out("r11") _,
            lateout("rax") _,
        );
    }
}
// Reset tty settings to original settings and close tty fd
Reset tty settings to original settings and close tty fd
Reset tty settings to original settings and close tty fd
pub fn disable_custom_mode() {
    if unsafe { TTYFD } == 0 {
        return;
    }
    // Set tty settings to our saved original values
    let ret: i32;
    unsafe {
        asm!("syscall",
            in("rax") 16, // SYS_IOCTL
            in("rdi") TTYFD,
            in("rsi") TCSETS,
            in("rdx") &TTYTERMIOS as *const Termios,
            out("rcx") _,
            out("r11") _,
            lateout("rax") ret,
        );
    }
    assert!(!ret.is_negative(), "SYS_IOCTL TCSETS returned an error: {}", ret);
    // Close the tty fd
    let ret: i32;
    unsafe {
        asm!("syscall",
            in("rax") 3, // SYS_CLOSE
            in("rdi") TTYFD,
            out("rcx") _,
            out("r11") _,
            lateout("rax") ret,
        );
    }
    assert!(!ret.is_negative(), "SYS_CLOSE returned an error: {}", ret);
    unsafe {
        TTYFD = 0;
    }
    let data = "\x1b[2J\x1b[?1049l\x1b[?25h";
    unsafe {
        asm!("syscall",
            in("rax") 1, // SYS_WRITE
            in("rdi") 1,
            in("rsi") data.as_ptr(),
            in("rdx") data.len(),
            out("rcx") _,
            out("r11") _,
            lateout("rax") _,
        );
    }
}
pub fn disable_custom_mode ( ) { if unsafe { TTYFD } == 0 { return ; } // Set tty settings to our saved original values let ret : i32 ; unsafe { asm ! ( " " in ( " " ) 16 // SYS_IOCTL in ( " " ) TTYFD in ( " " ) TCSETS in ( " " ) TTYTERMIOS as const Termios out ( " " ) out ( " " ) lateout ( " " ) ret ) ; } assert ! ( ret is_negative ( ) " " ret ) ; // Close the tty fd let ret : i32 ; unsafe { asm ! ( " " in ( " " ) 3 // SYS_CLOSE in ( " " ) TTYFD out ( " " ) out ( " " ) lateout ( " " ) ret ) ; } assert ! ( ret is_negative ( ) " " ret ) ; unsafe { TTYFD = 0 ; } let data = " \x1b \x1b \x1b " ; unsafe { asm ! ( " " in ( " " ) 1 // SYS_WRITE in ( " " ) 1 in ( " " ) data as_ptr ( ) in ( " " ) data len ( ) out ( " " ) out ( " " ) lateout ( " " ) ) ; } }
Reset tty settings to original settings and close tty fd
Reset tty settings to original settings and close tty fd