GithubHelp home page GithubHelp logo

bar-config's Introduction

Bar Config

Crate for easily creating system bars/panels/docks.

The goal of this crate is to make it as simple as possible to create complex bars/panels/docks for linux without having to worry about anything but rendering.

To get started with the crate, a new bar needs to be created. This is done using the load method in the Bar.

Examples

This example shows you how to create a simple bar with three components which prints the state of every component in the console every time it's updated.

use std::io::Cursor;

use bar_config::Bar;

fn main() {
    // Create input configuration input with three components
    let input = Cursor::new(String::from(
        "\
         height: 30\n\
         monitors:\n\
         - { name: \"DVI-1\" }\n\
         left:\n\
         - { text: \"Hello, World!\" }\n\
         center:\n\
         - { name: \"clock\" }\n\
         right:\n\
         - { text: \"VOLUME\" }",
    ));

    // Load the bar configuration from the input
    let mut bar = Bar::load(input).unwrap();

    // Render the state of the bar at startup
    print_bar(&bar);

    loop {
        // Wait for any update to the bar
        let _ = bar.recv();

        // Print all components every time one changes
        print_bar(&bar);
    }
}

// Prints the text of every component in the configuration
fn print_bar(bar: &Bar) {
    for comp in bar.components() {
        if let Some(text) = comp.text() {
            print!("{}\t", text);
        }
    }
    println!("");
}

Bar Configuration Grammar

This is the grammar for the user configuration. It is designed to map to data formats like YAML or JSON but should also allow an easy representation in Rust.

# Legend
#     !   Field is required
#     ?   Field is optional

# Root element of the bar
Bar
    # General configuration options
    !height: u8
    ?position: Position
    ?background: Background
    ?border: Border
    !monitors: [Monitor]

    # Default fallback values for components
    ?defaults: ComponentSettings

    # Component containers
    ?left: [Component]
    ?center: [Component]
    ?right: [Component]

# A single component/block/module in the bar
Component
    # Name used to identify which component should be loaded
    ?name: String

    # State of a component (inlined struct).
    ?ComponentSettings

    # Extra options are passed to the component
    ?_: T

# Default options available for every component

# Full component state which contains everything necessary for rendering a component.
ComponentSettings
    ?foreground: (r: u8, g: u8, b: u8, a: u8)
    ?background: Background
    ?width: u8
    ?padding: u8
    ?offset_x: i8
    ?offset_y: i8
    ?fonts: [Font]

# Background of a component or the bar
Background
    !Image(path: String) | Color(r: u8, g: u8, b: u8, a: u8)

# Dinstinct identification for a font
Font
    !name: String
    !size: u8

# Distinct identification for a monitor
Monitor
    !name: String
    ?fallback_names: [String]

# Border separating the bar from the rest of the WM
Border
    !height: u8
    !color: (r: u8, g: u8, b: u8, a: u8)

# Available positions for the bar
Position
    !Top | Bottom

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.