File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Anything that implements Display can be wrapped in a DisplayModel.
2
+
3
+ use std:: fs:: read_dir;
4
+ use std:: io;
5
+ use std:: thread:: sleep;
6
+ use std:: time:: Duration ;
7
+
8
+ use nutmeg:: models:: DisplayModel ;
9
+
10
+ fn main ( ) -> io:: Result < ( ) > {
11
+ let options = nutmeg:: Options :: default ( ) ;
12
+ let model = DisplayModel :: new ( String :: new ( ) ) ;
13
+ let view = nutmeg:: View :: new ( model, options) ;
14
+ for p in read_dir ( "." ) ? {
15
+ let dir_entry = p?;
16
+ view. update ( |DisplayModel ( message) | * message = dir_entry. path ( ) . display ( ) . to_string ( ) ) ;
17
+ sleep ( Duration :: from_millis ( 300 ) ) ;
18
+ }
19
+ Ok ( ( ) )
20
+ }
Original file line number Diff line number Diff line change @@ -287,6 +287,13 @@ where
287
287
#[ derive( Debug ) ]
288
288
pub struct DisplayModel < T : Display + Debug > ( pub T ) ;
289
289
290
+ impl < T : Display + Debug > DisplayModel < T > {
291
+ /// Construct a new model holding a value implementing `Display`.
292
+ pub fn new ( value : T ) -> DisplayModel < T > {
293
+ DisplayModel ( value)
294
+ }
295
+ }
296
+
290
297
impl < T : Display + Debug > Model for DisplayModel < T > {
291
298
fn render ( & mut self , _width : usize ) -> String {
292
299
format ! ( "{}" , self . 0 )
You can’t perform that action at this time.
0 commit comments