passing tests now

This commit is contained in:
filipriec_vm
2026-01-11 23:20:52 +01:00
parent 1044003179
commit 91ac418bc0
6 changed files with 14 additions and 44 deletions

View File

@@ -1,6 +1,6 @@
extern crate alloc; extern crate alloc;
use tui_orchestrator::focus::{FocusBuilder, FocusId, FocusManager, Focusable}; use tui_orchestrator::focus::{FocusId, FocusManager, Focusable};
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum FormElement { enum FormElement {
@@ -10,6 +10,8 @@ enum FormElement {
Submit, Submit,
} }
impl FocusId for FormElement {}
struct FormPage { struct FormPage {
username: alloc::string::String, username: alloc::string::String,
password: alloc::string::String, password: alloc::string::String,
@@ -46,12 +48,4 @@ fn main() {
println!("Is first: {}", focus_manager.is_first()); println!("Is first: {}", focus_manager.is_first());
println!("Is last: {}", focus_manager.is_last()); println!("Is last: {}", focus_manager.is_last());
println!("\n--- FocusBuilder Demo ---");
let builder = FocusBuilder::new()
.target(FormElement::Username)
.target(FormElement::Password)
.target(FormElement::Submit);
let targets = builder.build();
println!("Built targets: {:?}", targets);
} }

View File

@@ -1,6 +1,6 @@
extern crate alloc; extern crate alloc;
use tui_orchestrator::focus::{FocusManager, Focusable}; use tui_orchestrator::focus::{FocusId, FocusManager, Focusable};
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum FormElement { enum FormElement {
@@ -11,6 +11,8 @@ enum FormElement {
Cancel, Cancel,
} }
impl FocusId for FormElement {}
#[allow(dead_code)] #[allow(dead_code)]
struct LoginForm { struct LoginForm {
username: String, username: String,

View File

@@ -1,5 +1,3 @@
// path_from_the_root: src/component/mod.rs
pub mod action; pub mod action;
pub mod error; pub mod error;
pub mod r#trait; pub mod r#trait;

View File

@@ -1,11 +1,10 @@
// path_from_the_root: src/component/trait.rs
use super::error::ComponentError; use super::error::ComponentError;
use crate::focus::FocusId; use crate::focus::FocusId;
use crate::input::Action;
pub trait Component { pub trait Component {
type Focus: FocusId; type Focus: FocusId;
type Action: core::fmt::Debug + Clone; type Action: Action;
type Event: Clone + core::fmt::Debug; type Event: Clone + core::fmt::Debug;
fn targets(&self) -> &[Self::Focus]; fn targets(&self) -> &[Self::Focus];

View File

@@ -1,6 +1,7 @@
extern crate alloc; extern crate alloc;
use tui_orchestrator::component::{Component, ComponentAction}; use tui_orchestrator::component::{Component, ComponentAction};
use tui_orchestrator::focus::FocusId;
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum TestFocus { enum TestFocus {
@@ -9,6 +10,8 @@ enum TestFocus {
ButtonC, ButtonC,
} }
impl FocusId for TestFocus {}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum TestEvent { enum TestEvent {
ButtonCPressed, ButtonCPressed,

View File

@@ -1,6 +1,6 @@
extern crate alloc; extern crate alloc;
use tui_orchestrator::focus::{FocusError, FocusManager, Focusable}; use tui_orchestrator::focus::{FocusError, FocusId, FocusManager, Focusable};
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[allow(dead_code)] #[allow(dead_code)]
@@ -11,6 +11,8 @@ enum TestId {
Dialog, Dialog,
} }
impl FocusId for TestId {}
#[test] #[test]
fn test_focus_id_trait() { fn test_focus_id_trait() {
let id1 = TestId::Button("save"); let id1 = TestId::Button("save");
@@ -253,31 +255,3 @@ fn test_focusable_trait() {
let targets = component.focus_targets(); let targets = component.focus_targets();
assert_eq!(targets.len(), 3); assert_eq!(targets.len(), 3);
} }
#[test]
fn test_usize_focus_id() {
let mut manager: FocusManager<usize> = FocusManager::new();
manager.set_targets(vec![0, 1, 2, 3]);
assert_eq!(manager.current(), Some(&0));
manager.next();
assert_eq!(manager.current(), Some(&1));
manager.set_focus(3).unwrap();
assert_eq!(manager.current(), Some(&3));
}
#[test]
fn test_string_focus_id() {
let mut manager: FocusManager<&str> = FocusManager::new();
manager.set_targets(vec!["input1", "input2", "button_save"]);
assert_eq!(manager.current(), Some(&"input1"));
manager.next();
assert_eq!(manager.current(), Some(&"input2"));
manager.set_focus("button_save").unwrap();
assert_eq!(manager.current(), Some(&"button_save"));
}