mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-07-03 00:46:57 +02:00
Dump solution and show its path
This commit is contained in:
@ -2,33 +2,11 @@ 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>,
|
||||
@ -85,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user