use crate::error::Result;
use crate::{AutoIt, Point, Selector};
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum MouseCursor {
Unknown = 0,
AppStarting = 1,
Arrow = 2,
Cross = 3,
Help = 4,
IBeam = 5,
Icon = 6,
No = 7,
Size = 8,
SizeAll = 9,
SizeNeSw = 10,
SizeNs = 11,
SizeNwSe = 12,
SizeWe = 13,
UpArrow = 14,
Wait = 15,
}
impl MouseCursor {
#[must_use]
pub const fn from_code(code: i32) -> Self {
match code {
1 => Self::AppStarting,
2 => Self::Arrow,
3 => Self::Cross,
4 => Self::Help,
5 => Self::IBeam,
6 => Self::Icon,
7 => Self::No,
8 => Self::Size,
9 => Self::SizeAll,
10 => Self::SizeNeSw,
11 => Self::SizeNs,
12 => Self::SizeNwSe,
13 => Self::SizeWe,
14 => Self::UpArrow,
15 => Self::Wait,
_ => Self::Unknown,
}
}
#[must_use]
pub const fn is_idle(self) -> bool {
matches!(self, Self::Arrow | Self::IBeam)
}
}
pub fn win_set_trans(ai: &AutoIt, window: &Selector, alpha: u8) -> Result<bool> {
ai.inner().win_set_trans(window, alpha)
}
pub fn win_menu_select_item(ai: &AutoIt, window: &Selector, path: &[&str]) -> Result<bool> {
ai.inner().win_menu_select_item(window, path)
}
pub fn statusbar_get_text(ai: &AutoIt, window: &Selector, part: u32) -> Result<String> {
ai.inner().statusbar_get_text(window, part)
}
pub fn caret_pos(ai: &AutoIt) -> Result<Point> {
ai.inner().win_get_caret_pos()
}
pub fn run_as(
ai: &AutoIt,
user: &str,
domain: &str,
password: &str,
command: &str,
working_dir: Option<&str>,
wait: bool,
) -> Result<i32> {
ai.inner()
.run_as(user, domain, password, command, working_dir, wait)
}
pub fn shutdown(ai: &AutoIt, flags: i32) -> Result<bool> {
ai.inner().shutdown(flags)
}
pub fn drive_map_add(
ai: &AutoIt,
device: &str,
share: &str,
user: &str,
password: &str,
) -> Result<String> {
ai.inner().drive_map_add(device, share, user, password)
}
pub fn drive_map_del(ai: &AutoIt, device: &str) -> Result<bool> {
ai.inner().drive_map_del(device)
}
pub fn drive_map_get(ai: &AutoIt, device: &str) -> Result<String> {
ai.inner().drive_map_get(device)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn idle_is_arrow_or_ibeam_only() {
assert!(MouseCursor::from_code(2).is_idle());
assert!(MouseCursor::from_code(5).is_idle());
assert!(!MouseCursor::from_code(15).is_idle()); assert!(!MouseCursor::from_code(1).is_idle()); }
#[test]
fn unknown_codes_do_not_panic() {
assert_eq!(MouseCursor::from_code(-1), MouseCursor::Unknown);
assert_eq!(MouseCursor::from_code(9999), MouseCursor::Unknown);
assert!(!MouseCursor::from_code(9999).is_idle());
}
}