Compare commits

...

15 commits
v0.1.0 ... main

Author SHA1 Message Date
SW
76824346b8 chore: update formula to v0.1.4, build from Forgejo source archive 2026-09-14 16:50:54 +02:00
SW
7e7cf1cf65 ci: remove corrupted .deb files before dpkg-scanpackages
All checks were successful
Release / release (push) Successful in 33s
2026-09-10 15:43:19 +02:00
SW
55e4539bf7 ci: build .deb manually with dpkg-deb instead of cargo-deb
Some checks failed
Release / release (push) Failing after 33s
2026-09-10 15:38:09 +02:00
SW
d5eaea9600 ci: use cargo deb without --no-build, add .deb debug output
Some checks failed
Release / release (push) Failing after 1m11s
2026-09-10 15:29:16 +02:00
SW
0a89020ce1 ci: drop macOS build and Homebrew tap, keep Linux + .deb + APT only
Some checks failed
Release / release (push) Failing after 1m11s
2026-09-10 15:23:11 +02:00
SW
e831dd1eb1 ci: make macOS build optional, skip Homebrew tap if it fails
Some checks failed
Release / release (push) Has been cancelled
2026-09-10 15:14:57 +02:00
SW
e0394a0a0f ci: install zig into /usr/local/bin with symlink
Some checks failed
Release / release (push) Failing after 2m48s
2026-09-10 15:01:07 +02:00
SW
1f42ba75f2 ci: download zig binary directly instead of apt
Some checks failed
Release / release (push) Has been cancelled
2026-09-10 14:58:45 +02:00
SW
45ad565459 ci: install zig for cargo-zigbuild macOS cross-compile
Some checks failed
Release / release (push) Failing after 2s
2026-09-10 14:55:59 +02:00
SW
b4afe150e8 ci: fix SSH deploy key mount path for Forgejo runner
Some checks are pending
Release / release (push) Waiting to run
2026-09-10 14:51:49 +02:00
SW
8bbe2fbde8 ci: switch release workflow to Forgejo, update repo URLs
Some checks failed
Release / release (push) Failing after 45s
- Add Forgejo release workflow with .deb, Homebrew tap and APT updates.
- Remove obsolete GitHub Actions release workflow.
- Update Cargo.toml repository and homepage URLs to git.janvete.com.
2026-09-10 14:37:49 +02:00
SW
5253514d4c docs: update install instructions for Forgejo 2026-09-10 14:22:15 +02:00
SW
6f8392824d Remove slow restic stats call, add snapshot details to repo panel 2026-08-28 22:07:45 +02:00
SW
48eb2e562d Fix release asset name collision, document Linux installation 2026-08-16 19:47:08 +02:00
SW
192eb06c9d Add Homebrew formula 2026-08-16 19:31:54 +02:00
9 changed files with 283 additions and 192 deletions

View file

