Skip to content

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

Open
@sarbbottam

Description

@sarbbottam
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!

Activity

jimthedev

jimthedev commented on Apr 4, 2016

@jimthedev
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

sarbbottam commented on Apr 4, 2016

@sarbbottam
ContributorAuthor

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

jimthedev

jimthedev commented on Apr 4, 2016

@jimthedev
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

sarbbottam commented on Apr 4, 2016

@sarbbottam
ContributorAuthor

@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

jimthedev commented on Apr 4, 2016

@jimthedev
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 <
notifications@github.com> 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

sarbbottam commented on Apr 4, 2016

@sarbbottam
ContributorAuthor

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

jimthedev commented on Aug 14, 2016

@jimthedev
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

travi commented on Mar 13, 2017

@travi
Contributor

@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

sarbbottam commented on Mar 14, 2017

@sarbbottam
ContributorAuthor

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

travi

travi commented on Mar 14, 2017

@travi
Contributor

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

travi commented on May 24, 2018

@travi
Contributor

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

jimthedev commented on May 24, 2018

@jimthedev
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jimthedev@travi@sarbbottam

        Issue actions

          Is it possible to change the color of the input beyond certain length? · Issue #178 · commitizen/cz-cli