Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change the color of the input beyond certain length? #359

Closed
sarbbottam opened this issue Apr 15, 2016 · 11 comments · Fixed by #642
Closed

Is it possible to change the color of the input beyond certain length? #359

sarbbottam opened this issue Apr 15, 2016 · 11 comments · Fixed by #642

Comments

@sarbbottam
Copy link

Is it possible to change the color of the input beyond certain length?

Somthing like
screen shot 2016-04-04 at 11 57 11 am

git-cz


May be something like:

...
}, {
    type: 'input',
    name: 'subject',
-    message: 'Write a short, imperative tense description of the change:\n'
+    message: 'Write a short, imperative tense description of the change:\n',
+    transformer: function(line) {
+        return line.substring(0, 99) + chalk.red(line.substring(100))
+   }
}, {
....

and

Inquirer.js/lib/prompts/input.js#L55-L70 can invoke this transformer function

Prompt.prototype.render = function (error) {
  var bottomContent = '';
  var message = this.getQuestion();

  if (this.status === 'answered') {
    message += chalk.cyan(this.answer);
  } else {
-   message += this.rl.line;
+   message += reference.to.the.transformer(this.rl.line);
  }

  if (error) {
    bottomContent = chalk.red('>> ') + error;
  }

  this.screen.render(message, bottomContent);
};

Thanks!

@sarbbottam
Copy link
Author

Hi @SBoudrias, does this sound feasible? If yes, I can work on a PR, with little guidance.

@SBoudrias
Copy link
Owner

Everything is possible, the question is more what would be the API exposed to the user?

@sarbbottam
Copy link
Author

I guess the API remains the same, if optional transformer function is passed, this.rl.line is transformed before it gets added to the message.

May be I am over-simplifying, you could suggest better.

@SBoudrias
Copy link
Owner

I think that makes sense. PR welcomed

@pudgereyem
Copy link

@sarbbottam, @SBoudrias, any progress on this?

If not, I might look into it.

@travi
Copy link
Contributor

travi commented Dec 13, 2017

@pudgereyem i've been meaning to make a contribution around this for a while, but have never found time to start looking into it. it would be hugely helpful to me if you end up getting it working. if any help testing it out would be helpful, i may be able to find some time for that.

@travi
Copy link
Contributor

travi commented Jan 19, 2018

@SBoudrias i know this is a pretty dated issue at this point, but i tried to take a stab as this a couple of nights ago and had some trouble figuring out how the tests are intended to run.

https://github.com/SBoudrias/Inquirer.js/blob/master/test/specs/prompts/input.js looks like an appropriate place to try to test drive this behavior, but the changes that i've made there don't appear to be executed when i run npm test. am i missing something obvious, or is this file somehow excluded from the tests that are intended to run? are there any tricks or tips you could share about how to test a new feature like this?

@SBoudrias
Copy link
Owner

@travi no magic around tests, the npm test command should have this file tests running... Any chance there's an error when parsing/importing the file and that somehow makes the runner skip the whole file?

@travi
Copy link
Contributor

travi commented Jan 20, 2018

no magic around tests, the npm test command should have this file tests running

i didnt think it looked like anything more than a simple config for the tests. however, even with my changes stashed, any console.logs that i add to the beforeEach or test blocks (it) dont show up in the mocha output when running npm test. if it's helpful, mocha reports 93 passing. does that number align with what you would expect if that file is being included?

i saw the engines defininition of using node 6:

"engines": {
    "node": ">=6.0.0"
  },

so after switching with nvm to v6 with nvm use 6, i end up on v6.9.1. thats the context i'm running npm test in

@SBoudrias
Copy link
Owner

@travi just checked it out myself, and you're right some tests weren't running. I think a version update changed how mocha treated the glob pattern and drop all test in nested folders (but kept travis green, so it went unnoticed.)

It's fixed on latest master.

@travi
Copy link
Contributor

travi commented Jan 21, 2018

Glad to hear I'm not crazy at least. Thanks for taking a look and getting it taken care of.

Hopefully that clears the way to getting this feature knocked out. With any luck I'll get a PR to you within the week so we can finalize implementation details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants