Skip to content

Commit

Permalink
🐳 chore: Makes clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
wychlw committed Sep 22, 2024
1 parent 6392d94 commit 781d5d1
Show file tree
Hide file tree
Showing 15 changed files with 3,260 additions and 263 deletions.
3,393 changes: 3,189 additions & 204 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "tester"
crate-type = ["cdylib"]
crate-type = ["cdylib", "staticlib", "rlib"]

[dependencies]
pyo3 = "0.22.0"
Expand All @@ -25,6 +25,13 @@ xcap = "0.0.13"
enigo = "0.2.1"
portable-pty = "0.8.1"
inventory = "0.3.15"
eframe = "0.28.1"
egui_extras = "0.28.1"

[toolchain]
channel = "nightly"

[[test]]
name = "ui_test"
path = "tests/ui_test.rs"
harness = false
2 changes: 1 addition & 1 deletion src/cli/deansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Tty for DeANSI {

/// Write data to the Tty
fn write(&mut self, data: &[u8]) -> Result<(), Box<dyn Error>> {
let data = strip_ansi_escapes::strip(&data);
let data = strip_ansi_escapes::strip(data);
self.inner.write(&data)?;
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion src/cli/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum SshPass {
Key(String), // Path to private key
}

#[allow(dead_code)]
pub struct Ssh {
// sess: Session,
channel: Arc<Mutex<Channel>>,
Expand Down Expand Up @@ -102,7 +103,7 @@ impl Ssh {

Ssh {
// sess: sess,
channel: channel,
channel,
buff,
stop,
handle: Some(handle),
Expand Down
10 changes: 3 additions & 7 deletions src/devhost/sdwirec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ use crate::info;

use super::devhost::DevHost;

#[derive(Default)]
pub struct Sdwirec {}

impl Sdwirec {
pub fn new() -> Sdwirec {
Sdwirec {}
}
}

#[allow(static_mut_refs)]
impl DevHost<Sdwirec> for Sdwirec {
fn get_device() -> Arc<Mutex<Sdwirec>> {
static mut DEVICE: Option<Arc<Mutex<Sdwirec>>> = None;
unsafe {
DEVICE
.get_or_insert_with(|| Arc::new(Mutex::new(Sdwirec::new())))
.get_or_insert_with(|| Arc::new(Mutex::new(Sdwirec::default())))
.clone()
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/device/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ use std::error::Error;
use crate::cli::{ssh::SshPass, tty::DynTty};


struct ShellOptions {
pub struct ShellOptions {
shell: Option<String>,
}

struct SerialOptions {
pub struct SerialOptions {
port: String,
baud: u32,
}

struct SshOptions {
pub struct SshOptions {
host: String,
port: u16,
user: String,
Expand Down
6 changes: 3 additions & 3 deletions src/exec/gui_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ impl GuiTestApi for GuiTestor {
let screen = self.read()?;
let mut res = None;
for handler in inventory::iter::<HandlerCollector> {
if !handler.inner.can_handle(&needle) {
if !handler.inner.can_handle(needle) {
continue;
}
res = Some(handler.inner.handle(&needle, &screen) || res.unwrap_or(false));
res = Some(handler.inner.handle(needle, &screen) || res.unwrap_or(false));
}
match res {
Some(true) => Ok(Some(())),
Expand All @@ -131,7 +131,7 @@ impl GuiTestApi for GuiTestor {
})
}
fn assert_screen_click(&mut self, needle: &Needle, timeout: u32) -> Result<(), Box<dyn Error>> {
self.assert_screen(&needle, timeout)?;
self.assert_screen(needle, timeout)?;
if !needle.is_basic() {
return Err("Only Basic Needle support this".into());
}
Expand Down
2 changes: 1 addition & 1 deletion src/exec/gui_handler/basic_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn basic_handle_once(area: &Area, screen: &RgbaImage) -> bool {
let similarity = match_count as f32 / total_count as f32;
similarity >= area.match_threhold
}
NeedleType::Ocr => return false,
NeedleType::Ocr => false,
NeedleType::Exclude => {
let mut match_count = 0;
let total_count = screen.width() * screen.height() - area.width * area.height;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::util::anybase::AnyBase;

/// A Screen trait, used to interact with a screen
pub trait Screen: AnyBase {
//! Get the size of the Screen

/// Get the size of the Screen
fn size(&self) -> (u32, u32);

/// Read the contents of the Screen as an image
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(box_into_inner)]
#![feature(macro_metavar_expr_concat)]
#![allow(clippy::module_inception)]

pub mod consts;
pub mod cli;
Expand All @@ -14,9 +16,8 @@ pub mod device {
pub mod util {
pub mod anybase;
pub mod logger;
pub mod singleton;
pub mod util;
}
pub mod pythonapi;
pub mod vendor;

pub mod ui;
4 changes: 3 additions & 1 deletion src/pythonapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use serial::Serial;
use shell::Shell;
use tee::Tee;
use shell_like::PyTty;
use util::{get_log_level, set_log_level};
use util::{get_log_level, run_ui, set_log_level};

#[pymodule]
#[pyo3(name = "tester")]
Expand All @@ -45,6 +45,8 @@ fn tester(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(set_log_level, m)?)?;
m.add_function(wrap_pyfunction!(get_log_level, m)?)?;

m.add_function(wrap_pyfunction!(run_ui, m)?)?;

m.add_function(wrap_pyfunction!(info, m)?)?;
m.add_function(wrap_pyfunction!(log, m)?)?;
m.add_function(wrap_pyfunction!(warn, m)?)?;
Expand Down
24 changes: 14 additions & 10 deletions src/pythonapi/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use pyo3::pyfunction;

use crate::util::logger::LogLevel;
use pyo3::{exceptions::PyRuntimeError, pyfunction, PyResult};

use crate::{ui::main::AppUi, util::logger::LogLevel};

#[pyfunction]
pub fn set_log_level(level: &str) {
Expand All @@ -17,12 +16,17 @@ pub fn set_log_level(level: &str) {

#[pyfunction]
pub fn get_log_level() -> String {
let level = crate::util::logger::LogLevelConf::get();
let level = crate::util::logger::get_log_level();
match level {
0 => "Debug".to_string(),
10 => "Info".to_string(),
20 => "Warn".to_string(),
30 => "Error".to_string(),
_ => "Debug".to_string(),
LogLevel::Debug => "Debug".to_string(),
LogLevel::Info => "Info".to_string(),
LogLevel::Warn => "Warn".to_string(),
LogLevel::Error => "Error".to_string(),
}
}
}

#[pyfunction]
pub fn run_ui() -> PyResult<()> {
AppUi::new().map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
Ok(())
}
35 changes: 26 additions & 9 deletions src/util/logger.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
use colored::Colorize;

use crate::singleton;

pub enum LogLevel {
Debug = 0,
Info = 10,
Warn = 20,
Error = 30,
}

singleton!(LogLevelConf, i32, LogLevel::Info as i32);
static mut LOG_LEVEL: i32 = LogLevel::Info as i32;

fn __get_log_level() -> i32 {
unsafe { LOG_LEVEL }
}

fn __set_log_level(level: LogLevel) {
unsafe {
LOG_LEVEL = level as i32;
}
}

pub fn __log(s: &str) {
if *LogLevelConf::get() <= LogLevel::Debug as i32 {
if __get_log_level() <= LogLevel::Debug as i32 {
println!("{} {}", "[LOG]".blue(), s);
}
}
Expand All @@ -23,7 +31,7 @@ macro_rules! log {
}

pub fn __info(s: &str) {
if *LogLevelConf::get() <= LogLevel::Info as i32 {
if __get_log_level() <= LogLevel::Info as i32 {
println!("{} {}", "[INFO]".green(), s);
}
}
Expand All @@ -34,7 +42,7 @@ macro_rules! info {
}

pub fn __warn(s: &str) {
if *LogLevelConf::get() <= LogLevel::Warn as i32 {
if __get_log_level() <= LogLevel::Warn as i32 {
eprintln!("{} {}", "[WARN]".yellow(), s);
}
}
Expand All @@ -45,7 +53,7 @@ macro_rules! warn {
}

pub fn __err(s: &str) {
if *LogLevelConf::get() <= LogLevel::Error as i32 {
if __get_log_level() <= LogLevel::Error as i32 {
eprintln!("{} {}", "[ERROR]".red(), s);
}
}
Expand All @@ -55,7 +63,16 @@ macro_rules! err {
($($arg:tt)*) => ($crate::util::logger::__err(&format!($($arg)*)))
}

pub fn get_log_level() -> LogLevel {
match __get_log_level() {
0 => LogLevel::Debug,
10 => LogLevel::Info,
20 => LogLevel::Warn,
30 => LogLevel::Error,
_ => LogLevel::Debug,
}
}

pub fn set_log_level(level: LogLevel) {
let l = LogLevelConf::get();
*l = level as i32;
__set_log_level(level);
}
17 changes: 0 additions & 17 deletions src/util/singleton.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/util/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
#[macro_export]
macro_rules! todo {
() => {
Err(Box::<dyn Error>::from("TODO"))
Err("TODO".into())
};
}

#[macro_export]
macro_rules! unfinished {
() => {
Err(Box::<dyn Error>::from("UNFINISHED"))
Err("UNFINISHED".into())
};
}

Expand Down

0 comments on commit 781d5d1

Please sign in to comment.