Skip to content

Commit 28d0b0a

Browse files
committed
Highlight selected row
1 parent b779c43 commit 28d0b0a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/list/state.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{Context, Result};
22
use crossterm::{
33
cursor::{MoveTo, MoveToNextLine},
4-
style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor},
4+
style::{Attribute, Color, ResetColor, SetAttribute, SetBackgroundColor, SetForegroundColor},
55
terminal::{self, BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate},
66
QueueableCommand,
77
};
@@ -115,6 +115,11 @@ impl<'a> ListState<'a> {
115115
let mut n_displayed_rows = 0;
116116
for (exercise_ind, exercise) in displayed_exercises {
117117
if self.selected == Some(n_displayed_rows) {
118+
stdout.queue(SetBackgroundColor(Color::Rgb {
119+
r: 50,
120+
g: 50,
121+
b: 50,
122+
}))?;
118123
stdout.write_all("🦀".as_bytes())?;
119124
} else {
120125
stdout.write_all(b" ")?;
@@ -135,14 +140,15 @@ impl<'a> ListState<'a> {
135140
stdout.write_all(b"PENDING ")?;
136141
}
137142

138-
stdout.queue(ResetColor)?;
143+
stdout.queue(SetForegroundColor(Color::Reset))?;
139144

140145
stdout.write_all(exercise.name.as_bytes())?;
141146
stdout.write_all(&SPACE[..self.name_col_width + 2 - exercise.name.len()])?;
142147

143148
stdout.write_all(exercise.path.as_bytes())?;
144149

145150
next_ln::<true>(stdout)?;
151+
stdout.queue(ResetColor)?;
146152
n_displayed_rows += 1;
147153
}
148154

0 commit comments

Comments
 (0)