npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-i3status

v0.1.5

Published

A library for creating status bars similar to i3status

Downloads

15

Readme

node-i3status

An i3status implementation in Node.js

const { Block, Status } = require('node-i3status');
/** An example block that shows the date every second */
class ExampleBlock extends Block {
  /** The constructor */
  constructor() {
    super('example');
    this.n = 0;
    // update the block every second
    setInterval(() => this.update(), 1000);
    this.on('mouse-LEFT', ev => {
      // can also use numbers, eg mouse-1
      this.n++;
      this.update();
    });
  }
  /**
   * The render function
   * @return {String}
   */
  render() {
    return {
      full_text: `${(new Date()).toString()} ${this.n}`,
      color: '#ffff00'
    };
  }
}

let status = new Status();

let b = new ExampleBlock();

// add the block to the status
status.addBlock(b);

// bind the status display to stdin/stdout
status.outStream.pipe(process.stdout);
process.stdin.pipe(status.inStream);

// remove it after 10 seconds
setTimeout(() => status.deleteBlock(b), 10000);

In ~/.config/i3/status:

bar {
    status_command /path/to/your/script.js
}

See examples folder for examples of more complex blocks.

API Reference

class: Status

Represents the status display. The Status object consists of many different Block objects.

update()

Sends the text of the current blocks to i3bar

renderBlock(block)

  • block <string> | <Block> The block to render

Render a single block

renderAll()

Render all the blocks

addBlock(block, index)

  • block <Block> The block to add
  • index <integer> Where to add the block

Add a block to the status display. If index is not specified, add the block to the end.

deleteBlock(block)

  • block <Block> The block to remove

Remove a block from the status display.

class: Block

Represents a part of the status display.

Constructor: new Block(name)

  • name <String> The name of the block

Create a new block. The name isn't currently used, besides to give to i3bar.

Event: 'input'

  • event <Object> A click event from i3

Emitted whenever there is input on the block, for example, if a user clicks it. See here for more information on the format which is used.

Event: 'mouse-<button>'

  • event <Object> A click event from i3

Emitted for a specific mouse event on the block. Both button names and button numbers can be used. See the input event for details and src/mouse-buttons.json for the names of the buttons.

update()

Tells the status display to update the block. Will call render() to get an updated display of the contents of the block.

render()

  • Returns: <string>

Update function. Will be called by the Status object to obtain the latest information provided by this block. See here for details about the format which should be used.

Does it suck?

Yes.