Skip to content

Commit ff89e1e

Browse files
committed
formatting changes
1 parent 92cf0d7 commit ff89e1e

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/handlers/execution.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,15 @@ impl fmt::Display for RuntimeError {
102102
let seperator = "-------------------------------";
103103
write!(
104104
f,
105-
"{}\nTestcase {} failed during execution!\n{}\n{}\n {}\n\n{}\n{}\n{}\n{}",
105+
"{}\nTestcase {} failed during execution!\n{sep}\n{}\n{}\n\n{}\n{}\n{sep}\n{}",
106106
"Runtime Error!".red().bold(),
107107
format!("{}", self.std_output.len()).red(),
108-
seperator.yellow(),
109108
"Error Message :".yellow(),
110109
self.runtime_error,
111110
"Full error message :".yellow(),
112111
self.full_runtime_error,
113-
seperator.yellow(),
114-
format!("{}\n{:?}", "Std Output :".yellow(), self.std_output)
112+
format!("{}\n{:?}", "Std Output :".yellow(), self.std_output),
113+
sep = seperator.yellow(),
115114
)
116115
}
117116
}
@@ -136,23 +135,22 @@ impl fmt::Display for Success {
136135
for i in 0..self.code_answer.len() {
137136
let is_correct = self.compare_result.chars().nth(i).unwrap_or('0') == '1';
138137
part2.push(format!(
139-
"{1}\n{2}\n{3}\n{0:10}: {4:?}\n{7:10}: {5:?}\n\n{6}",
138+
"{sep}\n{1}\n{sep}\n{0:10}: {2:?}\n{5:10}: {3:?}\n\n{4}",
140139
"Output",
141-
seperator.yellow(),
142140
if is_correct {
143141
format!("Testcase {} execution success", i + 1).green()
144142
} else {
145143
format!("Testcase {} execution failed", i + 1).red()
146144
},
147-
seperator.yellow(),
148145
self.code_answer[i],
149146
self.expected_code_answer[i],
150147
if !self.std_output[i].is_empty() {
151148
format!("Std Output :\n{}\n", self.std_output[i])
152149
} else {
153150
String::new()
154151
},
155-
"Expected"
152+
"Expected",
153+
sep = seperator.yellow()
156154
));
157155
}
158156

@@ -176,7 +174,7 @@ impl fmt::Display for Success {
176174
.italic()
177175
.to_string()
178176
} else {
179-
"".to_string()
177+
String::new()
180178
},
181179
);
182180

@@ -189,7 +187,18 @@ impl fmt::Display for Success {
189187
.min(100),
190188
"Memory",
191189
);
192-
write!(f, "{}{}{}{}", part1, part2.join(""), part3, part4)
190+
191+
let part5 = format!(
192+
"{seperator}\n{:10}: {}",
193+
"Status",
194+
if self.is_correct() {
195+
"Testcase execution success".green().italic()
196+
} else {
197+
"Testcase execution failed".yellow().italic()
198+
},
199+
seperator = seperator.yellow()
200+
);
201+
write!(f, "{}{}{}{}{}", part1, part2.join(""), part3, part4, part5)
193202
}
194203
}
195204

src/handlers/helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ impl fmt::Display for DailyChallenge {
117117
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118118
write!(
119119
f,
120-
"Title : {}\nDifficulty : {}\nDate : {}\nStatus : {}\nAC Rate : {:.2}%",
120+
"{title_txt:12}: {}\n{diff:12}: {}\n{date:12}: {}\n{status:12}: {}\n{ac_rate:12}: {:.2}%",
121121
self.question.title.bright_cyan(),
122122
Difficulty::from_str(&self.question.difficulty).map_err(|_| fmt::Error)?,
123123
self.date,
124124
self.userStatus,
125125
self.question.acRate
126+
, title_txt = "Title", diff = "Difficulty", ac_rate = "AC Rate",
127+
date = "Date", status = "Status"
126128
)
127129
}
128130
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() -> Result<()> {
3232
},
3333
Some(Commands::DailyChallenge) => {
3434
let daily_challenge = lc.get_daily_challenge()?;
35-
println!("Today's Daily Challenge: {}", daily_challenge);
35+
println!("Today's Daily Challenge:\n{}", daily_challenge);
3636
let title = daily_challenge.question.titleSlug;
3737
let question = lc.question_content(&title)?;
3838

src/utils.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ pub(crate) fn execute_testcases<P: AsRef<Path>>(
4848
match lc.execute_default(&code_file)? {
4949
ExecutionResult::Success(result) => {
5050
println!("{}", result);
51-
// if !result.is_correct() {
52-
// println!(
53-
// "{}",
54-
// "Testcases can be found in testcase.txt".yellow().italic()
55-
// );
56-
// }
5751
return Ok((result.is_correct(), code_file));
5852
}
5953
ExecutionResult::LimitExceeded(limit_exceeded) => {

0 commit comments

Comments
 (0)