@@ -7,22 +7,28 @@ use std::io::{self, StdoutLock, Write};
7
7
8
8
use crate :: {
9
9
cmd:: CmdRunner ,
10
- term:: { self , CountedWrite , terminal_file_link, write_ansi} ,
10
+ term:: { self , CountedWrite , file_path , terminal_file_link, write_ansi} ,
11
11
} ;
12
12
13
13
/// The initial capacity of the output buffer.
14
14
pub const OUTPUT_CAPACITY : usize = 1 << 14 ;
15
15
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 < ( ) > {
17
21
stdout. queue ( SetAttribute ( Attribute :: Bold ) ) ?;
18
22
stdout. write_all ( b"Solution" ) ?;
19
23
stdout. queue ( ResetColor ) ?;
20
24
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
+ } ) ?;
26
32
stdout. write_all ( b"\n " )
27
33
}
28
34
@@ -72,12 +78,18 @@ pub struct Exercise {
72
78
}
73
79
74
80
impl 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
+ } )
81
93
}
82
94
}
83
95
0 commit comments