# Network (https://mangowm.github.io/docs/bar/modules/network)

Shows the interface currently carrying traffic together with its link state
(connected / disconnected) and connection type (wifi / ethernet). Clicking
toggles between the normal format and live up/down speeds (KB/s below 1MB/s,
MB/s otherwise).

The active interface is the one holding the default route (lowest metric), so
when you unplug ethernet and the system fails over to wifi the module follows
automatically. The state is re-detected on every poll **and** immediately on
network `udev` events, so a cable unplug or wifi association shows up right
away.

```jsonc
"modules-right": ["network"],

"network": {
    "format": "{icon} {ifname}",
    "format-wifi": "{signal} {ssid}",
    "format-disconnected": "{icon}",
    "icon-wifi": "󰖩",
    "icon-ethernet": "󰈀",
    "icon-disconnected": "󰖪",
    "signal-icons": ["󰤯", "󰤟", "󰤢", "󰤥", "󰤨"],
    "format-alt": "↓{down} ↑{up}"
}
```

## Options [#options]

| Option                | Type         | Default               | Description                                                                            |
| --------------------- | ------------ | --------------------- | -------------------------------------------------------------------------------------- |
| `format`              | string       | `{icon} {ifname}`     | Normal format                                                                          |
| `format-alt`          | string       | —                     | Speed format; toggled by left click                                                    |
| `format-wifi`         | string       | —                     | Format used while connected over wifi (e.g. `{signal} {ssid}`); falls back to `format` |
| `format-ethernet`     | string       | —                     | Format used while connected over ethernet; falls back to `format`                      |
| `format-disconnected` | string       | `{icon}`              | Format used while no interface is connected; empty falls back to `format`              |
| `icon-wifi`           | string       | `󰖩`                   | Icon used for a wireless link                                                          |
| `icon-ethernet`       | string       | `󰈀`                   | Icon used for a wired link                                                             |
| `icon-disconnected`   | string       | `󰖪`                   | Icon used when nothing is connected                                                    |
| `signal-icons`        | string array | 5 built-in levels     | Wi‑Fi signal-strength icons, weakest → strongest (used by `{signal}`)                  |
| `interval`            | int (s)      | global `sys-interval` | Refresh interval override; larger values smooth the speed reading                      |

## Placeholders [#placeholders]

| Placeholder                       | Description                                                                      |
| --------------------------------- | -------------------------------------------------------------------------------- |
| `{}` / `{ifname}`                 | Active interface name (empty while disconnected)                                 |
| `{ipaddr}` / `{ip}`               | IPv4 address of the active interface (empty when unaddressed)                    |
| `{ssid}` / `{essid}`              | SSID of the associated wireless network (empty on wired links)                   |
| `{signal}`                        | Signal-strength icon picked from `signal-icons` (empty when unavailable)         |
| `{strength}` / `{signal-percent}` | Signal strength as a percentage (0–100)                                          |
| `{status}`                        | `connected` or `disconnected`                                                    |
| `{type}`                          | `wifi` or `ethernet` (empty while disconnected / unknown)                        |
| `{icon}`                          | Icon for the current state (`icon-wifi` / `icon-ethernet` / `icon-disconnected`) |
| `{down}`                          | Current download speed (alt format only)                                         |
| `{up}`                            | Current upload speed (alt format only)                                           |

Signal strength is read from the wireless-extensions interface and smoothed
over a few samples so the icon does not flap between adjacent levels (it is
empty on wired links). The mapping needs no configuration: it uses phone-style
Wi‑Fi bars, where −70 dBm or better is already full strength and −90 dBm is 0%,
so `{signal}` matches the bars a phone would show. `signal-icons` just supplies
the icon for each level and defaults to a built-in 5-step ladder, so it can be
left out entirely.

## Styling [#styling]

The module exposes link-state classes that can be combined. The cascade is
`#network` plus `#network.connected` / `#network.disconnected` and
`#network.wifi` / `#network.ethernet`, so a connected wifi link matches both
`#network.connected` and `#network.wifi`.

```css
#network {
  background: linear-gradient(to top, #b8bb26, mix(#b8bb26, #fbf1c7, 0.3));
  color: #1b1a1a;
}

#network.wifi {
  background-color: #83a598;
}

#network.ethernet {
  background-color: #b8bb26;
}

#network.disconnected {
  background-color: #fb4934;
}
```