@@ -3,25 +3,29 @@ use crate::{dns, tweak, utils};
33
44use clap:: { Args , Parser , Subcommand } ;
55
6- pub struct CLI ;
6+ pub struct ConsoleUi ;
77
8- impl CLI {
8+ impl ConsoleUi {
99 pub fn new ( ) -> Self {
1010 Self { }
1111 }
1212}
1313
14- impl UI for CLI {
14+ impl UI for ConsoleUi {
1515 fn show_message ( & self , message_type : MessageType , message : & str , title : String ) {
16- let type_str = match message_type {
17- MessageType :: Info => "INFO" ,
18- MessageType :: Warning => "WARNING" ,
19- MessageType :: Error => "ERROR" ,
20- } ;
21- println ! ( "[{type_str}] {title}: {message}" ) ;
16+ println ! ( "{}" , format_message( message_type, message, & title) ) ;
2217 }
2318}
2419
20+ fn format_message ( message_type : MessageType , message : & str , title : & str ) -> String {
21+ let type_str = match message_type {
22+ MessageType :: Info => "INFO" ,
23+ MessageType :: Warning => "WARNING" ,
24+ MessageType :: Error => "ERROR" ,
25+ } ;
26+ format ! ( "[{type_str}] {title}: {message}" )
27+ }
28+
2529pub fn run_command ( command : & str , escalate : bool ) -> bool {
2630 let status = utils:: run_cmd ( command. into ( ) , escalate) . expect ( "failed to run cmd" ) ;
2731 status. success ( )
@@ -123,3 +127,25 @@ pub enum AppToLaunch {
123127 /// Launch the `CachyOS` Kernel Manager
124128 KernelManager ,
125129}
130+
131+ #[ cfg( test) ]
132+ mod test {
133+ use super :: * ;
134+ use crate :: ui:: MessageType ;
135+
136+ #[ test]
137+ fn show_message_formats_correctly ( ) {
138+ assert_eq ! (
139+ format_message( MessageType :: Info , "test message" , "Title" ) ,
140+ "[INFO] Title: test message"
141+ ) ;
142+ assert_eq ! (
143+ format_message( MessageType :: Warning , "test message" , "Title" ) ,
144+ "[WARNING] Title: test message"
145+ ) ;
146+ assert_eq ! (
147+ format_message( MessageType :: Error , "test message" , "Title" ) ,
148+ "[ERROR] Title: test message"
149+ ) ;
150+ }
151+ }
0 commit comments