1
0

tui_task.rs 891 B

1234567891011121314151617181920212223242526272829303132
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus::tui::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let count = use_state(&cx, || 0);
  7. use_future(&cx, (), move |_| {
  8. let count = count.to_owned();
  9. let update = cx.schedule_update();
  10. async move {
  11. loop {
  12. count.with_mut(|f| *f += 1);
  13. tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
  14. update();
  15. }
  16. }
  17. });
  18. cx.render(rsx! {
  19. div { width: "100%",
  20. div { width: "50%", height: "5px", background_color: "blue", justify_content: "center", align_items: "center",
  21. "Hello {count}!"
  22. }
  23. div { width: "50%", height: "10px", background_color: "red", justify_content: "center", align_items: "center",
  24. "Hello {count}!"
  25. }
  26. }
  27. })
  28. }