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