@@ -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-
2824use crate :: utils:: tty:: { stderr_isatty, stdout_isatty} ;
2925
3026/// An abstraction for the current process.
@@ -62,11 +58,11 @@ use crate::utils::tty::{stderr_isatty, stdout_isatty};
6258/// methods are in performance critical loops (except perhaps progress bars -
6359/// and even there we should be doing debouncing and managing update rates).
6460#[ enum_dispatch]
65- pub trait CurrentProcess : CurrentDirSource + Debug { }
61+ pub trait CurrentProcess : Debug { }
6662
6763/// Allows concrete types for the currentprocess abstraction.
6864#[ derive( Clone , Debug ) ]
69- #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
65+ #[ enum_dispatch( CurrentProcess ) ]
7066pub enum Process {
7167 OSProcess ( OSProcess ) ,
7268 #[ cfg( feature = "test" ) ]
@@ -146,6 +142,14 @@ impl Process {
146142 }
147143 }
148144
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+
149153 #[ cfg( test) ]
150154 fn id ( & self ) -> u64 {
151155 match self {
@@ -156,6 +160,32 @@ impl Process {
156160 }
157161}
158162
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+
159189/// Obtain the current instance of CurrentProcess
160190pub fn process ( ) -> Process {
161191 home_process ( )
0 commit comments