Skip to content

Commit

Permalink
Merge pull request #2745 from hi-rustin/rustin-patch-cleanup-currentp…
Browse files Browse the repository at this point in the history
…rocess

Make some pub structs/functions crate-public
  • Loading branch information
rbtcollins authored May 4, 2021
2 parents 44be718 + 1d03dbc commit 8e632bb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/cli/term2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ mod termhack {
// - Disable all terminal controls on non-tty's
// - Swallow errors when we try to use features a terminal doesn't have
// such as setting colours when no TermInfo DB is present
pub struct AutomationFriendlyTerminal<T>(Box<dyn term::Terminal<Output = T> + Send>)
pub(crate) struct AutomationFriendlyTerminal<T>(Box<dyn term::Terminal<Output = T> + Send>)
where
T: Isatty + io::Write;
pub type StdoutTerminal = AutomationFriendlyTerminal<Box<dyn Writer>>;
pub type StderrTerminal = AutomationFriendlyTerminal<Box<dyn Writer>>;
pub(crate) type StdoutTerminal = AutomationFriendlyTerminal<Box<dyn Writer>>;
pub(crate) type StderrTerminal = AutomationFriendlyTerminal<Box<dyn Writer>>;

macro_rules! swallow_unsupported {
( $call:expr ) => {{
Expand Down Expand Up @@ -225,14 +225,14 @@ lazy_static! {
Mutex::new(term::terminfo::TermInfo::from_env().ok());
}

pub fn stdout() -> StdoutTerminal {
pub(crate) fn stdout() -> StdoutTerminal {
let info_result = TERMINFO.lock().unwrap().clone();
AutomationFriendlyTerminal(termhack::make_terminal_with_fallback(info_result, || {
process().stdout()
}))
}

pub fn stderr() -> StderrTerminal {
pub(crate) fn stderr() -> StderrTerminal {
let info_result = TERMINFO.lock().unwrap().clone();
AutomationFriendlyTerminal(termhack::make_terminal_with_fallback(info_result, || {
process().stderr()
Expand Down
26 changes: 13 additions & 13 deletions src/currentprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::sync::{Arc, Mutex};

use rand::{thread_rng, Rng};

pub mod argsource;
pub mod cwdsource;
pub mod filesource;
pub(crate) mod argsource;
pub(crate) mod cwdsource;
pub(crate) mod filesource;
mod homethunk;
pub mod varsource;
pub(crate) mod varsource;

use argsource::*;
use cwdsource::*;
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn process() -> Box<dyn CurrentProcess> {
}

/// Obtain the current instance of HomeProcess
pub fn home_process() -> Box<dyn HomeProcess> {
pub(crate) fn home_process() -> Box<dyn HomeProcess> {
match PROCESS.with(|p| p.borrow().clone()) {
None => panic!("No process instance"),
Some(p) => p,
Expand Down Expand Up @@ -163,7 +163,7 @@ fn clear_process() {
}

thread_local! {
pub static PROCESS:RefCell<Option<Box<dyn HomeProcess>>> = RefCell::new(None);
pub(crate) static PROCESS:RefCell<Option<Box<dyn HomeProcess>>> = RefCell::new(None);
}

// PID related things
Expand Down Expand Up @@ -191,13 +191,13 @@ impl ProcessSource for OSProcess {

#[derive(Clone, Debug, Default)]
pub struct TestProcess {
pub cwd: PathBuf,
pub args: Vec<String>,
pub vars: HashMap<String, String>,
pub id: u64,
pub stdin: TestStdinInner,
pub stdout: TestWriterInner,
pub stderr: TestWriterInner,
pub(crate) cwd: PathBuf,
pub(crate) args: Vec<String>,
pub(crate) vars: HashMap<String, String>,
pub(crate) id: u64,
pub(crate) stdin: TestStdinInner,
pub(crate) stdout: TestWriterInner,
pub(crate) stderr: TestWriterInner,
}

impl TestProcess {
Expand Down
2 changes: 1 addition & 1 deletion src/currentprocess/argsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl ArgSource for super::OSProcess {
}

/// Helper for ArgSource over `Vec<String>`
pub struct VecArgs<T> {
pub(crate) struct VecArgs<T> {
v: Vec<String>,
i: usize,
_marker: PhantomData<T>,
Expand Down
4 changes: 2 additions & 2 deletions src/currentprocess/filesource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl BufRead for TestStdinLock<'_> {
}
}

pub type TestStdinInner = Arc<Mutex<Cursor<String>>>;
pub(crate) type TestStdinInner = Arc<Mutex<Cursor<String>>>;

struct TestStdin(TestStdinInner);

Expand Down Expand Up @@ -165,7 +165,7 @@ impl Write for TestWriterLock<'_> {
}
}

pub type TestWriterInner = Arc<Mutex<Vec<u8>>>;
pub(crate) type TestWriterInner = Arc<Mutex<Vec<u8>>>;

struct TestWriter(TestWriterInner);

Expand Down
7 changes: 6 additions & 1 deletion tests/mock/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,12 @@ where
output
}

pub fn run_inprocess<I, A>(config: &Config, name: &str, args: I, env: &[(&str, &str)]) -> Output
pub(crate) fn run_inprocess<I, A>(
config: &Config,
name: &str,
args: I,
env: &[(&str, &str)],
) -> Output
where
I: IntoIterator<Item = A>,
A: AsRef<OsStr>,
Expand Down

0 comments on commit 8e632bb

Please sign in to comment.