statig icon indicating copy to clipboard operation
statig copied to clipboard

Would be awesome to have an attribute that draws an ASCII picture of the resulting tree

Open matthewgapp opened this issue 1 year ago • 5 comments

Thinking something like

#[state_machine(visualize)]
impl MyStruct { ... } 

fn main() { 
  let mut state_machine = Blinky::default().uninitialized_state_machine().init();
  let ascii_visualization: String = state_machine.visualize();
  println!("{}", ascii_visualiztion);
}

Which would print something like

                          ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐             
                                    Top                       
                          └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘             
                                     │                        
                        ┌────────────┴────────────┐           
                        │                         │           
             ┌─────────────────────┐   ╔═════════════════════╗
             │      Blinking       │   ║     NotBlinking     ║
             │─────────────────────│   ╚═════════════════════╝
             │ counter: &'a usize  │                          
             └─────────────────────┘                          
                        │                                     
           ┌────────────┴────────────┐                        
           │                         │                        
╔═════════════════════╗   ╔═════════════════════╗             
║        LedOn        ║   ║        LedOff       ║             
║─────────────────────║   ║─────────────────────║             
║ counter: usize      ║   ║ counter: usize      ║             
╚═════════════════════╝   ╚═════════════════════╝

matthewgapp avatar Mar 10 '23 02:03 matthewgapp