Repository: ultrabug/py3status

Issue:
mpd_status 'max_width' ineffective
- **Archlinux**
- **py3status version 3.15**
- **python-mpd2 version 1.0.0-2**
- **window manager 'sway-git' (same with i3)**

New to py3status, coming from i3blocks where I had a script to limit the output of characters to a set length.  Using mpd_status module in py3status, I see there is an option for max_width.  I have set this to 50, yet this has no effect on the artist/track name displayed.  Here is the mpd_status block I'm using...

```
mpd_status {
        name = ""
	format = "{name} [[[{artist} - ]{title}]|[{file}]]"
        on_click 1 = "exec mpc prev"
        on_click 2 = "exec mpc toggle"
        on_click 3 = "exec mpc next"
        color_play = "#ffffff"
        color_stop = "#ffffff"
        color_pause = "#676E7D"
	max_width = 50
}
```

- **What I expect to see**
Artist and song info printed in py3status that is longer than 50 chars, cut to 50 with "..." appended.

- **What I actually see**
Artist and song info is printed in full regardless of the max_width setting.
mpd_status 'max_width' ineffective
- **Archlinux**
- **py3status version 3.15**
- **python-mpd2 version 1.0.0-2**
- **window manager 'sway-git' (same with i3)**

New to py3status, coming from i3blocks where I had a script to limit the output of characters to a set length.  Using mpd_status module in py3status, I see there is an option for max_width.  I have set this to 50, yet this has no effect on the artist/track name displayed.  Here is the mpd_status block I'm using...

```
mpd_status {
        name = ""
	format = "{name} [[[{artist} - ]{title}]|[{file}]]"
        on_click 1 = "exec mpc prev"
        on_click 2 = "exec mpc toggle"
        on_click 3 = "exec mpc next"
        color_play = "#ffffff"
        color_stop = "#ffffff"
        color_pause = "#676E7D"
	max_width = 50
}
```

- **What I expect to see**
Artist and song info printed in py3status that is longer than 50 chars, cut to 50 with "..." appended.

- **What I actually see**
Artist and song info is printed in full regardless of the max_width setting.


Discussion:
As seen with you it comes from the fact that the `text` is a composite and we check the length of the composites instead of their output in here

```python
        if len(text) > self.max_width:
            text = u"{}...".format(text[:self.max_width])
```
As seen with you it comes from the fact that the `text` is a composite and we check the length of the composites instead of their output in here

```python
        if len(text) > self.max_width:
            text = u"{}...".format(text[:self.max_width])
```

Resolving patch:
diff --git a/py3status/modules/mpd_status.py b/py3status/modules/mpd_status.py
--- a/py3status/modules/mpd_status.py
+++ b/py3status/modules/mpd_status.py
@@ -66,6 +66,7 @@
 import datetime
 import re
 import socket
+from py3status.composite import Composite
 from mpd import MPDClient, CommandError, ConnectionError
 
 
@@ -182,6 +183,8 @@ def attr_getter(attr):
                     return song_attr(song, attr)
 
                 text = self.py3.safe_format(self.format, attr_getter=attr_getter)
+                if isinstance(text, Composite):
+                    text = text.text()
 
         except ValueError:
             # when status.get(...) returns None; e.g. during reversal of playlist


Test patch: