Skip to content

Commit

Permalink
Bump version to 1.6 beta, document format syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-kast committed Mar 12, 2022
1 parent 4d85a02 commit da92032
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "empress"
version = "1.5.0"
version = "1.6.0-beta.1"
authors = ["rookie1024 <rookie1286@gmail.com>"]
edition = "2021"
description = "A D-Bus MPRIS daemon for controlling media players."
Expand Down
60 changes: 60 additions & 0 deletions etc/now_playing_long.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Print information about the current track.

FORMAT STRING SYNTAX

Format strings take the form of a string of literal text to be printed combined with expressions inside {{...}} blocks. For example, the format string "The title is {{ title }}" will print "The title is Foo" for a track named Foo.

EXPRESSION REFERENCE

Basic expressions are supported, such as numbers, 'single-quoted strings,' and "double-quoted strings".

Any of the JSON values normally output can be accessed using C-like object access syntax. For example, {{ title }} gets the track title and {{ player.id }} gets the media player name. See below for a list of available values.

Arrays of values can be constructed using a comma-separated list in square brackets (e.g. {{ [1, 2, 3] }} creates a three-element array).

Function calls take the form {{ ident(arg1, arg2, ...) }}. See below for a list of available functions.

Any expression can be wrapped in parentheses for clarity - {{ (12) }} is equivalent to {{ 12 }}, etc.

Values in an array or an object can be accessed using the index operator. For example {{ artist[0] }} retrieves the first artist and {{ player["id"] }} retrieves the player name. Indexing into a value with an invalid index will throw an error.

Expressions can be piped through functions using the | (pipe) operator. When calling a pipe function with no arguments, parentheses are optional, so {{ "hi" | lower() }} is equivalent to {{ "hi" | lower }}. You can chain as many functions together using pipes as you like.

To provide a fallback value in case an expression is blank the ?? (null-coalescing) operator can be used. For instance, to handle players that can return null for the album field, one might use {{ album ?? "Unknown album" }}.

VALUE REFERENCE

To see the values available to format strings, simply run the now-playing command without any format string and the raw JSON will be printed. Currently, the values provided are:

{
"status": string, // one of 'Playing', 'Paused', or 'Stopped'
"player": {
"bus": string,
"id": string,
},
"title": string?,
"artist": string[]?,
"album": string?,
}

FUNCTION REFERENCE

compact(): When an array is piped in, returns a new array with all the blank elements removed

join(sep): When an array is piped in, returns a string containing each element separated by `sep`

json(): When any value is piped in, returns a JSON string representing that value

lower(): When any printable value is piped in, returns its printed form converted to lowercase

shorten(len, val): When any printable value is piped in, returns a string no more than `len` characters long. If the string has been shortened it will end with `val`.

shortenMid(len, val): When any printable value is piped in, returns a string no more than `len` characters long. If the string has been shortened its middle will be replaced with `val`.

sym(): Converts several special strings to Unicode symbols. Currently if the {{ status }} field is piped into this function it will be converted to the appropriate play/pause/stop symbol.

trim(): When any printable value is piped in, returns its printed form with all whitespace trimmed off both ends of the resulting string.

upper(): When any printable value is piped in, returns its printed form converted to uppercase

xml(): When any printable value is piped in, returns its printed form with all illegal XML characters replaced with their appropriate XML entity forms. This is useful for applications where the output string must be valid Pango markup.
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,13 @@ enum ClientCommand {
/// Skip one track forwards
Next(PlayerOpts),
/// Print information about the current track
#[clap(long_about = include_str!("../etc/now_playing_long.txt"))]
NowPlaying {
#[clap(flatten)]
player: PlayerOpts,

/// Instead of outputting JSON, output a plaintext string with the given
/// format.
///
/// TODO: document format
/// format. See the full help for this command for a syntax reference.
#[clap(short, long)]
format: Option<String>,
},
Expand Down

0 comments on commit da92032

Please sign in to comment.