From 3c01cf1f0c01f9bc7238bf79543372866e711ff4 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 20 Jun 2023 13:56:47 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 4 ++++ src/main.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c6c6184 --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e9afa49 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "screen-flip" +version = "0.1.0" +edition = "2021" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0b67f83 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,30 @@ +use std::fs::{read_to_string, write}; + +fn find_first_number_position(input: &str) -> Option { + 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::(); + 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"); +}