pub struct Screen { /* private fields */ }Expand description
A rendered Script Filter result screen.
Screen wraps the parsed JSON output from an Alfred workflow invocation,
providing read-only accessors for inspecting items and their properties.
When created by a Simulator, it also carries graph
context for action routing.
§Example
use alfrusco::simulator::Screen;
let json = r#"{"items":[{"title":"Hello","arg":"world","valid":true}]}"#;
let screen = Screen::from_json(json).unwrap();
assert_eq!(screen.items().len(), 1);
assert_eq!(screen.items()[0].title(), "Hello");
assert_eq!(screen.items()[0].arg(), Some("world"));
assert!(screen.items()[0].is_valid());Implementations§
Source§impl Screen
impl Screen
Sourcepub fn from_json(json: &str) -> Result<Self, ScreenError>
pub fn from_json(json: &str) -> Result<Self, ScreenError>
Parses a JSON string (Alfred Script Filter output) into a Screen.
A Screen created this way has no graph context; Screen::action will
return None. Use Simulator to get action-routable screens.
§Errors
Returns an error if the JSON is invalid or missing the items array.
Sourcepub fn with_context(self, graph: Arc<WorkflowGraph>, source_uid: String) -> Self
pub fn with_context(self, graph: Arc<WorkflowGraph>, source_uid: String) -> Self
Creates a screen with graph context for action routing.
This is useful for testing action resolution without a full
Simulator setup — parse JSON via Screen::from_json,
then attach a graph.
Sourcepub fn items(&self) -> &[ScreenItem]
pub fn items(&self) -> &[ScreenItem]
Returns the items on this screen.
Sourcepub fn assert_renders(&self)
pub fn assert_renders(&self)
Sourcepub fn action(&self, index: usize) -> Option<ActionResult>
pub fn action(&self, index: usize) -> Option<ActionResult>
Determines the action result for the item at the given index.
Walks the workflow graph from the source Script Filter to determine what would happen if the user actioned this item (with the given modifier bitmask, defaulting to 0 for no modifiers).
Returns None if this screen has no graph context (created via
Screen::from_json rather than a Simulator).
§Panics
Panics if index is out of bounds.
Sourcepub fn action_first(&self) -> Option<ActionResult>
pub fn action_first(&self) -> Option<ActionResult>
Determines the action result for the first item on this screen.
Convenience wrapper around Screen::action with index 0.
Returns None if this screen has no graph context or is empty.
Sourcepub fn action_with_modifiers(
&self,
index: usize,
modifiers: u64,
) -> Option<ActionResult>
pub fn action_with_modifiers( &self, index: usize, modifiers: u64, ) -> Option<ActionResult>
Determines the action result for the item at the given index with a specific modifier bitmask.
Alfred modifier bitmasks: Cmd=1048576, Alt=524288, Ctrl=262144, Shift=131072, Fn=8388608. Combine with bitwise OR.
Returns None if this screen has no graph context.
§Panics
Panics if index is out of bounds.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Screen
impl RefUnwindSafe for Screen
impl Send for Screen
impl Sync for Screen
impl Unpin for Screen
impl UnsafeUnpin for Screen
impl UnwindSafe for Screen
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more