Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d6c0f7508c | |||
| 6fdb4bbbf8 |
@@ -0,0 +1,65 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
# The release workflow gates a tag, which is late: a broken commit sits green until
|
||||||
|
# somebody decides to publish. This runs the same checks on the way in.
|
||||||
|
#
|
||||||
|
# push is scoped to main so that a branch pushed as part of a pull request is not checked
|
||||||
|
# twice.
|
||||||
|
#
|
||||||
|
# No actions/checkout, deliberately -- same as the terdut-server, letsvisit and charts
|
||||||
|
# workflows. The runner image is ubuntu:22.04 whose `nodejs` package is Node 12, and
|
||||||
|
# actions/checkout@v4 is built with ES2022 static initialiser blocks, so it dies with
|
||||||
|
# `SyntaxError: Unexpected token '{'` before running. Cloning with git directly avoids JS
|
||||||
|
# actions entirely. This repo is public, so the clone needs no credential at all.
|
||||||
|
#
|
||||||
|
# `${{ }}` values are passed through `env:` and referenced as quoted shell variables: a
|
||||||
|
# ref name is attacker-influenced by anyone who can push a branch or open a PR, and
|
||||||
|
# expanding one straight into `run:` is a shell-injection vector.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
# A rapid series of pushes only needs the last one checked.
|
||||||
|
concurrency:
|
||||||
|
group: ci-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
REPO_URL: https://git.ryuvia.com/niklas/terdut-tui.git
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: golang:1.26.6-bookworm
|
||||||
|
# act_runner destroys a job's own volumes when it finishes, so without these every
|
||||||
|
# run re-downloads the whole module graph. The names must appear in the runner's
|
||||||
|
# container.valid_volumes allowlist (charts/act-runner in the k8s repo); unlisted
|
||||||
|
# volumes are dropped silently, so a workflow that looks correct can still be
|
||||||
|
# running uncached.
|
||||||
|
volumes:
|
||||||
|
- go-mod-cache:/go/pkg/mod
|
||||||
|
- go-build-cache:/root/.cache/go-build
|
||||||
|
- gobin-cache:/go/bin
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
env:
|
||||||
|
REF_NAME: ${{ github.ref_name }}
|
||||||
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||||
|
run: |
|
||||||
|
if [ -n "$HEAD_SHA" ]; then
|
||||||
|
# A pull_request ref_name is "<n>/merge", which is not a fetchable branch.
|
||||||
|
git clone "$REPO_URL" .
|
||||||
|
git checkout -q "$HEAD_SHA"
|
||||||
|
else
|
||||||
|
git clone --depth=1 --branch "$REF_NAME" "$REPO_URL" .
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Vet
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
# Covers the API client against a stub server, the Update state machine, and View
|
||||||
|
# rendering -- all three are pure enough to test without a terminal.
|
||||||
|
- name: Test
|
||||||
|
run: go test ./...
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
# Checkout, interpolation and caching conventions match ci.yaml -- see the header there
|
||||||
|
# for why there are no JS actions and why every `${{ }}` goes through `env:`.
|
||||||
|
#
|
||||||
|
# There is no upload-artifact/download-artifact equivalent here (both are JS actions, and
|
||||||
|
# this Gitea has no artifact store wired up), so the job that builds the binaries is also
|
||||||
|
# the job that publishes them. Nothing is handed between jobs.
|
||||||
|
#
|
||||||
|
# The asset names matter beyond being tidy: internal/updater looks for exactly
|
||||||
|
# terdut-tui-<tag>-<goos>-<goarch> in the latest release and reports every available name
|
||||||
|
# when it cannot find one. Renaming the pattern here breaks self-update for every
|
||||||
|
# installed binary.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: release-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
REPO_URL: https://git.ryuvia.com/niklas/terdut-tui.git
|
||||||
|
API: https://git.ryuvia.com/api/v1/repos/niklas/terdut-tui
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Gates the build, so a tag that fails here publishes no binaries.
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: golang:1.26.6-bookworm
|
||||||
|
volumes:
|
||||||
|
- go-mod-cache:/go/pkg/mod
|
||||||
|
- go-build-cache:/root/.cache/go-build
|
||||||
|
- gobin-cache:/go/bin
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
env:
|
||||||
|
REF_NAME: ${{ github.ref_name }}
|
||||||
|
run: git clone --depth=1 --branch "$REF_NAME" "$REPO_URL" .
|
||||||
|
|
||||||
|
- name: Vet
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
binaries:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: golang:1.26.6-bookworm
|
||||||
|
volumes:
|
||||||
|
- go-mod-cache:/go/pkg/mod
|
||||||
|
- go-build-cache:/root/.cache/go-build
|
||||||
|
- gobin-cache:/go/bin
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
env:
|
||||||
|
REF_NAME: ${{ github.ref_name }}
|
||||||
|
run: git clone --depth=1 --branch "$REF_NAME" "$REPO_URL" .
|
||||||
|
|
||||||
|
- name: Build every target
|
||||||
|
env:
|
||||||
|
REF_NAME: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
mkdir -p dist
|
||||||
|
for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do
|
||||||
|
GOOS="${target%/*}"
|
||||||
|
GOARCH="${target#*/}"
|
||||||
|
out="dist/terdut-tui-${REF_NAME}-${GOOS}-${GOARCH}"
|
||||||
|
echo "building $out"
|
||||||
|
GOOS="$GOOS" GOARCH="$GOARCH" go build \
|
||||||
|
-ldflags "-X main.version=${REF_NAME}" \
|
||||||
|
-o "$out" .
|
||||||
|
done
|
||||||
|
|
||||||
|
# Creating the release is made idempotent rather than assumed-new: a re-run of a
|
||||||
|
# failed release must not die on the release that already exists. Assets are
|
||||||
|
# replaced the same way, so a re-run repairs a partial upload.
|
||||||
|
- name: Publish the release
|
||||||
|
env:
|
||||||
|
REF_NAME: ${{ github.ref_name }}
|
||||||
|
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
auth="Authorization: token $TOKEN"
|
||||||
|
|
||||||
|
body=$(curl -sf -H "$auth" "$API/releases/tags/$REF_NAME" || true)
|
||||||
|
if [ -z "$body" ]; then
|
||||||
|
body=$(curl -sf -X POST -H "$auth" -H 'Content-Type: application/json' \
|
||||||
|
-d "{\"tag_name\":\"$REF_NAME\",\"name\":\"$REF_NAME\"}" \
|
||||||
|
"$API/releases")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The release object serialises `id` first, so the first match is the release's
|
||||||
|
# own id and not one of the nested author/asset ids.
|
||||||
|
release_id=$(printf '%s' "$body" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
[ -n "$release_id" ] || { echo "::error::could not determine release id"; exit 1; }
|
||||||
|
echo "release id $release_id"
|
||||||
|
|
||||||
|
for f in dist/*; do
|
||||||
|
name=$(basename "$f")
|
||||||
|
# Drop an existing asset of the same name first: Gitea happily stores two
|
||||||
|
# attachments with one name, and the updater matches by name.
|
||||||
|
old=$(curl -sf -H "$auth" "$API/releases/$release_id/assets" \
|
||||||
|
| tr '}' '\n' | grep "\"name\":\"$name\"" \
|
||||||
|
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
|
if [ -n "$old" ]; then
|
||||||
|
curl -sf -X DELETE -H "$auth" "$API/releases/$release_id/assets/$old" || true
|
||||||
|
fi
|
||||||
|
echo "uploading $name"
|
||||||
|
curl -sf -X POST -H "$auth" -F "attachment=@$f" \
|
||||||
|
"$API/releases/$release_id/assets?name=$name" > /dev/null
|
||||||
|
done
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
# The release workflow gates a tag, which is late: a broken commit sits green
|
|
||||||
# until somebody decides to publish. This runs the same checks on the way in.
|
|
||||||
#
|
|
||||||
# push is scoped to main so that a branch pushed as part of a pull request is
|
|
||||||
# not checked twice.
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
# A rapid series of pushes only needs the last one checked.
|
|
||||||
concurrency:
|
|
||||||
group: ci-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Vet
|
|
||||||
run: go vet ./...
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: go test ./...
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
name: Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# Gates the build, so a tag that fails here publishes no binaries. The suite
|
|
||||||
# covers the API client against a stub server, the Update state machine, and
|
|
||||||
# View rendering — all three are pure enough to test without a terminal.
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Vet
|
|
||||||
run: go vet ./...
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: go test ./...
|
|
||||||
|
|
||||||
build:
|
|
||||||
needs: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
- goos: linux
|
|
||||||
goarch: arm64
|
|
||||||
- goos: darwin
|
|
||||||
goarch: amd64
|
|
||||||
- goos: darwin
|
|
||||||
goarch: arm64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
env:
|
|
||||||
GOOS: ${{ matrix.goos }}
|
|
||||||
GOARCH: ${{ matrix.goarch }}
|
|
||||||
run: |
|
|
||||||
go build \
|
|
||||||
-ldflags "-X main.version=${{ github.ref_name }}" \
|
|
||||||
-o terdut-tui-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
|
|
||||||
.
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: terdut-tui-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
||||||
path: terdut-tui-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
||||||
|
|
||||||
release:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
merge-multiple: true
|
|
||||||
|
|
||||||
- uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
files: 'terdut-tui-*'
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# terdut-tui
|
# terdut-tui
|
||||||
|
|
||||||
TUI client for [terdut-server](https://github.com/terdut-server), a Prometheus Alertmanager receiver and incident manager. Requires server **v0.4.0+**.
|
TUI client for [terdut-server](https://git.ryuvia.com/niklas/terdut-server), a Prometheus Alertmanager receiver and incident manager. Requires server **v0.4.0+**.
|
||||||
|
|
||||||
## Domain model
|
## Domain model
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# terdut-tui
|
# terdut-tui
|
||||||
|
|
||||||
A terminal user interface for [terdut-server](https://github.com/terdut-server). Communicates with the server over its REST API.
|
A terminal user interface for [terdut-server](https://git.ryuvia.com/niklas/terdut-server). Communicates with the server over its REST API.
|
||||||
|
|
||||||
Written in Go using [Bubbletea](https://github.com/charmbracelet/bubbletea).
|
Written in Go using [Bubbletea](https://github.com/charmbracelet/bubbletea).
|
||||||
|
|
||||||
@@ -55,10 +55,10 @@ editing one reports the server's 404.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Download the latest release binary for your platform from the [releases page](https://github.com/yeniklas/terdut-tui/releases), or build from source:
|
Download the latest release binary for your platform from the [releases page](https://git.ryuvia.com/niklas/terdut-tui/releases), or build from source:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go install github.com/yeniklas/terdut-tui@latest
|
go install git.ryuvia.com/niklas/terdut-tui@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module github.com/yeniklas/terdut-tui
|
module git.ryuvia.com/niklas/terdut-tui
|
||||||
|
|
||||||
go 1.25.9
|
go 1.25.9
|
||||||
|
|
||||||
|
|||||||
+25
-7
@@ -4,13 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/charmbracelet/bubbles/help"
|
||||||
"github.com/charmbracelet/bubbles/table"
|
"github.com/charmbracelet/bubbles/table"
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ── Enums ──────────────────────────────────────────────────────────────────
|
// ── Enums ──────────────────────────────────────────────────────────────────
|
||||||
@@ -354,27 +354,45 @@ func defaultTableStyles() table.Styles {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setRows replaces a table's rows and keeps its cursor in a state the rest of
|
||||||
|
// this package can rely on: valid whenever the table has any rows at all.
|
||||||
|
//
|
||||||
|
// bubbles does not do that on its own. SetRows only clamps the cursor *down*
|
||||||
|
// (`if m.cursor > len(rows)-1`), so setting zero rows drives it to -1 and
|
||||||
|
// nothing ever brings it back — filling the table later leaves -1 in place,
|
||||||
|
// because -1 is not greater than len-1. Every table here is rebuilt from empty
|
||||||
|
// once at startup, when the first WindowSizeMsg arrives before any fetch has
|
||||||
|
// returned, so without this every cursor is -1 until the user happens to press
|
||||||
|
// up or down. Indexing a slice with that panics, which is exactly what
|
||||||
|
// assigning an on-call week did.
|
||||||
|
func setRows(t *table.Model, rows []table.Row) {
|
||||||
|
t.SetRows(rows)
|
||||||
|
if len(rows) > 0 && t.Cursor() < 0 {
|
||||||
|
t.SetCursor(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildIncidentTable() {
|
func (m *Model) rebuildIncidentTable() {
|
||||||
m.incidentTable.SetColumns(incidentColumns(m.width))
|
m.incidentTable.SetColumns(incidentColumns(m.width))
|
||||||
m.incidentTable.SetRows(incidentRows(m.incidents))
|
setRows(&m.incidentTable, incidentRows(m.incidents))
|
||||||
m.incidentTable.SetHeight(tableHeight(m.height, 8))
|
m.incidentTable.SetHeight(tableHeight(m.height, 8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildTable() {
|
func (m *Model) rebuildTable() {
|
||||||
m.alertTable.SetColumns(alertColumns(m.width))
|
m.alertTable.SetColumns(alertColumns(m.width))
|
||||||
m.alertTable.SetRows(alertRows(m.alerts))
|
setRows(&m.alertTable, alertRows(m.alerts))
|
||||||
m.alertTable.SetHeight(tableHeight(m.height, 8))
|
m.alertTable.SetHeight(tableHeight(m.height, 8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildArchivedTable() {
|
func (m *Model) rebuildArchivedTable() {
|
||||||
m.archivedTable.SetColumns(incidentColumns(m.width))
|
m.archivedTable.SetColumns(incidentColumns(m.width))
|
||||||
m.archivedTable.SetRows(incidentRows(m.archivedIncidents))
|
setRows(&m.archivedTable, incidentRows(m.archivedIncidents))
|
||||||
m.archivedTable.SetHeight(tableHeight(m.height, 8))
|
m.archivedTable.SetHeight(tableHeight(m.height, 8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildScheduleTable() {
|
func (m *Model) rebuildScheduleTable() {
|
||||||
m.scheduleTable.SetColumns(scheduleColumns(m.width))
|
m.scheduleTable.SetColumns(scheduleColumns(m.width))
|
||||||
m.scheduleTable.SetRows(scheduleRows(m.scheduleDays))
|
setRows(&m.scheduleTable, scheduleRows(m.scheduleDays))
|
||||||
m.scheduleTable.SetHeight(tableHeight(m.height, 10))
|
m.scheduleTable.SetHeight(tableHeight(m.height, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +402,7 @@ func (m *Model) rebuildUserPickerTable() {
|
|||||||
for i, u := range m.users {
|
for i, u := range m.users {
|
||||||
rows[i] = table.Row{u.Username, u.Email}
|
rows[i] = table.Row{u.Username, u.Email}
|
||||||
}
|
}
|
||||||
m.userPickerTable.SetRows(rows)
|
setRows(&m.userPickerTable, rows)
|
||||||
m.userPickerTable.SetHeight(tableHeight(m.height, 10))
|
m.userPickerTable.SetHeight(tableHeight(m.height, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +416,7 @@ func (m *Model) rebuildUserManageTable() {
|
|||||||
}
|
}
|
||||||
rows[i] = table.Row{u.Username, u.Email, topic, u.CreatedAt.UTC().Format("2006-01-02")}
|
rows[i] = table.Row{u.Username, u.Email, topic, u.CreatedAt.UTC().Format("2006-01-02")}
|
||||||
}
|
}
|
||||||
m.userManageTable.SetRows(rows)
|
setRows(&m.userManageTable, rows)
|
||||||
m.userManageTable.SetHeight(tableHeight(m.height, 10))
|
m.userManageTable.SetHeight(tableHeight(m.height, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
"github.com/charmbracelet/bubbles/table"
|
"github.com/charmbracelet/bubbles/table"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNextFilter(t *testing.T) {
|
func TestNextFilter(t *testing.T) {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package tui
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
@@ -468,7 +468,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
cursor := m.scheduleTable.Cursor()
|
cursor := m.scheduleTable.Cursor()
|
||||||
if cursor >= len(m.scheduleDays) {
|
if cursor < 0 || cursor >= len(m.scheduleDays) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
day := m.scheduleDays[cursor]
|
day := m.scheduleDays[cursor]
|
||||||
@@ -484,7 +484,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
cursor := m.userManageTable.Cursor()
|
cursor := m.userManageTable.Cursor()
|
||||||
if cursor >= len(m.users) {
|
if cursor < 0 || cursor >= len(m.users) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
m.selectedUser = m.users[cursor]
|
m.selectedUser = m.users[cursor]
|
||||||
@@ -510,7 +510,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
cursor := m.userManageTable.Cursor()
|
cursor := m.userManageTable.Cursor()
|
||||||
if cursor >= len(m.users) {
|
if cursor < 0 || cursor >= len(m.users) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
m.selectedUser = m.users[cursor]
|
m.selectedUser = m.users[cursor]
|
||||||
@@ -527,7 +527,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
cursor := m.userManageTable.Cursor()
|
cursor := m.userManageTable.Cursor()
|
||||||
if cursor >= len(m.users) {
|
if cursor < 0 || cursor >= len(m.users) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
m.selectedUser = m.users[cursor]
|
m.selectedUser = m.users[cursor]
|
||||||
@@ -893,7 +893,7 @@ func (m Model) handleUserPickerKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scheduleCursor := m.scheduleTable.Cursor()
|
scheduleCursor := m.scheduleTable.Cursor()
|
||||||
if scheduleCursor >= len(m.scheduleDays) {
|
if scheduleCursor < 0 || scheduleCursor >= len(m.scheduleDays) {
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// press sends one key and returns the resulting model and command. A nil command
|
// press sends one key and returns the resulting model and command. A nil command
|
||||||
@@ -676,3 +676,50 @@ func containsAll(s string, subs ...string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The bug: assigning an on-call week panicked with "index out of range [-1]"
|
||||||
|
// on a perfectly normal schedule, as long as nobody had moved the cursor first.
|
||||||
|
//
|
||||||
|
// The cause is not in this package. bubbles' SetRows clamps the cursor down but
|
||||||
|
// never up, so the empty rebuild every table gets from the first WindowSizeMsg
|
||||||
|
// -- which arrives before any fetch returns -- pins the cursor at -1, and
|
||||||
|
// loading real rows afterwards leaves it there. Pressing up or down hid it,
|
||||||
|
// which is why every existing test missed it: they all call SetCursor, and
|
||||||
|
// SetCursor clamps.
|
||||||
|
//
|
||||||
|
// So this test must NOT touch the cursor. It reproduces the real order of
|
||||||
|
// events: size first, data second, keys third.
|
||||||
|
func TestSchedule_AssignWeekAfterStartupSizingDoesNotPanic(t *testing.T) {
|
||||||
|
m := NewModel(nil, "http://test", time.Minute)
|
||||||
|
m.connected = true
|
||||||
|
m.activeSection = sectionSchedule
|
||||||
|
m.scheduleWindow = time.Date(2026, 7, 27, 0, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
|
// 1. Terminal size arrives while every table is still empty.
|
||||||
|
next, _ := m.Update(tea.WindowSizeMsg{Width: 120, Height: 40})
|
||||||
|
m = next.(Model)
|
||||||
|
|
||||||
|
// 2. The schedule and the user list land.
|
||||||
|
next, _ = m.Update(scheduleFetchedMsg{entries: []api.ScheduleEntry{}})
|
||||||
|
m = next.(Model)
|
||||||
|
next, _ = m.Update(usersFetchedMsg{users: []api.User{
|
||||||
|
{ID: 1, Username: "niklas", Email: "n@example.com"},
|
||||||
|
}})
|
||||||
|
m = next.(Model)
|
||||||
|
|
||||||
|
if got := m.scheduleTable.Cursor(); got < 0 {
|
||||||
|
t.Fatalf("schedule cursor is %d after loading %d days; a populated table must have a usable cursor",
|
||||||
|
got, len(m.scheduleDays))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Assign the week to the first user, without ever moving a cursor.
|
||||||
|
m, _ = press(t, m, "W")
|
||||||
|
if m.mode != modeUserPicker {
|
||||||
|
t.Fatalf("W did not open the user picker, got mode %v", m.mode)
|
||||||
|
}
|
||||||
|
m, _ = press(t, m, "enter") // panicked here
|
||||||
|
|
||||||
|
if m.mode == modeUserPicker {
|
||||||
|
t.Fatal("enter left the picker open; the assignment never went anywhere")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Order must match the section constants — renderTabs indexes this by ordinal.
|
// Order must match the section constants — renderTabs indexes this by ordinal.
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ansi matches the escape sequences lipgloss emits when it decides the output
|
// ansi matches the escape sequences lipgloss emits when it decides the output
|
||||||
|
|||||||
@@ -12,7 +12,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const releaseAPI = "https://api.github.com/repos/yeniklas/terdut-tui/releases/latest"
|
// Gitea's release payload carries the same tag_name, and its attachments the same name
|
||||||
|
// and browser_download_url, so the types below are unchanged from the GitHub original.
|
||||||
|
//
|
||||||
|
// A binary installed before the move still polls api.github.com and will never see a
|
||||||
|
// release published here. That GitHub repository is still in place, so such a build
|
||||||
|
// reports itself up to date rather than erroring -- its last GitHub release is the
|
||||||
|
// bridge, and crossing it is a one-time manual download.
|
||||||
|
const releaseAPI = "https://git.ryuvia.com/api/v1/repos/niklas/terdut-tui/releases/latest"
|
||||||
|
|
||||||
type release struct {
|
type release struct {
|
||||||
TagName string `json:"tag_name"`
|
TagName string `json:"tag_name"`
|
||||||
@@ -125,7 +132,7 @@ func fetchLatest() (*release, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/vnd.github+json")
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -134,7 +141,7 @@ func fetchLatest() (*release, error) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("GitHub API returned %s", resp.Status)
|
return nil, fmt.Errorf("Gitea API returned %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rel release
|
var rel release
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/config"
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/tui"
|
||||||
|
"git.ryuvia.com/niklas/terdut-tui/internal/updater"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
|
||||||
"github.com/yeniklas/terdut-tui/internal/config"
|
|
||||||
"github.com/yeniklas/terdut-tui/internal/tui"
|
|
||||||
"github.com/yeniklas/terdut-tui/internal/updater"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "dev"
|
var version = "dev"
|
||||||
|
|||||||
Reference in New Issue
Block a user