Skip to content

Commit 6b61682

Browse files
authored
Merge pull request #14 from alayshahh/stdERR
💄/ 🩹 :stderr prints red and stdout always prints
2 parents 6b2ff7a + 32c2b80 commit 6b61682

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ predicates = "1"
2424
walkdir = "2"
2525
log = "0.4.0"
2626
env_logger = "0.8.3"
27+
termcolor = "1.1.2"

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ lightmon rust
3131

3232
While there are not many languages supported currently, we plan to have an extensive list by our first official release.
3333

34+
### For unsupported languages or complicated builds
35+
`lightmon shell -s <path> -w <patterns>`
36+
37+
Here users can specify the path to the shell script and which file types to watch for seperated by commas.
38+
39+
For example, in a `python` project a user may want to watch `.py` and `.ipynb` files:
40+
41+
`lightmon shell -s run.sh -w .py,.ipynb`
42+
43+
Here `run.sh` would contain the shell command to execute the project.
3444
## License
3545
`lightmon` uses the [GNU GPL v3.0](https://github.com/reaganmcf/lightmon/blob/master/LICENSE) License
3646

src/cli.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ impl Cli {
9090
debug!("Configuring for shell mode...");
9191
debug!("Script Path = {:?}", sub_matcher.value_of("script"));
9292
debug!("Watch Pattern = {:?}", sub_matcher.value_of("watch"));
93-
if !Path::new(sub_matcher.value_of("script").unwrap()).exists() {
94-
error!("Given path to script does not exist!");
95-
std::process::exit(1);
96-
}
9793
let split = sub_matcher.value_of("watch").unwrap().split(',');
9894
for s in split {
9995
watch_patterns.push(format!("*{}", s.to_string()));

src/exec.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use std::io::{self, Write};
12
use std::process::{Command, Stdio};
23
use std::sync::Arc;
34
use std::thread;
5+
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
46

57
pub use crate::cli::Cli;
68
pub use crate::LightmonEvent;
@@ -17,10 +19,25 @@ pub fn start(cli_args: Arc<Cli>) -> std::thread::JoinHandle<()> {
1719
for argument in split.iter().skip(1) {
1820
cmd.arg(argument);
1921
}
20-
2122
debug!("final cmd = {:?}", cmd);
22-
let output = cmd.stdout(Stdio::inherit()).output().unwrap();
23-
debug!("{:?}", output);
23+
let output = cmd.output().unwrap();
24+
cmd.stdout(Stdio::inherit());
25+
cmd.stdout(Stdio::inherit());
26+
//write stdout to stdout
27+
io::stdout().write_all(&output.stdout).unwrap();
28+
if !output.stderr.is_empty() {
29+
//if stderr
30+
//change color to red
31+
let mut error = StandardStream::stderr(ColorChoice::Always);
32+
error
33+
.set_color(ColorSpec::new().set_fg(Some(Color::Red)))
34+
.unwrap();
35+
//write to stderr
36+
io::stderr().write_all(&output.stderr).unwrap();
37+
//reset terminal output color
38+
let color_reset = WriteColor::reset(&mut error).unwrap();
39+
debug!("reset color? {:?}", color_reset);
40+
}
2441
}
2542
})
2643
}

0 commit comments

Comments
 (0)