elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.33k stars 381 forks source link

[FEATURE] literal documentation #133

Closed n0vember closed 3 years ago

n0vember commented 3 years ago

Description of the requested feature

Documentation on the literal widget is pretty thin, I can't find any example of its use and the code is a bit too complex for me to dive in.

Proposed configuration syntax

I would like a working example of the literal widget.

Additional context

I have a script that outputs valid eww xml, I have it loaded in a var using script-var and I can't get it integrated, whatever twisted way I try: <literal content="{{ myVar }}"/> or <literal content="myVar" /> or even <literal>{{ myVar }}</literal>

undefinedDarkness commented 3 years ago

Could you show your scripts source & an example of its output

legendofmiracles commented 3 years ago

If the script outputs valid xml then you should be able to use it with:

<literal content="{{myVar}}"/>

Or here is my working example: This goes into the variables block:

<script-var name="list" interval="10s">
    egs.sh
</script-var>

This is the literal tag:

<literal content="{{list}}"/>

And at last my script:

#!/bin/env sh
#set -x
echo '<box>'
list=$(legendary list-installed --json | jq '.[].title' -r) # | xargs -n1 -p -d "\n" -I {} echo 'button onclick="'$(./app_name.sh {})'">'{}'</button>'
while IFS= read -r line; do
    echo '<button onclick="legendary launch '$(app_name.sh "$line")'">'$line'</button>'
done <<< "$list"
echo '</box>'

I also agree, examples would be great. But elkowar has talked about that being too much effort, to update them with every change that eww gets, in the past if I recall correctly.

n0vember commented 3 years ago

So here is my more precise exemple.

The shell script:

#!/usr/bin/env bash

df --exclude-type=tmpfs --exclude-type=devtmpfs --output=target,pcent,avail --human \
  | sed -r '1d;s/^([^ ]+) +([^ ]+) +([^ ]+)$/\1 \2 \3/' \
  | while read mountPoint usedPct freeSpace
do
  cat <<EOF
<box class="widget-no-border" orientation="h" halign="fill">
  <box class="small" halign="start">${mountPoint}</box>
  <box class="small" halign="center">${usedPct}</box>
  <box class="small" halign="end">${freeSpace}</box>
</box>
EOF
done

its output:

<box class="widget-no-border" orientation="h" halign="fill">
  <box class="small" halign="start">/</box>
  <box class="small" halign="center">64%</box>
  <box class="small" halign="end">174G</box>
</box>
<box class="widget-no-border" orientation="h" halign="fill">
  <box class="small" halign="start">/media/data</box>
  <box class="small" halign="center">46%</box>
  <box class="small" halign="end">1,5T</box>
</box>

the var inclusion:

<script-var name="diskAll" interval="1m">~/.config/eww/scripts/diskUsage</script-var>

the define inclusion:

<def name="diskAll">
  <literal content="{{ diskAll }}"/>
</def>

And all I get as output is empty space. No error in eww logs. If I replace the literal widget by the output of the script, I get exactly what I want.

This is very similar to the exemple provided above and I am really puzzled here.

n0vember commented 3 years ago

As additional context here, my goal is to replace the percentage display with a scale and have a dynamic list, whatever gets mounted.

undefinedDarkness commented 3 years ago

You need to wrap your entire script output in <box> or it won't work XML is pain Do that for any literal script you end up making So it outputs:

<box>
<box class="widget-no-border" orientation="h" halign="fill">
  <box class="small" halign="start">/</box>
  <box class="small" halign="center">64%</box>
  <box class="small" halign="end">174G</box>
</box>
<box class="widget-no-border" orientation="h" halign="fill">
  <box class="small" halign="start">/media/data</box>
  <box class="small" halign="center">46%</box>
  <box class="small" halign="end">1,5T</box>
</box>
</box>
legendofmiracles commented 3 years ago

Maybe also don't use spaces between the {{ and the variable name. Not sure if that is contributing to the issue tho.

n0vember commented 3 years ago

Thank you so much @undefinedDarkness ! The addition did the trick. Even on @legendofmiracles example script, I was focusing on the loop, not seeing those echo commands.

Also, space between curly brackets and variable name has no incidence. I just got this habit for templating to make variables more visible.