cargo fmt, delete random c file

This commit is contained in:
2025-03-14 18:57:00 -04:00
parent 850d06d432
commit 333e52dc49
5 changed files with 7 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
#![warn(clippy::all, clippy::pedantic)] #![warn(clippy::all, clippy::pedantic)]
pub mod os;
pub mod ansi; pub mod ansi;
pub mod os;

View File

@@ -46,7 +46,8 @@ struct Termios {
cc: [u8; NCCS], cc: [u8; NCCS],
} }
#[must_use] pub fn is_terminal() -> bool { #[must_use]
pub fn is_terminal() -> bool {
unsafe { isatty(1) != 0 } unsafe { isatty(1) != 0 }
} }
@@ -85,14 +86,14 @@ pub fn disable_raw_mode() -> io::Result<()> {
fn get_attributes(fd: c_int, termios: &mut Termios) -> io::Result<()> { fn get_attributes(fd: c_int, termios: &mut Termios) -> io::Result<()> {
if unsafe { tcgetattr(fd, &raw mut *termios) } != 0 { if unsafe { tcgetattr(fd, &raw mut *termios) } != 0 {
return Err(io::Error::last_os_error()) return Err(io::Error::last_os_error());
} }
Ok(()) Ok(())
} }
fn set_attributes(fd: c_int, termios: &mut Termios) -> io::Result<()> { fn set_attributes(fd: c_int, termios: &mut Termios) -> io::Result<()> {
if unsafe { tcsetattr(fd, 0, std::ptr::from_mut(termios)) } != 0 { if unsafe { tcsetattr(fd, 0, std::ptr::from_mut(termios)) } != 0 {
return Err(io::Error::last_os_error()) return Err(io::Error::last_os_error());
} }
Ok(()) Ok(())
} }

View File

@@ -9,7 +9,7 @@ const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 4;
const ENABLE_ECHO_INPUT: u32 = 4; const ENABLE_ECHO_INPUT: u32 = 4;
const ENABLE_LINE_INPUT: u32 = 2; const ENABLE_LINE_INPUT: u32 = 2;
const ENABLE_PROCESSED_INPUT: u32 = 1; const ENABLE_PROCESSED_INPUT: u32 = 1;
const INVALID_HANDLE_VALUE: usize = usize::MAX-1; const INVALID_HANDLE_VALUE: usize = usize::MAX - 1;
unsafe extern "system" { unsafe extern "system" {
fn GetStdHandle(nStdHandle: u32) -> usize; fn GetStdHandle(nStdHandle: u32) -> usize;
@@ -43,7 +43,7 @@ pub fn is_terminal() -> bool {
Ok(handle) => { Ok(handle) => {
let mut dwMode = 0; let mut dwMode = 0;
return unsafe { GetConsoleMode(handle, &mut dwMode) != 0 }; return unsafe { GetConsoleMode(handle, &mut dwMode) != 0 };
}, }
_ => false, _ => false,
} }
} }

13
test.c
View File

@@ -1,13 +0,0 @@
#include <stdio.h>
#include <termios.h>
#include <sys/ioctl.h>
int main() {
printf("ECHO: 0x%x\n", ECHO);
printf("ICANON: 0x%x\n", ICANON);
printf("ISIG: 0x%x\n", ISIG);
printf("\nNCCS: 0x%x\n", NCCS);
printf("TIOCFWINSZ: 0x%x\n", TIOCGWINSZ);
return 0;
}

BIN
test.o

Binary file not shown.