summaryrefslogtreecommitdiffstats
path: root/src/print.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.dev>2020-01-26 17:37:18 -0500
committerKevin Song <chipbuster@users.noreply.github.com>2020-01-26 16:37:18 -0600
commit3365beae09af2f12b6323a52f88633ed97b39c51 (patch)
treefb36ec6c06439edd29775fc4a7b1a06041619b69 /src/print.rs
parent5342dcc658110f8884a77ef1b3f83e867322ffb5 (diff)
test(nodejs): Port nodejs module tests from E2E to integraton (#867)
Replaces the existing nodejs module end-to-end tests with integration tests that don't require preinstalled environmental dependencies. - Moved the tests to the same file as the module they test - Created a render_module utility function for rendering modules within tests - Removed Node.js installation during CI setup - Add Shell to Context to allow for tests to not run shell-specific code
Diffstat (limited to 'src/print.rs')
-rw-r--r--src/print.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/print.rs b/src/print.rs
index ee3b36662..46d44d223 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -1,3 +1,4 @@
+use ansi_term::ANSIStrings;
use clap::ArgMatches;
use rayon::prelude::*;
use std::fmt::Write as FmtWrite;
@@ -35,10 +36,11 @@ pub fn get_prompt(context: Context) -> String {
for module in printable {
// Skip printing the prefix of a module after the line_break
if print_without_prefix {
- let module_without_prefix = module.to_string_without_prefix();
+ let module_without_prefix = module.to_string_without_prefix(context.shell.clone());
write!(buf, "{}", module_without_prefix).unwrap()
} else {
- write!(buf, "{}", module).unwrap();
+ let module = module.ansi_strings_for_shell(context.shell.clone());
+ write!(buf, "{}", ANSIStrings(&module)).unwrap();
}
print_without_prefix = module.get_name() == "line_break"
@@ -49,15 +51,14 @@ pub fn get_prompt(context: Context) -> String {
pub fn module(module_name: &str, args: ArgMatches) {
let context = Context::new(args);
-
- // If the module returns `None`, print an empty string
- let module = modules::handle(module_name, &context)
- .map(|m| m.to_string())
- .unwrap_or_default();
-
+ let module = get_module(module_name, context).unwrap_or_default();
print!("{}", module);
}
+pub fn get_module(module_name: &str, context: Context) -> Option<String> {
+ modules::handle(module_name, &context).map(|m| m.to_string())
+}
+
pub fn explain(args: ArgMatches) {
let context = Context::new(args);
@@ -73,7 +74,7 @@ pub fn explain(args: ArgMatches) {
.into_iter()
.filter(|module| !dont_print.contains(&module.get_name().as_str()))
.map(|module| {
- let ansi_strings = module.ansi_strings_for_prompt(false);
+ let ansi_strings = module.ansi_strings();
let value = module.get_segments().join("");
ModuleInfo {
value: ansi_term::ANSIStrings(&ansi_strings[1..ansi_strings.len() - 1]).to_string(),