mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Highlight selected row
This commit is contained in:
parent
b779c43126
commit
28d0b0a21e
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor::{MoveTo, MoveToNextLine},
|
cursor::{MoveTo, MoveToNextLine},
|
||||||
style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor},
|
style::{Attribute, Color, ResetColor, SetAttribute, SetBackgroundColor, SetForegroundColor},
|
||||||
terminal::{self, BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate},
|
terminal::{self, BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate},
|
||||||
QueueableCommand,
|
QueueableCommand,
|
||||||
};
|
};
|
||||||
|
@ -115,6 +115,11 @@ impl<'a> ListState<'a> {
|
||||||
let mut n_displayed_rows = 0;
|
let mut n_displayed_rows = 0;
|
||||||
for (exercise_ind, exercise) in displayed_exercises {
|
for (exercise_ind, exercise) in displayed_exercises {
|
||||||
if self.selected == Some(n_displayed_rows) {
|
if self.selected == Some(n_displayed_rows) {
|
||||||
|
stdout.queue(SetBackgroundColor(Color::Rgb {
|
||||||
|
r: 50,
|
||||||
|
g: 50,
|
||||||
|
b: 50,
|
||||||
|
}))?;
|
||||||
stdout.write_all("🦀".as_bytes())?;
|
stdout.write_all("🦀".as_bytes())?;
|
||||||
} else {
|
} else {
|
||||||
stdout.write_all(b" ")?;
|
stdout.write_all(b" ")?;
|
||||||
|
@ -135,7 +140,7 @@ impl<'a> ListState<'a> {
|
||||||
stdout.write_all(b"PENDING ")?;
|
stdout.write_all(b"PENDING ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.queue(ResetColor)?;
|
stdout.queue(SetForegroundColor(Color::Reset))?;
|
||||||
|
|
||||||
stdout.write_all(exercise.name.as_bytes())?;
|
stdout.write_all(exercise.name.as_bytes())?;
|
||||||
stdout.write_all(&SPACE[..self.name_col_width + 2 - exercise.name.len()])?;
|
stdout.write_all(&SPACE[..self.name_col_width + 2 - exercise.name.len()])?;
|
||||||
|
@ -143,6 +148,7 @@ impl<'a> ListState<'a> {
|
||||||
stdout.write_all(exercise.path.as_bytes())?;
|
stdout.write_all(exercise.path.as_bytes())?;
|
||||||
|
|
||||||
next_ln::<true>(stdout)?;
|
next_ln::<true>(stdout)?;
|
||||||
|
stdout.queue(ResetColor)?;
|
||||||
n_displayed_rows += 1;
|
n_displayed_rows += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue