@@ -19,13 +19,9 @@ use enum_dispatch::enum_dispatch;
1919#[ cfg( feature = "test" ) ]
2020use rand:: { thread_rng, Rng } ;
2121
22- pub mod cwdsource;
2322pub mod filesource;
24- mod homethunk;
2523pub mod terminalsource;
2624
27- use cwdsource:: * ;
28-
2925/// An abstraction for the current process.
3026///
3127/// This acts as a clonable proxy to the global state provided by some key OS
@@ -61,11 +57,11 @@ use cwdsource::*;
6157/// methods are in performance critical loops (except perhaps progress bars -
6258/// and even there we should be doing debouncing and managing update rates).
6359#[ enum_dispatch]
64- pub trait CurrentProcess : CurrentDirSource + Debug { }
60+ pub trait CurrentProcess : Debug { }
6561
6662/// Allows concrete types for the currentprocess abstraction.
6763#[ derive( Clone , Debug ) ]
68- #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
64+ #[ enum_dispatch( CurrentProcess ) ]
6965pub enum Process {
7066 OSProcess ( OSProcess ) ,
7167 #[ cfg( feature = "test" ) ]
@@ -145,6 +141,14 @@ impl Process {
145141 }
146142 }
147143
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+
148152 #[ cfg( test) ]
149153 fn id ( & self ) -> u64 {
150154 match self {
@@ -155,6 +159,32 @@ impl Process {
155159 }
156160}
157161
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+
158188/// Obtain the current instance of CurrentProcess
159189pub fn process ( ) -> Process {
160190 home_process ( )
0 commit comments