@@ -47,38 +47,25 @@ fn main() -> std::io::Result<()> {
4747
4848 println ! ( "mode: {mode}\r " ) ;
4949
50- run ( move |key| match mode {
51- "home" => {
52- let Some ( Actions :: Home ( config) ) = modes. get ( mode) else {
53- return false ;
54- } ;
55-
56- match config. get ( & key) {
57- Some ( action) => match action {
58- HomeAction :: Quit => quit ( "quit!" ) ,
59- HomeAction :: Edit => {
60- mode = "edit" ;
61- print ( "enter edit mode!" )
62- }
63- } ,
64- None => print ( & format ! ( "{}" , key. code) ) ,
65- }
66- }
67- "edit" => {
68- let Some ( Actions :: Edit ( config) ) = modes. get ( mode) else {
69- return false ;
70- } ;
71-
72- match config. get ( & key) {
73- Some ( action) => match action {
74- EditAction :: Exit => {
75- mode = "home" ;
76- print ( "exit edit mode!" )
77- }
78- } ,
79- None => print ( & format ! ( "{}" , key. code) ) ,
80- }
81- }
82- _ => unreachable ! ( ) ,
50+ run ( move |key| match modes. get ( mode) . unwrap ( ) {
51+ Actions :: Home ( config) => match config. get ( & key) {
52+ Some ( action) => match action {
53+ HomeAction :: Quit => quit ( "quit!" ) ,
54+ HomeAction :: Edit => {
55+ mode = "edit" ;
56+ print ( "enter edit mode!" )
57+ }
58+ } ,
59+ None => print ( & format ! ( "{}" , key. code) ) ,
60+ } ,
61+ Actions :: Edit ( config) => match config. get ( & key) {
62+ Some ( action) => match action {
63+ EditAction :: Exit => {
64+ mode = "home" ;
65+ print ( "exit edit mode!" )
66+ }
67+ } ,
68+ None => print ( & format ! ( "{}" , key. code) ) ,
69+ } ,
8370 } )
8471}
0 commit comments