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

Customizable timer start/end text #18

Closed
Purpzie opened this issue May 24, 2018 · 0 comments · May be fixed by #22
Closed

Customizable timer start/end text #18

Purpzie opened this issue May 24, 2018 · 0 comments · May be fixed by #22
Labels
feature request Request for a new feature

Comments

@Purpzie
Copy link

Purpzie commented May 24, 2018

Is your feature request related to a problem? Please describe.
As of right now, there is no way to change the text used when a timer is started or ended. It's hard-coded in.

Describe the solution you'd like
It would be awesome if we could specify custom text and colors for this instead! For example:

const log = new Signale({
  timers: {
    start: {
      // similar to types, just without a label
      badge: '👌',
      color: 'green',
      text: 'Custom timer started...'
    },
    end: {
      badge: '👍',
      color: 'red',
      text: ['Timer with custom text ran for:', 'and also has text here'],
      time: 'red' // color for time value
    }
  }
});

log.time('example');
setTimeout(() => { log.timeEnd('example') }, 1000);
// 👌 example     Custom timer started...
// 👍 example     Timer with custom text ran for: 1s and also has text here

We could also use options on specific timers.
signale.time(label, options)

log.time('another example', {
  start: { color: 'cyan', 'badge': '!' },
  end: { text: 'woah custom text and this timer ran for' }
});

setTimeout(() => { log.timeEnd('another example') }, 1000);
// ! another example     Custom timer started...
// 👍 another example     woah custom text and this timer ran for 1s

Additional context
The text option could either take a single string (putting the time after it), or an array of two strings (putting the time between them).

Also, to avoid having to type out a whole configuration, another option could possibly be to simply grab an existing one. To have a timer's start log behave as if it was logged with signale.star(), you could maybe do the following. This isn't a necessary function but it could be useful to some people.

signale.time('label', { start: { type: signale.star } }); // or perhaps just the string "star"

And if for whatever reason someone wanted the same configuration for both start and end without having two copies of it, these could be possible ways to implement that.

// put options in "both"
signale.time('label', { both: { color: 'red' } });

// OR just bring options outside
signale.time('label', { color: 'red' });

// however this works, start and end can still be specified to override things
signale.time('label', { color: 'red', start: { color: 'green' } });
// starts with green, ends with red

Of course, all of this would be optional in a configuration, since there's already a default for how timers should display.

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

Successfully merging a pull request may close this issue.

2 participants