JSPM

cli-meter

0.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 3
    • Score
      100M100P100Q14503F
    • License MIT

    Dynamic meter in your terminal

    Package Exports

    • cli-meter

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cli-meter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    cli-meter

    meter = require 'cli-meter'

    Creating a meter

    # 100 steps by default
    m = new Meter()
    
    # optional total steps
    m = new Meter(total: 500)
    
    # optional starting value
    m = new Meter(total: 500, value: 120)
    
    # optional display length in the terminal
    m = new Meter(total: 500, length: 30)

    You can then manipulate it with

    m.step(1)    # increment by 1
    m.step(-3)   # decrement by 3
    m.set(70)    # jump to 70

    And finally display it

    console.log "Processing #{m}"
    # Processing  [==============      ]
    
    console.log "#{m} #{m.value} dB"
    # [==============      ] 30 dB
    
    console.log "#{m} #{m.value} / #{m.total}"
    # [==============      ] 230 / 500

    Animations

    If you use console.log, the meter will be printed to a different line each time:

    # [============        ] 6 / 10
    # [================    ] 8 / 10

    If you have a TTY stream like process.stdout, you can show animations instead:

    setInterval (->
    
      process.stdout.write "Meter 1 #{m1}\n"
      process.stdout.write "Meter 2 #{m2}\n"
      process.stdout.write "Meter 3 #{m3}\n"
    
      process.stdout.moveCursor 0, -3
    
    ), 100

    example