@ -0,0 +1,165 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
container:
image: rust:bookworm
volumes:
- /opt/runner/keys:/keys:ro
steps:
- name: Install tools
run: |
apt-get update
apt-get install -y dpkg-dev git curl openssh-client
- name: Setup SSH
run: |
test -r /keys/forgejo_runner || { echo "Deploy key /keys/forgejo_runner chybi"; exit 1; }
install -m 600 /keys/forgejo_runner /tmp/forgejo_runner
echo "GIT_SSH_COMMAND=ssh -p 554 -i /tmp/forgejo_runner -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR" >> "$GITHUB_ENV"
- name: Checkout source
run: |
git clone ssh://git@git-ssh.janvete.com:554/seth/resticview.git src
cd src
git checkout "${{ github.ref_name }}"
- name: Build Linux release binary and .deb
working-directory: src
run: |
VERSION=${{ github.ref_name }}
VER=${VERSION#v}
mkdir -p dist
cargo build --release
# .deb package
DEB_DIR="resticview_${VER}_amd64"
mkdir -p "${DEB_DIR}/DEBIAN" "${DEB_DIR}/usr/bin"
cp target/release/resticview "${DEB_DIR}/usr/bin/resticview"
chmod 755 "${DEB_DIR}/usr/bin/resticview"
cat > "${DEB_DIR}/DEBIAN/control" << CONTROL
Package: resticview
Version: ${VER}
Section: utils
Priority: optional
Architecture: amd64
Maintainer: janvete <jan.vete@example.com>
Description: TUI browser for restic backup repositories
CONTROL
dpkg-deb --build "${DEB_DIR}" "dist/${DEB_DIR}.deb"
# Linux tarball
STAGING=$(mktemp -d)
cp target/release/resticview "${STAGING}/resticview"
tar -czf "dist/resticview-${VERSION}-linux-amd64.tar.gz" -C "${STAGING}" resticview
rm -rf "${STAGING}"
- name: Print checksums
working-directory: src
run: |
echo "=== SHA256 checksums ==="
sha256sum dist/*
- name: Create Forgejo Release
working-directory: src
env:
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
FORGEJO_URL: https://git.janvete.com
run: |
VERSION=${{ github.ref_name }}
API="${FORGEJO_URL}/api/v1/repos/seth/resticview"
RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
-H "Content-Type: application/json" \
-X POST \
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \
"${API}/releases")
echo "Create release response: ${RELEASE_JSON}"
RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
if [ -z "${RELEASE_ID}" ]; then
echo "Release may already exist, fetching existing release..."
EXISTING=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
"${API}/releases/tags/${VERSION}")
echo "Existing release response: ${EXISTING}"
RELEASE_ID=$(echo "${EXISTING}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
fi
if [ -z "${RELEASE_ID}" ]; then
echo "Failed to create or fetch release"
exit 1
fi
for ARCHIVE in dist/*; do
[ -e "${ARCHIVE}" ] || continue
NAME=$(basename "${ARCHIVE}")
case "${NAME}" in
*.tar.gz) CONTENT_TYPE="application/gzip" ;;
*.deb) CONTENT_TYPE="application/vnd.debian.binary-package" ;;
*) CONTENT_TYPE="application/octet-stream" ;;
esac
curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
-H "Content-Type: ${CONTENT_TYPE}" \
--data-binary "@${ARCHIVE}" \
"${API}/releases/${RELEASE_ID}/assets?name=${NAME}"
echo "Uploaded ${NAME}"
done
- name: Update APT repository
working-directory: src
run: |
VERSION=${{ github.ref_name }}
git clone ssh://git@git-ssh.janvete.com:554/seth/apt.git apt-repo
cp dist/*.deb apt-repo/
cd apt-repo
# Remove any corrupted .deb files left from previous failed runs
for f in *.deb; do
[ -e "$f" ] || continue
if ! dpkg-deb -I "$f" >/dev/null 2>&1; then
echo "Removing corrupted package: $f"
rm -f "$f"
fi
done
dpkg-scanpackages . > Packages
gzip -k -f Packages
cat > Release << RELEASE
Origin: janvete
Label: janvete
Suite: stable
Codename: stable
Version: 1.0
Architectures: amd64
Components: main
Description: janvete tools APT repository
Date: $(date -Ru)
RELEASE
{
echo "SHA256:"
for f in Packages Packages.gz *.deb; do
[ -e "$f" ] || continue
printf " %s %16d %s\n" "$(sha256sum "$f" | cut -d' ' -f1)" "$(stat -c%s "$f")" "$f"
done
} >> Release
git config user.email "forgejo-actions[bot]@janvete.com"
git config user.name "forgejo-actions[bot]"
git add -A
git commit -m "chore: add resticview ${VERSION}"
git push

View file

@ -1,68 +0,0 @@
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g. v0.1.6)'
required: true
permissions:
contents: write
jobs:
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --release
- run: cargo test --release
- run: cargo clippy --release -- -D warnings
- uses: actions/upload-artifact@v4
with:
name: resticview-macos
path: target/release/resticview
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo install cargo-deb
- run: cargo build --release
- run: cargo test --release
- run: cargo clippy --release -- -D warnings
- run: cargo deb
- uses: actions/upload-artifact@v4
with:
name: resticview-linux
path: |
target/release/resticview
target/debian/*.deb
release:
needs: [build-macos, build-linux]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: resticview-macos
path: artifacts/macos
- uses: actions/download-artifact@v4
with:
name: resticview-linux
path: artifacts/linux
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
files: |
artifacts/macos/resticview
artifacts/linux/release/resticview
artifacts/linux/debian/*.deb
generate_release_notes: true
overwrite_files: true

View file

@ -5,8 +5,8 @@ edition = "2024"
authors = ["janvete"]
description = "TUI browser for restic backup repositories"
license = "MIT"
repository = "https://github.com/janvete/resticview"
homepage = "https://github.com/janvete/resticview"
repository = "https://git.janvete.com/seth/resticview"
homepage = "https://git.janvete.com/seth/resticview"
keywords = ["cli", "tui", "restic", "backup"]
categories = ["command-line-utilities"]

18
Formula/resticview.rb Normal file
View file

@ -0,0 +1,18 @@
class Resticview < Formula
desc "TUI browser for restic backup repositories"
homepage "https://git.janvete.com/seth/resticview"
url "https://git.janvete.com/seth/resticview/archive/v0.1.4.tar.gz"
sha256 "79de9f0e8ecac078094e457677c316c6f0a37ca87de36d82ec0723c283aaa4b2"
license "MIT"
head "https://git.janvete.com/seth/resticview.git", branch: "main"
depends_on "rust" => :build
def install
system "cargo", "install", *std_cargo_args
end
test do
assert_match "TUI browser for restic backup repositories", shell_output("#{bin}/resticview --help")
end
end

View file

@ -1,20 +1,39 @@
# resticview
A TUI browser for restic backup repositories. Browse snapshots, explore the file tree of any snapshot, view repository stats, and restore whole snapshots or single paths on demand.
A TUI browser for restic backup repositories. Browse snapshots, explore the file tree of any snapshot, and restore whole snapshots or single paths on demand.
## Installation
### macOS (Homebrew)
```bash
brew tap janvete/tools
brew tap janvete/tools https://git.janvete.com/seth/homebrew-tools.git
brew install resticview
```
### Debian / Ubuntu (.deb)
Add the janvete APT repository and install:
```bash
echo "deb [trusted=yes] https://git.janvete.com/seth/apt/raw/branch/main ./" | sudo tee /etc/apt/sources.list.d/janvete.list
sudo apt update
sudo apt install resticview
```
### Prebuilt binaries
Each [release](https://git.janvete.com/seth/resticview/releases) also ships standalone binaries: `resticview-macos` (Apple Silicon) and `resticview-linux` (x86_64). Put the file on your `PATH` and make it executable:
```bash
chmod +x resticview-linux
sudo mv resticview-linux /usr/local/bin/resticview
```
### From source
```bash
cargo install --git https://github.com/janvete/resticview
cargo install --git ssh://git@git-ssh.janvete.com:554/seth/resticview
```
`restic` must be installed and on `PATH`.
@ -29,7 +48,7 @@ resticview --env-dir DIR # use a different env directory
resticview --select # always show the env file picker
```
The main view has three panels: snapshots (left), the file tree of the selected snapshot (middle), and repository stats (right). The focused panel has a highlighted border.
The main view has three panels: snapshots (left), the file tree of the selected snapshot (middle), and repository / snapshot info (right). The right panel shows the repository name, env file, total snapshot count, and details of the selected snapshot (time, host, user, paths, tags). The focused panel has a highlighted border.
Restore (`r`) asks for a target directory (pre-filled with `~/restic-restore-<id>`), asks for confirmation, and then runs `restic restore` in the background. With the focus on the snapshot list the whole snapshot is restored; with the focus on the file tree only the selected path is restored (`--include`).
@ -45,7 +64,7 @@ Restore (`r`) asks for a target directory (pre-filled with `~/restic-restore-<id
| `h` / `l` or `←` / `→` | collapse / expand directory |
| `g` / `G` | jump to top / bottom |
| `r` | restore selected snapshot or path |
| `R` | refresh snapshots and repository stats |
| `R` | refresh snapshots |
| `Esc` | close prompt / dialog, clear status |
## License

View file

@ -16,30 +16,30 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEventKind};
use ratatui::widgets::ListState;
use crate::envfile::EnvFile;
use crate::restic::{self, LsLine, Snapshot, Stats};
use crate::restic::{self, LsLine, Snapshot};
use crate::tree::Tree;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Focus {
Snapshots,
Tree,
Stats,
Repo,
}
impl Focus {
pub fn next(self) -> Self {
match self {
Focus::Snapshots => Focus::Tree,
Focus::Tree => Focus::Stats,
Focus::Stats => Focus::Snapshots,
Focus::Tree => Focus::Repo,
Focus::Repo => Focus::Snapshots,
}
}
pub fn prev(self) -> Self {
match self {
Focus::Snapshots => Focus::Stats,
Focus::Snapshots => Focus::Repo,
Focus::Tree => Focus::Snapshots,
Focus::Stats => Focus::Tree,
Focus::Repo => Focus::Tree,
}
}
}
@ -85,7 +85,6 @@ pub enum BgMsg {
snapshot: String,
result: Result<Vec<LsLine>, String>,
},
Stats(Result<Stats, String>),
Restore(Result<String, String>),
}
@ -112,8 +111,6 @@ pub struct App {
tree_generation: u64,
tree_cancel: Arc<AtomicBool>,
pub stats: LoadState<Stats>,
pub restore_state: RestoreState,
/// Last finished restore: (success, message).
pub restore_outcome: Option<(bool, String)>,
@ -144,7 +141,6 @@ impl App {
tree_cache: HashMap::new(),
tree_generation: 0,
tree_cancel: Arc::new(AtomicBool::new(false)),
stats: LoadState::Loading,
restore_state: RestoreState::Idle,
restore_outcome: None,
restore_cancel: Arc::new(AtomicBool::new(false)),
@ -153,7 +149,6 @@ impl App {
rx,
};
app.spawn_snapshots();
app.spawn_stats();
app
}
@ -180,16 +175,6 @@ impl App {
});
}
fn spawn_stats(&mut self) {
self.stats = LoadState::Loading;
let env = self.env.clone();
let tx = self.tx.clone();
thread::spawn(move || {
let result = restic::stats(&env).map_err(|e| format!("{e:#}"));
let _ = tx.send(BgMsg::Stats(result));
});
}
/// Make sure the tree for the currently selected snapshot is loaded:
/// serve it from the cache when possible, otherwise start a background
/// load (cancelling any stale one).
@ -230,7 +215,7 @@ impl App {
});
}
/// Refresh snapshots and stats (`R`); drops the tree cache.
/// Refresh snapshots (`R`); drops the tree cache.
pub fn refresh(&mut self) {
self.tree_cancel.store(true, Ordering::Relaxed);
self.tree_generation += 1;
@ -238,7 +223,6 @@ impl App {
self.tree = None;
self.tree_status = TreeStatus::Idle;
self.spawn_snapshots();
self.spawn_stats();
self.status = Some("refreshing…".to_string());
}
@ -286,12 +270,6 @@ impl App {
}
}
}
BgMsg::Stats(Ok(stats)) => {
self.stats = LoadState::Ready(stats);
}
BgMsg::Stats(Err(e)) => {
self.stats = LoadState::Failed(e);
}
BgMsg::Restore(result) => {
self.restore_state = RestoreState::Idle;
match result {
@ -355,7 +333,7 @@ impl App {
}
}
Focus::Snapshots => self.focus = Focus::Tree,
Focus::Stats => {}
Focus::Repo => {}
},
_ => {}
}
@ -391,7 +369,7 @@ impl App {
tree.move_by(delta);
}
}
Focus::Stats => {}
Focus::Repo => {}
}
}
@ -408,7 +386,7 @@ impl App {
tree.first();
}
}
Focus::Stats => {}
Focus::Repo => {}
}
}
@ -430,7 +408,7 @@ impl App {
tree.last();
}
}
Focus::Stats => {}
Focus::Repo => {}
}
}
@ -461,7 +439,7 @@ impl App {
return;
}
},
Focus::Stats => {
Focus::Repo => {
self.status = Some("focus Snapshots or Files to restore".to_string());
return;
}
@ -661,8 +639,8 @@ mod tests {
#[test]
fn focus_cycles() {
assert_eq!(Focus::Snapshots.next(), Focus::Tree);
assert_eq!(Focus::Tree.next(), Focus::Stats);
assert_eq!(Focus::Stats.next(), Focus::Snapshots);
assert_eq!(Focus::Snapshots.prev(), Focus::Stats);
assert_eq!(Focus::Tree.next(), Focus::Repo);
assert_eq!(Focus::Repo.next(), Focus::Snapshots);
assert_eq!(Focus::Snapshots.prev(), Focus::Repo);
}
}

View file

@ -22,7 +22,7 @@ impl EnvFile {
self.vars.get(key).map(String::as_str)
}
/// Value of RESTIC_REPOSITORY, for display in the picker and stats panel.
/// Value of RESTIC_REPOSITORY, for display in the picker and repo panel.
pub fn repository(&self) -> &str {
self.get("RESTIC_REPOSITORY")
.unwrap_or("(no RESTIC_REPOSITORY)")

View file

@ -22,6 +22,11 @@ use serde::Deserialize;
pub struct Snapshot {
pub short_id: String,
pub time: String,
pub hostname: String,
pub username: String,
pub paths: Vec<String>,
#[serde(default)]
pub tags: Vec<String>,
}
/// One line of `restic ls <id> --json` (either the snapshot header or a node).
@ -47,13 +52,6 @@ impl LsLine {
}
}
/// Result of `restic stats --json` (default mode).
#[derive(Debug, Clone, Deserialize)]
pub struct Stats {
pub total_size: u64,
pub total_file_count: u64,
}
fn base_command(env: &HashMap<String, String>) -> Command {
let mut cmd = Command::new("restic");
cmd.envs(env);
@ -136,19 +134,6 @@ pub fn ls(env: &HashMap<String, String>, snapshot: &str, cancel: &AtomicBool) ->
Ok(out)
}
/// `restic stats --json` (default mode).
pub fn stats(env: &HashMap<String, String>) -> Result<Stats> {
let out = base_command(env)
.args(["stats", "--json"])
.output()
.context("failed to run restic (is it installed and on PATH?)")?;
if !out.status.success() {
return Err(stderr_error(&out.stderr));
}
let text = String::from_utf8_lossy(&out.stdout);
serde_json::from_str(text.trim()).context("failed to parse restic stats output")
}
/// `restic restore <snapshot> --target <dir> [--include <path>]`.
///
/// Polls the child so a running restore can be cancelled via `cancel`
@ -214,11 +199,21 @@ mod tests {
#[test]
fn parse_snapshot_json() {
// Real restic output carries many more fields; serde ignores them.
let json = r#"[{"time":"2026-08-15T21:02:18.148309+02:00","paths":["/Users/seth"],"hostname":"mac.local","username":"seth","id":"46dd2015bcdb","short_id":"46dd2015"}]"#;
let json = r#"[{"time":"2026-08-15T21:02:18.148309+02:00","paths":["/Users/seth"],"hostname":"mac.local","username":"seth","id":"46dd2015bcdb","short_id":"46dd2015","tags":["daily","auto"]}]"#;
let snaps: Vec<Snapshot> = serde_json::from_str(json).unwrap();
assert_eq!(snaps[0].short_id, "46dd2015");
assert_eq!(snaps[0].time, "2026-08-15T21:02:18.148309+02:00");
assert_eq!(snaps[0].hostname, "mac.local");
assert_eq!(snaps[0].username, "seth");
assert_eq!(snaps[0].paths, vec!["/Users/seth"]);
assert_eq!(snaps[0].tags, vec!["daily", "auto"]);
}
#[test]
fn parse_snapshot_json_without_tags() {
let json = r#"[{"time":"2026-08-15T21:02:18.148309+02:00","paths":["/Users/seth"],"hostname":"mac.local","username":"seth","id":"46dd2015bcdb","short_id":"46dd2015"}]"#;
let snaps: Vec<Snapshot> = serde_json::from_str(json).unwrap();
assert!(snaps[0].tags.is_empty());
}
#[test]
@ -247,17 +242,6 @@ mod tests {
assert_eq!(file.size, Some(1234));
}
#[test]
fn parse_stats_json() {
// `snapshots_count` (present since restic 0.19) is ignored.
let stats: Stats = serde_json::from_str(
r#"{"total_size":16942067259,"total_file_count":294549,"snapshots_count":6}"#,
)
.unwrap();
assert_eq!(stats.total_size, 16942067259);
assert_eq!(stats.total_file_count, 294549);
}
#[test]
fn tilde_expansion() {
let home = dirs::home_dir().unwrap();

View file

@ -26,7 +26,7 @@ pub fn draw(frame: &mut Frame, app: &mut App) {
draw_snapshots(frame, app, cols[0]);
draw_tree(frame, app, cols[1]);
draw_stats(frame, app, cols[2]);
draw_repo(frame, app, cols[2]);
draw_status(frame, app, chunks[1]);
draw_footer(frame, chunks[2]);
@ -183,25 +183,26 @@ fn draw_tree(frame: &mut Frame, app: &mut App, area: Rect) {
}
}
fn draw_stats(frame: &mut Frame, app: &App, area: Rect) {
let focused = app.focus == Focus::Stats;
fn draw_repo(frame: &mut Frame, app: &App, area: Rect) {
let focused = app.focus == Focus::Repo;
let block = panel_block("Repository".to_string(), focused);
let label = Style::default().fg(Color::Gray);
let value = Style::default();
let mut lines = vec![
Line::from(vec![
Span::styled("Repository: ", label),
Span::raw(app.repo.clone()),
Span::styled(app.repo.clone(), value),
]),
Line::from(vec![
Span::styled("Env file: ", label),
Span::raw(app.env_rel_path.clone()),
Span::styled(app.env_rel_path.clone(), value),
]),
Line::from(""),
];
match &app.snapshots {
LoadState::Ready(snaps) => lines.push(Line::from(vec![
Span::styled("Snapshots: ", label),
Span::raw(snaps.len().to_string()),
Span::styled(snaps.len().to_string(), value),
])),
LoadState::Loading => lines.push(Line::from(vec![
Span::styled("Snapshots: ", label),
@ -212,33 +213,45 @@ fn draw_stats(frame: &mut Frame, app: &App, area: Rect) {
Span::styled("error", Style::default().fg(Color::Red)),
])),
}
match &app.stats {
LoadState::Loading => lines.push(Line::from(vec![
Span::styled("Stats: ", label),
Span::raw(format!("{} loading…", app.spinner())),
])),
LoadState::Failed(e) => {
lines.push(Line::from(vec![
Span::styled("Stats: ", label),
Span::styled("error", Style::default().fg(Color::Red)),
]));
lines.push(Line::from(""));
lines.push(Line::from(Span::styled(
e.clone(),
Style::default().fg(Color::Red),
)));
}
LoadState::Ready(stats) => {
match app.selected_snapshot() {
Some(snap) => {
lines.push(Line::from(vec![
Span::styled("Total size: ", label),
Span::raw(human_size(stats.total_size)),
Span::styled("Snapshot: ", label),
Span::styled(snap.short_id.clone(), value),
]));
lines.push(Line::from(vec![
Span::styled("Files: ", label),
Span::raw(format_count(stats.total_file_count)),
Span::styled("Time: ", label),
Span::styled(format_time(&snap.time), value),
]));
lines.push(Line::from(vec![
Span::styled("Host: ", label),
Span::styled(snap.hostname.clone(), value),
]));
lines.push(Line::from(vec![
Span::styled("User: ", label),
Span::styled(snap.username.clone(), value),
]));
lines.push(Line::from(vec![
Span::styled("Paths: ", label),
Span::styled(snap.paths.join(", "), value),
]));
if !snap.tags.is_empty() {
lines.push(Line::from(vec![
Span::styled("Tags: ", label),
Span::styled(snap.tags.join(", "), value),
]));
}
}
None => {
lines.push(Line::from(vec![Span::styled(
"no snapshot selected",
Style::default().fg(Color::Gray),
)]));
}
}
frame.render_widget(
Paragraph::new(lines).block(block).wrap(Wrap { trim: false }),
area,
@ -355,18 +368,6 @@ pub fn human_size(bytes: u64) -> String {
format!("{value:.1} {}", UNITS[unit])
}
pub fn format_count(n: u64) -> String {
let s = n.to_string();
let mut out = String::new();
for (i, c) in s.chars().enumerate() {
if i > 0 && (s.len() - i).is_multiple_of(3) {
out.push(',');
}
out.push(c);
}
out
}
#[cfg(test)]
mod tests {
use super::*;
@ -389,10 +390,4 @@ mod tests {
assert_eq!(human_size(3158099665), "2.9 GiB");
}
#[test]
fn count_formatting() {
assert_eq!(format_count(294549), "294,549");
assert_eq!(format_count(6), "6");
assert_eq!(format_count(1000), "1,000");
}
}