diff options
| author | Mo <76752051+mo8it@users.noreply.github.com> | 2024-04-24 02:56:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-24 02:56:20 +0200 |
| commit | 53fdb9044d54dbdf5f0aa6c309cd285829a04b3a (patch) | |
| tree | b45b6f11597130690232b2eaa9621f25ecf98200 /src/exercise.rs | |
| parent | 86684b7fc9dd5e8bedad6056565645d1d980925c (diff) | |
| parent | 8a085a0a85c759029cd57c28364867bde817e738 (diff) | |
Merge pull request #1955 from rust-lang/solutions
Solutions
Diffstat (limited to 'src/exercise.rs')
| -rw-r--r-- | src/exercise.rs | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/src/exercise.rs b/src/exercise.rs index e85efe4..45ac208 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -2,35 +2,14 @@ use anyhow::{Context, Result}; use crossterm::style::{style, StyledContent, Stylize}; use std::{ fmt::{self, Display, Formatter}, - fs, path::Path, process::{Command, Output}, }; -use crate::{info_file::Mode, DEBUG_PROFILE}; - -pub struct TerminalFileLink<'a> { - path: &'a str, -} - -impl<'a> Display for TerminalFileLink<'a> { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - if let Ok(Some(canonical_path)) = fs::canonicalize(self.path) - .as_deref() - .map(|path| path.to_str()) - { - write!( - f, - "\x1b]8;;file://{}\x1b\\{}\x1b]8;;\x1b\\", - canonical_path, self.path, - ) - } else { - write!(f, "{}", self.path,) - } - } -} +use crate::{info_file::Mode, terminal_link::TerminalFileLink, DEBUG_PROFILE}; pub struct Exercise { + pub dir: Option<&'static str>, // Exercise's unique name pub name: &'static str, // Exercise's path @@ -84,9 +63,7 @@ impl Exercise { } pub fn terminal_link(&self) -> StyledContent<TerminalFileLink<'_>> { - style(TerminalFileLink { path: self.path }) - .underlined() - .blue() + style(TerminalFileLink(self.path)).underlined().blue() } } |
