@@ -18,13 +18,9 @@ use enum_dispatch::enum_dispatch;
1818#[ cfg( feature = "test" ) ]
1919use rand:: { thread_rng, Rng } ;
2020
21- pub mod cwdsource;
2221pub mod filesource;
23- mod homethunk;
2422pub mod terminalsource;
2523
26- use cwdsource:: * ;
27-
2824/// An abstraction for the current process.
2925///
3026/// This acts as a clonable proxy to the global state provided by some key OS
@@ -60,11 +56,11 @@ use cwdsource::*;
6056/// methods are in performance critical loops (except perhaps progress bars -
6157/// and even there we should be doing debouncing and managing update rates).
6258#[ enum_dispatch]
63- pub trait CurrentProcess : CurrentDirSource + Debug { }
59+ pub trait CurrentProcess : Debug { }
6460
6561/// Allows concrete types for the currentprocess abstraction.
6662#[ derive( Clone , Debug ) ]
67- #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
63+ #[ enum_dispatch( CurrentProcess ) ]
6864pub enum Process {
6965 OSProcess ( OSProcess ) ,
7066 #[ cfg( feature = "test" ) ]
@@ -144,6 +140,14 @@ impl Process {
144140 }
145141 }
146142
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+
147151 #[ cfg( test) ]
148152 fn id ( & self ) -> u64 {
149153 match self {
@@ -154,6 +158,32 @@ impl Process {
154158 }
155159}
156160
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+
157187/// Obtain the current instance of CurrentProcess
158188pub fn process ( ) -> Process {
159189 home_process ( )
0 commit comments