cctv 0.2.0

Terminal interface for CoolerControl
<div align="center">
  <h1>
  <img alt="cctv_logo" src="https://gitlab.com/caferen/cctv/-/raw/master/assets/cctv.png" width="200">
  <br>
  cctv
  <br>
  </h1>

An experimental terminal client for [CoolerControl](https://gitlab.com/coolercontrol/coolercontrol).

![](assets/demo.webm)
:warning: Requires the CoolerControl service daemon to be running either locally or remotely, [see Configuration](#configuration).

</div>

[[_TOC_]]

## Building

Clone the git repo and build with cargo. Requires a working [Rust installation](https://www.rust-lang.org/tools/install).

```bash
git clone https://gitlab.com/caferen/cctv.git
cd cctv
cargo build --release
cargo run --release
```

## Installing/Upgrading

There are no packages for distributions yet but you can download and install the
latest binary artifact built from master or build from source yourself.

### Latest release

```bash
curl -LOJ --clobber --output-dir "/tmp" \
    https://gitlab.com/api/v4/projects/68712421/packages/generic/master/latest/cctv
sudo install -Dm 755 /tmp/cctv -t /usr/bin
```

### From source

Install with cargo. Requires a working [Rust installation](https://www.rust-lang.org/tools/install).

```bash
cargo install --git https://gitlab.com/caferen/cctv.git
```

### From crates.io

`cctv` is also published to crates.io. Note that the version there may be slightly outdated.

```bash
cargo install cctv
```

Make sure `$HOME/.cargo/bin` is in your path:

```bash
# Bash users
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

# zsh users
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
```

## Usage

### CLI

While primarily a TUI application, `cctv` also has a command line interface for some common operations.

```None
Usage: cctv [OPTIONS]
TUI client for CoolerControl

Options:
  --list-modes, -l                              Lists all available modes.
  --activate-mode <mode-name>, -a <mode-name>   Activates the specified mode.
  --delay-by <seconds>                          When used in conjunction with --activate-mode, sets
                                                the delay in seconds before the mode switch.
  --help, -h                                    Shows this help message.

If no options are passed, the application will launch into the TUI.
```

### TUI

Keybindings:

```
Down, e, j: Select next item
Up, i, k: Select previous item
Right, o, l: Go to the next page
Left, n, h: Go to the previous page
R: Refresh app data
s: Toggle legend visibility on charts.
Ctrl+q: Quit
```

#### Devices Page

Additional keybindings:

```
a: Toggle between the default and the alternative chart.
```

#### Modes Page

Additional keybindings:

```
Enter: Activate the currently highlighted mode.
```

#### Profiles Page

##### Editing profiles

Profile editing is a work-in-progress. There's experimental support for
manipulating graph profiles.

:warning: take a backup of your config before editing - there may be breakages.

There are two input modes: edit and normal. Normal mode is the default.

When you enter edit mode you will see a popup populated with the current
settings. You can edit this popup and submit the changes first to cctv which
will update the internal state without making a submission to the daemon.

The popup will look like this:

`[[20.0,20.0],[65.0,30.0],[85.0,100.0],[100.0,100.0]]`

Each of these entries represent a point on the graph. First value being the
temperature and the second being the duty. You can make any change you want,
however, the result must be a list of list of numbers. If you make any mistakes,
you will be notified when you attemp to save.

:warning: even though duties look like floating point numbers, they are
actually integers. Floating point numbers will be truncated to integers.

Adding or removing entries is also supported.

After you save, the graph will show your edits but they won't be applied yet.
You can make further edits or reset your changes by refreshing the app data (`R`).

When you're happy, submit the current state to CoolerControl. To avoid
accidental submissions, it is not possible to submit without quitting edit
mode.

You will be notified of any errors. Lack of a notification indicates success.

:warning: note that the official GUI will not update automatically. You will
need to refresh the page to see the changes there. The reverse is also true.

Additional keybindings when in normal mode:

```
E: Enter edit mode.
D: Discard working changes. Locally applied changes do not count as working.
A: Apply the changes to the daemon.
```

Additional keybindings when in edit mode:

Following characters can be inserted: digits, space, '.', ',', '[', ']'

```
Esc: Exit edit mode. Note that your working changes are saved during the session.
Enter: Save working changes without applying them to the daemon.
D: Discard working changes.
Right: move cursor to the right.
Left: move cursor to the left.
Backspace: delete one character.
```

## Configuration

Configuration is optional. `cctv` will attempt to construct configurations from
below locations, in order of precedence:

- Environment variables listed [below]#environment-variables.
- `coolercontrold` configuration file
- CoolerControl defaults

This means that if you're overriding CoolerControl's defaults, `cctv` will
automatically pick _some of_ them up. But you can still override them specifically for
`cctv` with the environment variables e.g. to have `cctv` connect to a remote
CoolerControl instance instead of your local daemon.

Note that there's currently no SSL or IPv6 support.

### Environment variables

- `CCTV_DAEMON_PORT` - The port CoolerControl is listening on. CoolerControl default: 11987
- `CCTV_DAEMON_ADDRESS` - The address CoolerControl is listening on. CoolerControl default: 127.0.0.1
- `CCTV_DAEMON_CONFIG_FILE_PATH` - The path to CoolerControl's config file. CoolerControl default: /etc/coolercontrol/config.toml
- `CCTV_TIME_RANGE` - Time range in seconds to look back to for device charts. cctv default: 60
- `CCTV_USERNAME` - CoolerControl username if you've set one. Otherwise the internal default is used.
- `CCTV_PASSWORD` - CoolerControl password if you've set one. Otherwise the internal default is used.
- `CCTV_NO_SPLASH` - Skips the splash screen when set to true. cctv default: false