@@ -17,7 +17,6 @@ mod ui;
1717
1818use crate :: { filehost, serial} ;
1919use anyhow:: Result ;
20- use crossterm:: event:: KeyCode ;
2120use serialport:: SerialPort ;
2221use ui:: { StatefulList , StatefulTable } ;
2322
@@ -95,69 +94,34 @@ impl App {
9594 Ok ( ( ) )
9695 }
9796
98- // @todo this should be moved to ui.rs so that mod.rs is independent of crossterm
99- pub fn keypress ( & mut self , key : crossterm:: event:: KeyCode ) -> Result < ( ) > {
100- match key {
101- KeyCode :: Enter => {
102- match self . active_widget {
103- AppWidgets :: FileSelector => self . select_filehost_item ( ) ?,
104- AppWidgets :: FileAction => self . select_file_action ( ) ?,
105- AppWidgets :: CBMBrowser => self . select_cbm_item ( ) ?,
106- _ => { }
107- }
108- }
97+ /// Go to previous item in current widget (typically when pressing arrow up)
98+ pub fn previous_item ( & mut self ) {
99+ match self . active_widget {
100+ AppWidgets :: CBMBrowser => self . cbm_browser . previous ( ) ,
101+ AppWidgets :: FileAction => self . file_action . previous ( ) ,
102+ AppWidgets :: FileSelector => self . filetable . previous ( ) ,
109103 _ => { }
110104 }
105+ }
106+
107+ /// Go to next item in current widget (typically when pressing arrow down)
108+ pub fn next_item ( & mut self ) {
111109 match self . active_widget {
112- AppWidgets :: CBMBrowser => match key {
113- KeyCode :: Down => {
114- self . cbm_browser . next ( ) ;
115- Ok ( ( ) )
116- }
117- KeyCode :: Up => {
118- self . cbm_browser . previous ( ) ;
119- Ok ( ( ) )
120- }
121- _ => Ok ( ( ) ) ,
122- } ,
123- AppWidgets :: FileAction => match key {
124- KeyCode :: Down => {
125- self . file_action . next ( ) ;
126- Ok ( ( ) )
127- }
128- KeyCode :: Up => {
129- self . file_action . previous ( ) ;
130- Ok ( ( ) )
131- }
132- _ => Ok ( ( ) ) ,
133- } ,
134- AppWidgets :: FileSelector => match key {
135- KeyCode :: Down => {
136- self . filetable . next ( ) ;
137- Ok ( ( ) )
138- }
139- KeyCode :: Up => {
140- self . filetable . previous ( ) ;
141- Ok ( ( ) )
142- }
143- KeyCode :: Char ( 's' ) => {
144- self . sort_filehost ( ) ;
145- Ok ( ( ) )
146- }
147- _ => Ok ( ( ) ) ,
148- } ,
149- _ => Ok ( ( ) ) ,
110+ AppWidgets :: CBMBrowser => self . cbm_browser . next ( ) ,
111+ AppWidgets :: FileAction => self . file_action . next ( ) ,
112+ AppWidgets :: FileSelector => self . filetable . next ( ) ,
113+ _ => { }
150114 }
151115 }
152116
153- fn escape_to_filehost_browser ( & mut self ) {
117+ fn return_to_filehost ( & mut self ) {
154118 self . set_current_widget ( AppWidgets :: FileSelector ) ;
155119 self . file_action . unselect ( ) ;
156120 }
157121
158122 /// Select currently highlighted file in FileHost browser
159123 fn select_filehost_item ( & mut self ) -> Result < ( ) , anyhow:: Error > {
160- // when selecting file, go to file action widget
124+ // when selecting file, go to file action widget
161125 self . active_widget = AppWidgets :: FileAction ;
162126 if !self . file_action . is_selected ( ) {
163127 self . file_action . state . select ( Some ( 0 ) ) ;
@@ -259,4 +223,11 @@ impl App {
259223 }
260224 Ok ( ( ) )
261225 }
226+
227+ /// Send reset signal to MEGA65
228+ pub fn reset ( & mut self ) -> Result < ( ) > {
229+ crate :: serial:: reset ( & mut self . port ) ?;
230+ self . add_message ( "Reset MEGA65" ) ;
231+ Ok ( ( ) )
232+ }
262233}
0 commit comments