@@ -10,6 +10,7 @@ use crate::FyiError;
1010use dactyl:: traits:: BytesToUnsigned ;
1111use fyi_msg:: {
1212 Msg ,
13+ MsgFlags ,
1314 MsgKind ,
1415} ;
1516use std:: {
@@ -19,76 +20,65 @@ use std::{
1920
2021
2122
23+ // Flags generated by build.rs.
24+ include ! ( concat!( env!( "OUT_DIR" ) , "/flags.rs" ) ) ;
25+
26+
27+
2228#[ derive( Debug , Clone , Copy ) ]
2329/// # Message Settings.
2430///
2531/// Most of these settings will get embedded into the `Msg` itself, but there
2632/// are a couple parts that do not get referenced until print time.
2733pub ( super ) struct Settings {
2834 /// # Flags.
29- flags : u8 ,
35+ flags : Flags ,
3036
3137 /// # Exit.
3238 exit : ExitCode ,
3339}
3440
3541impl Settings {
36- /// # Indent Message.
37- const FLAG_INDENT : u8 = 0b0001 ;
38-
39- /// # Print to STDERR.
40- const FLAG_STDERR : u8 = 0b0010 ;
41-
42- /// # Include Timestamp.
43- const FLAG_TIMESTAMP : u8 = 0b0100 ;
44-
45- /// # Default Yes (for Prompt).
46- const FLAG_YES : u8 = 0b1000 ;
47-
4842 /// # Exit Code.
4943 pub ( super ) fn exit ( self ) -> Result < ( ) , FyiError > {
5044 if self . exit == ExitCode :: SUCCESS { Ok ( ( ) ) }
5145 else { Err ( FyiError :: Passthrough ( self . exit ) ) }
5246 }
5347
5448 /// # Stderr?
55- pub ( super ) const fn stderr ( self ) -> bool {
56- Self :: FLAG_STDERR == self . flags & Self :: FLAG_STDERR
57- }
49+ pub ( super ) const fn stderr ( self ) -> bool { self . flags . contains ( Flags :: Stderr ) }
5850
5951 /// # Default Yes?
60- pub ( super ) const fn yes ( self ) -> bool {
61- Self :: FLAG_YES == self . flags & Self :: FLAG_YES
62- }
52+ pub ( super ) const fn yes ( self ) -> bool { self . flags . contains ( Flags :: Yes ) }
6353
6454 /// # Convert to `Msg` Flags.
65- const fn msg_flags ( self ) -> u8 {
66- let mut flags: u8 = fyi_msg :: FLAG_NEWLINE ;
67- if Self :: FLAG_INDENT == self . flags & Self :: FLAG_INDENT {
68- flags |= fyi_msg :: FLAG_INDENT ;
55+ const fn msg_flags ( self ) -> MsgFlags {
56+ let mut flags = MsgFlags :: Newline ;
57+ if self . flags . contains ( Flags :: Indent ) {
58+ flags = flags . with ( MsgFlags :: Indent ) ;
6959 }
70- if Self :: FLAG_TIMESTAMP == self . flags & Self :: FLAG_TIMESTAMP {
71- flags |= fyi_msg :: FLAG_TIMESTAMP ;
60+ if self . flags . contains ( Flags :: Timestamp ) {
61+ flags = flags . with ( MsgFlags :: Timestamp ) ;
7262 }
7363 flags
7464 }
7565
7666 /// # New.
7767 const fn new ( ) -> Self {
78- Self { flags : 0 , exit : ExitCode :: SUCCESS }
68+ Self { flags : Flags :: None , exit : ExitCode :: SUCCESS }
7969 }
8070
8171 /// # Set Indent.
82- fn set_indent ( & mut self ) { self . flags |= Self :: FLAG_INDENT ; }
72+ fn set_indent ( & mut self ) { self . flags |= Flags :: Indent ; }
8373
8474 /// # Set Stderr.
85- fn set_stderr ( & mut self ) { self . flags |= Self :: FLAG_STDERR ; }
75+ fn set_stderr ( & mut self ) { self . flags |= Flags :: Stderr ; }
8676
8777 /// # Set Timestamp.
88- fn set_timestamp ( & mut self ) { self . flags |= Self :: FLAG_TIMESTAMP ; }
78+ fn set_timestamp ( & mut self ) { self . flags |= Flags :: Timestamp ; }
8979
9080 /// # Set Yes.
91- fn set_yes ( & mut self ) { self . flags |= Self :: FLAG_YES ; }
81+ fn set_yes ( & mut self ) { self . flags |= Flags :: Yes ; }
9282}
9383
9484
0 commit comments