Giter Club home page Giter Club logo

Comments (8)

iarna avatar iarna commented on June 4, 2024

@jokeyrhyme So this was kind of a pain with gauge@1, but with the just released gauge@2 it's pretty easy... it'd be something like

var themes = require('gauge/themes')
var Gauge = require('gauge')
// Add the ability to include eta to all existing and future themes
themes.addToAllThemes({
  eta: function (values, theme, width) {
    // compute the eta here, in the example we just hard code it
    // values.completed has the percent completion in it.
    return 'eta 3m30s'
  }
})
// add a new template that includes the eta
var etaTemplate = [
  {type: 'progressbar', length: 20},
  {type: 'eta', length: 9},
  {type: 'activityIndicator', kerning: 1, length: 1},
  {type: 'section', kerning: 1},
  {type: 'subsection', kerning: 1}
]
var gauge = new Gauge(process.stderr, {template: etaTemplate})

I would be all for adding an eta implementation to the base theme (adding it to the default template will require a little more tought, but I'm hesitantly for it).

from gauge.

jokeyrhyme avatar jokeyrhyme commented on June 4, 2024

@iarna thanks. I see if I can play with this soon. :)

from gauge.

iarna avatar iarna commented on June 4, 2024

@jokeyrhyme I updated the example to use the updated theme mixin support.

from gauge.

jokeyrhyme avatar jokeyrhyme commented on June 4, 2024

Nice GIF. :)

from gauge.

iarna avatar iarna commented on June 4, 2024

Thanks =)

I've fiddled a bit with adding ETA support and right now I'm seeing a lot more jitter in the estimates than I'd like, dejittering it requires some place for template functions to store state, which will require a bit of architectural fiddling, but it's on my mind.

from gauge.

jokeyrhyme avatar jokeyrhyme commented on June 4, 2024

Yeah, I've actually started wondering about a React renderer for the console. Not using blessed or ncurses, just something that renders (or re-renders) one line at a time for typical non-interactive console output. Then we could really treat everything on that line as a component, which might make things like progress bars and colours easier to manage. Hmmmm.....

from gauge.

iarna avatar iarna commented on June 4, 2024

My wip for this is over here:

https://github.com/iarna/gauge/tree/eta

from gauge.

iarna avatar iarna commented on June 4, 2024

It has render-template.js half way converted to a class as template.js. I'd like to finish that conversion before actually using that code.

It also has a pretty nice implementation of the eta template item in https://github.com/iarna/gauge/blob/eta/eta.js

The jitter was easy enough to cleanup by just not updating the eta every tick (I, arbitrarily, chose once a second, and that feels a lot better).

themes.addToAllThemes({
  'eta': function (values, theme, width) {
    var eta = getEta(this)
    var now = process.hrtime()
    var sinceLast = elapsed(now, eta.last)
    if (sinceLast >= 1 || !eta.remaining || eta.remaining < 1) {
      var tillNow = elapsed(eta.last, eta.created)
      var remaining = (tillNow / values.completed) - tillNow
      eta.last = now
      eta.remaining = remaining
    }
    return formatNumber(eta.remaining)
  },
  'elapsed': function (values, theme, width) {
    var eta = getEta(this)
    return formatNumber(elapsed(process.hrtime(), eta.created))
  }
})

Originally I was using process.uptime() and I'd probably go back to that, which means we can ditch the elapsed function.

from gauge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.