@@ -18,13 +18,9 @@ use enum_dispatch::enum_dispatch;
18
18
#[ cfg( feature = "test" ) ]
19
19
use rand:: { thread_rng, Rng } ;
20
20
21
- pub mod cwdsource;
22
21
pub mod filesource;
23
- mod homethunk;
24
22
pub mod terminalsource;
25
23
26
- use cwdsource:: * ;
27
-
28
24
use crate :: utils:: tty:: { stderr_isatty, stdout_isatty} ;
29
25
30
26
/// An abstraction for the current process.
@@ -62,11 +58,11 @@ use crate::utils::tty::{stderr_isatty, stdout_isatty};
62
58
/// methods are in performance critical loops (except perhaps progress bars -
63
59
/// and even there we should be doing debouncing and managing update rates).
64
60
#[ enum_dispatch]
65
- pub trait CurrentProcess : CurrentDirSource + Debug { }
61
+ pub trait CurrentProcess : Debug { }
66
62
67
63
/// Allows concrete types for the currentprocess abstraction.
68
64
#[ derive( Clone , Debug ) ]
69
- #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
65
+ #[ enum_dispatch( CurrentProcess ) ]
70
66
pub enum Process {
71
67
OSProcess ( OSProcess ) ,
72
68
#[ cfg( feature = "test" ) ]
@@ -146,6 +142,14 @@ impl Process {
146
142
}
147
143
}
148
144
145
+ pub ( crate ) fn current_dir ( & self ) -> io:: Result < PathBuf > {
146
+ match self {
147
+ Process :: OSProcess ( _) => env:: current_dir ( ) ,
148
+ #[ cfg( feature = "test" ) ]
149
+ Process :: TestProcess ( p) => Ok ( p. cwd . clone ( ) ) ,
150
+ }
151
+ }
152
+
149
153
#[ cfg( test) ]
150
154
fn id ( & self ) -> u64 {
151
155
match self {
@@ -156,6 +160,32 @@ impl Process {
156
160
}
157
161
}
158
162
163
+ impl home:: env:: Env for Process {
164
+ fn home_dir ( & self ) -> Option < PathBuf > {
165
+ match self {
166
+ Process :: OSProcess ( _) => self . var ( "HOME" ) . ok ( ) . map ( |v| v. into ( ) ) ,
167
+ #[ cfg( feature = "test" ) ]
168
+ Process :: TestProcess ( _) => home:: env:: OS_ENV . home_dir ( ) ,
169
+ }
170
+ }
171
+
172
+ fn current_dir ( & self ) -> Result < PathBuf , io:: Error > {
173
+ match self {
174
+ Process :: OSProcess ( _) => self . current_dir ( ) ,
175
+ #[ cfg( feature = "test" ) ]
176
+ Process :: TestProcess ( _) => home:: env:: OS_ENV . current_dir ( ) ,
177
+ }
178
+ }
179
+
180
+ fn var_os ( & self , key : & str ) -> Option < OsString > {
181
+ match self {
182
+ Process :: OSProcess ( _) => self . var_os ( key) ,
183
+ #[ cfg( feature = "test" ) ]
184
+ Process :: TestProcess ( _) => self . var_os ( key) ,
185
+ }
186
+ }
187
+ }
188
+
159
189
/// Obtain the current instance of CurrentProcess
160
190
pub fn process ( ) -> Process {
161
191
home_process ( )
0 commit comments