Skip to content

Commit e966235

Browse files
authored
Merge branch 'rust-lang:main' into main
2 parents c4fd295 + a8b13f5 commit e966235

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/list/state.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub struct ListState<'a> {
4343
filter: Filter,
4444
term_width: u16,
4545
term_height: u16,
46-
separator_line: Vec<u8>,
4746
show_footer: bool,
4847
pub search_query: String,
4948
}
@@ -77,7 +76,6 @@ impl<'a> ListState<'a> {
7776
// Set by `set_term_size`
7877
term_width: 0,
7978
term_height: 0,
80-
separator_line: Vec::new(),
8179
show_footer: true,
8280
search_query: String::new(),
8381
};
@@ -97,14 +95,10 @@ impl<'a> ListState<'a> {
9795
}
9896

9997
let header_height = 1;
100-
// 2 separators, 1 progress bar, 2 footer message lines.
101-
let footer_height = 5;
98+
// 1 progress bar, 2 footer message lines.
99+
let footer_height = 3;
102100
self.show_footer = height > header_height + footer_height;
103101

104-
if self.show_footer {
105-
self.separator_line = "─".as_bytes().repeat(width as usize);
106-
}
107-
108102
self.scroll_state.set_max_n_rows_to_display(
109103
height.saturating_sub(header_height + u16::from(self.show_footer) * footer_height)
110104
as usize,
@@ -204,9 +198,6 @@ impl<'a> ListState<'a> {
204198
}
205199

206200
if self.show_footer {
207-
stdout.write_all(&self.separator_line)?;
208-
next_ln(stdout)?;
209-
210201
progress_bar(
211202
&mut MaxLenWriter::new(stdout, self.term_width as usize),
212203
self.app_state.n_done(),
@@ -215,9 +206,6 @@ impl<'a> ListState<'a> {
215206
)?;
216207
next_ln(stdout)?;
217208

218-
stdout.write_all(&self.separator_line)?;
219-
next_ln(stdout)?;
220-
221209
let mut writer = MaxLenWriter::new(stdout, self.term_width as usize);
222210
if self.message.is_empty() {
223211
// Help footer message

src/term.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use crossterm::{
77
cursor::MoveTo,
8-
style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor},
8+
style::{Attribute, Color, SetAttribute, SetForegroundColor},
99
terminal::{Clear, ClearType},
1010
Command, QueueableCommand,
1111
};
@@ -93,20 +93,19 @@ pub fn progress_bar<'a>(
9393
total: u16,
9494
line_width: u16,
9595
) -> io::Result<()> {
96+
debug_assert!(total < 1000);
9697
debug_assert!(progress <= total);
9798

9899
const PREFIX: &[u8] = b"Progress: [";
99100
const PREFIX_WIDTH: u16 = PREFIX.len() as u16;
100-
// Leaving the last char empty (_) for `total` > 99.
101-
const POSTFIX_WIDTH: u16 = "] xxx/xx exercises_".len() as u16;
101+
const POSTFIX_WIDTH: u16 = "] xxx/xxx".len() as u16;
102102
const WRAPPER_WIDTH: u16 = PREFIX_WIDTH + POSTFIX_WIDTH;
103103
const MIN_LINE_WIDTH: u16 = WRAPPER_WIDTH + 4;
104104

105105
if line_width < MIN_LINE_WIDTH {
106106
writer.write_ascii(b"Progress: ")?;
107107
// Integers are in ASCII.
108-
writer.write_ascii(format!("{progress}/{total}").as_bytes())?;
109-
return writer.write_ascii(b" exercises");
108+
return writer.write_ascii(format!("{progress}/{total}").as_bytes());
110109
}
111110

112111
let stdout = writer.stdout();
@@ -133,8 +132,9 @@ pub fn progress_bar<'a>(
133132
}
134133
}
135134

136-
stdout.queue(ResetColor)?;
137-
write!(stdout, "] {progress:>3}/{total} exercises")
135+
stdout.queue(SetForegroundColor(Color::Reset))?;
136+
137+
write!(stdout, "] {progress:>3}/{total}")
138138
}
139139

140140
pub fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> {

0 commit comments

Comments
 (0)