@@ -145,8 +145,28 @@ impl Mode for NavigationMode {
145145
146146 fn footer ( & self , ctx : & TableContext ) -> FooterLine {
147147 use ratatui:: text:: Span ;
148- FooterLine {
149- hint : Some ( Line :: from ( vec ! [
148+ let hint = if let Some ( stats) = ctx. selection_stats ( ) {
149+ Line :: from ( vec ! [
150+ Span :: styled( "平均值=" , Style :: default ( ) . fg( ctx. theme. accent) ) ,
151+ Span :: styled(
152+ format!( " {}" , format_number( stats. average) ) ,
153+ Style :: default ( ) . fg( ctx. theme. text_dim) ,
154+ ) ,
155+ Span :: styled( " " , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
156+ Span :: styled( "求和=" , Style :: default ( ) . fg( ctx. theme. accent) ) ,
157+ Span :: styled(
158+ format!( " {}" , format_number( stats. sum) ) ,
159+ Style :: default ( ) . fg( ctx. theme. text_dim) ,
160+ ) ,
161+ Span :: styled( " " , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
162+ Span :: styled( "计数=" , Style :: default ( ) . fg( ctx. theme. accent) ) ,
163+ Span :: styled(
164+ format!( " {}" , stats. count) ,
165+ Style :: default ( ) . fg( ctx. theme. text_dim) ,
166+ ) ,
167+ ] )
168+ } else {
169+ Line :: from ( vec ! [
150170 Span :: styled( "Ctrl+S" , Style :: default ( ) . fg( ctx. theme. accent) ) ,
151171 Span :: styled( " 保存" , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
152172 Span :: styled( " " , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
@@ -155,7 +175,11 @@ impl Mode for NavigationMode {
155175 Span :: styled( " " , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
156176 Span :: styled( "Enter" , Style :: default ( ) . fg( ctx. theme. accent) ) ,
157177 Span :: styled( " 编辑" , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
158- ] ) ) ,
178+ ] )
179+ } ;
180+
181+ FooterLine {
182+ hint : Some ( hint) ,
159183 status : Some ( Line :: from ( vec ! [
160184 Span :: styled( "[" , Style :: default ( ) . fg( ctx. theme. text_dim) ) ,
161185 Span :: styled(
@@ -208,3 +232,18 @@ impl NavigationMode {
208232 }
209233 }
210234}
235+
236+ fn format_number ( n : f64 ) -> String {
237+ if n == 0.0 {
238+ return "0" . to_string ( ) ;
239+ }
240+
241+ let abs = n. abs ( ) ;
242+ if abs < 1e-6 || abs >= 1e12 {
243+ return format ! ( "{:.2e}" , n) ;
244+ }
245+
246+ let text = format ! ( "{:.10}" , n) ;
247+ let text = text. trim_end_matches ( '0' ) ;
248+ text. trim_end_matches ( '.' ) . to_string ( )
249+ }
0 commit comments