From d82a5f6e1bc878b0e6a695f88eb69404ca6d571d Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Sun, 16 Jun 2024 17:07:21 +0200 Subject: Make platform dependent code possible to disable by disabling libc and ansi features --- src/main.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 16de4cd..e97b085 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ -use std::io::{self, BufRead, Write}; +#[cfg(feature = "libc")] +use std::io::Write; +use std::io::{self, BufRead}; use std::str::FromStr; use textgraph::graph::GraphBuilder; use textgraph::parseopts::{parseopts, OptsBuilder}; +#[cfg(feature = "libc")] extern "C" fn handle_sigint(_sig: i32) { print!("\x1b[?25h"); print!("\x1B[?1049l"); @@ -11,6 +14,7 @@ extern "C" fn handle_sigint(_sig: i32) { } /// Set a signalhandler for swapping back to the the main screen on sigint +#[cfg(feature = "libc")] fn set_filter_signalhandler() { let mut sig_action: libc::sigaction = unsafe { std::mem::zeroed() }; sig_action.sa_flags = 0; @@ -56,9 +60,12 @@ fn build_graph(x_values: &Vec, y_values: &Vec, opts: &OptsBuilder) -> /// /// * `opts` - textgraph::parseopts::OptBuilder fn filter(opts: OptsBuilder) { - set_filter_signalhandler(); - print!("\x1b[?1049h"); - print!("\x1b[?25l"); + #[cfg(feature = "libc")] + { + set_filter_signalhandler(); + print!("\x1b[?1049h"); + print!("\x1b[?25l"); + } let mut x_values: Vec = Vec::new(); let mut y_values: Vec = Vec::new(); @@ -73,6 +80,7 @@ fn filter(opts: OptsBuilder) { y_values.push(y); x_values.push(i); + #[cfg(feature = "ansi")] print!("\x1B[2J\x1B[H"); println!("{}", build_graph(&x_values, &y_values, &opts)); } -- cgit v1.2.3