@@ -7,22 +7,28 @@ use std::io::{self, StdoutLock, Write};
77
88use crate :: {
99 cmd:: CmdRunner ,
10- term:: { self , CountedWrite , terminal_file_link, write_ansi} ,
10+ term:: { self , CountedWrite , file_path , terminal_file_link, write_ansi} ,
1111} ;
1212
1313/// The initial capacity of the output buffer.
1414pub const OUTPUT_CAPACITY : usize = 1 << 14 ;
1515
16- pub fn solution_link_line ( stdout : & mut StdoutLock , solution_path : & str ) -> io:: Result < ( ) > {
16+ pub fn solution_link_line (
17+ stdout : & mut StdoutLock ,
18+ solution_path : & str ,
19+ emit_file_links : bool ,
20+ ) -> io:: Result < ( ) > {
1721 stdout. queue ( SetAttribute ( Attribute :: Bold ) ) ?;
1822 stdout. write_all ( b"Solution" ) ?;
1923 stdout. queue ( ResetColor ) ?;
2024 stdout. write_all ( b" for comparison: " ) ?;
21- if let Some ( canonical_path) = term:: canonicalize ( solution_path) {
22- terminal_file_link ( stdout, solution_path, & canonical_path, Color :: Cyan ) ?;
23- } else {
24- stdout. write_all ( solution_path. as_bytes ( ) ) ?;
25- }
25+ file_path ( stdout, Color :: Cyan , |writer| {
26+ if emit_file_links && let Some ( canonical_path) = term:: canonicalize ( solution_path) {
27+ terminal_file_link ( writer, solution_path, & canonical_path)
28+ } else {
29+ writer. stdout ( ) . write_all ( solution_path. as_bytes ( ) )
30+ }
31+ } ) ?;
2632 stdout. write_all ( b"\n " )
2733}
2834
@@ -72,12 +78,18 @@ pub struct Exercise {
7278}
7379
7480impl Exercise {
75- pub fn terminal_file_link < ' a > ( & self , writer : & mut impl CountedWrite < ' a > ) -> io:: Result < ( ) > {
76- if let Some ( canonical_path) = self . canonical_path . as_deref ( ) {
77- return terminal_file_link ( writer, self . path , canonical_path, Color :: Blue ) ;
78- }
79-
80- writer. write_str ( self . path )
81+ pub fn terminal_file_link < ' a > (
82+ & self ,
83+ writer : & mut impl CountedWrite < ' a > ,
84+ emit_file_links : bool ,
85+ ) -> io:: Result < ( ) > {
86+ file_path ( writer, Color :: Blue , |writer| {
87+ if emit_file_links && let Some ( canonical_path) = self . canonical_path . as_deref ( ) {
88+ terminal_file_link ( writer, self . path , canonical_path)
89+ } else {
90+ writer. write_str ( self . path )
91+ }
92+ } )
8193 }
8294}
8395
0 commit comments