Giter VIP home page Giter VIP logo

mblocks's Introduction

This is my fork of the excellent mblocks software, by Mehdi Z., who managed to flawlessly implement the suckless philosophy in a Rust program. The code is self-documenting and can be extended and hacked on, even without extensive knowledge of Rust, because of the ease of use and intuitive nature of the code.

My changes merely involve what information is displayed in the statusbar, not how it functions.

Original README continues below:

mblocks

This program is a multi-threaded memory-safe status monitor written in Rust. It updates the status only when there is a change.

example

Installation

First, clone this repository.

git clone https://gitlab.com/mhdy/mblocks.git

Then, configure the status blocks by editing src/config.rs.

Next, build a release binary.

cargo build --release

If the build succeeds, the binary can be found in target/release/mblocks.

Finally, move the executable to one directory of your PATH directories, and add mblocks & to your ~/.xinitrc.

Configuration

The status monitor can be configured directly in the source src/config.rs. Examples of src/config.rs can be found here and here.

Status blocks are defined in the BLOCKS vector. Each block has a kind, executes a command, and has a prefix and a suffix for formatting.

There are 4 kinds of blocks:

  • Once: blocks labeled with this kind are executed once at the start of the program.
  • Periodic(N): blocks of this type are executed every N seconds.
  • Signal(S): these blocks are executed when the signal S is sent to the mblocks process. To send a signal, you can use kill -$((34 + S)) $(pidof mblocks) where S is the argument given to Signal, and it should not exceed 15 (1 <= S <= 15). This means that you can define at most 15 Signal blocks, which is large enough.
  • PeriodicOrSignal(N, S): the update of the block is made every N seconds or at the reception of the signal S.

The command attribute corresponds to the command to be executed and can be one of the following:

  • Shell(COMMAND): this executes the shell command given as arguments (e.g. Shell(&["date", "+%a, %b %d %Y"])). Note the & preceding the array of arguments!
  • Function(F): this executes the Rust function F given as argument. These latter can be placed in the directory src/blocks/. Check out the example functions.

The configuration file also defines the variable SEPARATOR that specifies the delimiter between blocks, and which could be any string. The generated status starts with the value of the variable PREFIX and ends with the value of the variable SUFFIX.

Misc.

  • If an empty string "" is returned by a block execution, then the corresponding block will not be displayed.
  • If the exit status of a Shell command is non-zero, then failed will be shown in the status (in the corresponding block).
  • If a Function command returns None, then failed will be shown in the status (in the corresponding block).
  • mblocks is memory-safe; it is validated with valgrind. The memory leaks shown by valgrind are false positives related to the signal-hook crate.

License

MIT.

mblocks's People

Contributors

raymon-roos avatar ydhm avatar

Watchers

 avatar

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.