Skip to content

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

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

Open
sarbbottam opened this issue Apr 4, 2016 · 12 comments
Open

Comments

@sarbbottam
Copy link
Contributor

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

Thanks!

@jimthedev
Copy link
Member

Hi @sarbbottam,

I like this idea. Unfortunately it might be difficult to accomplish. We'd likely need to find a way to use the node-color-readline package with Inquirer.js. If we could find that out, then it might be possible. Even then, we'd need the individual commitizen adapters to adopt this feature.

Thanks!

@sarbbottam
Copy link
Contributor Author

Thanks @jimthedev, wondering if this should be implemented at Inquirer.js, since Inquirer.js owns/handles the prompt.

@jimthedev
Copy link
Member

@sarbbottam Technically we just pass the adapter an instance of Inquirer, so you can ignore that instance and use something completely separate for prompts. If that thing you uses works with node-color-readline then everything should work. Currently most adapters take advantage of Inquirer because it is so simple to implement and covers a high percentage of use cases. I am open to having these changes in the cz-conventional-changelog if you'd like to put in a PR.

@sarbbottam
Copy link
Contributor Author

@jimthedev let me take a look, will be more than happy to raise a PR, I might need a little guidance.

I guess I should have raised the issue in cz-conventional-changelog.

@jimthedev
Copy link
Member

Sure thing. I'm happy to answer any questions, review code, or point you in
the right direction.
On Mon, Apr 4, 2016 at 4:06 PM Sarbbottam Bandyopadhyay <
[email protected]> wrote:

@jimthedev https://github.com/jimthedev let me take a look, will be
more than happy to raise a PR, I might need a little guidance.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#178 (comment)

@sarbbottam
Copy link
Contributor Author

Hi @jimthedev,

I am open to having these changes in the cz-conventional-changelog if you'd like to put in a PR.

I guess cz-conventional-changelog/index.js#L67-L71 can pass a transformer function to Inquirer.js

...
}, {
    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);
};

Let me know your thoughts.

@jimthedev
Copy link
Member

@sarbbottam Seems like a good idea. I'm open to it. If you can get a PR landed in Inquirer then I'd be open to this.

@travi
Copy link
Contributor

travi commented Mar 13, 2017

@sarbbottam are you still planning to put a PR together for SBoudrias/Inquirer.js#359 to enable this?

I think it would be a very valuable enhancement to cz-cli to change the color after 50 characters for a "recommended" length and to change it again or prevent typing at the point the short description would be truncated.

My team has been surprised many times where their messages are truncated when reading through previous logs since there is currently no feedback when constructing the commit.

@sarbbottam
Copy link
Contributor Author

@travi I have been busy, feel free to take it up.

@travi
Copy link
Contributor

travi commented Mar 14, 2017

thanks for the update. i'm not sure when i will get a chance to do it, but i will keep it in mind. please feel free if you get a chance before me.

@travi
Copy link
Contributor

travi commented May 24, 2018

it looks like i never updated this thread with progress that i was able to make. i was able to get the change discussed above accepted into inquirer in SBoudrias/Inquirer.js#359 (pr was SBoudrias/Inquirer.js#642), but i havent found time to leverage that ability to make the contribution back to commitizen to finish this up.

if someone happens to want to pick that up before i can get to it, the documentation to use the formatter/transformer can be found here (under transformer).

@jimthedev
Copy link
Member

Thanks for the update and the work to get that into Inquirer @travi! Seems like it would be a good one for someone to pick up. I will leave this open as a todo.

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

No branches or pull requests

3 participants