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