Initial commit

This commit is contained in:
s-prechtl 2023-06-20 13:56:47 +02:00
parent 67bfb15b87
commit 3c01cf1f0c
4 changed files with 42 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "screen-flip"
version = "0.1.0"

4
Cargo.toml Normal file
View file

@ -0,0 +1,4 @@
[package]
name = "screen-flip"
version = "0.1.0"
edition = "2021"

30
src/main.rs Normal file
View file

@ -0,0 +1,30 @@
use std::fs::{read_to_string, write};
fn find_first_number_position(input: &str) -> Option<usize> {
let mut position = None;
for (idx, c) in input.chars().enumerate() {
if c.is_digit(10) {
position = Some(idx);
break;
}
}
position
}
fn main() {
let path = "/home/sprechtl/.config/hypr/transform.conf";
let input = read_to_string(&path).expect("Could not read transform.conf");
let index_of_number = find_first_number_position(&input).expect("No number in line");
let mut output = "".to_string();
if let Some(tranform) = input.chars().nth(index_of_number) {
output = input.chars().take(index_of_number).collect::<String>();
if tranform == '0' {
output.push('2');
} else {
output.push('0');
}
} else {
panic!("Could not find tranform");
}
write(path, output).expect("Could not write transform.conf");
}