v0.14.0 815fb98

format.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6	"fmt"
7	"strconv"
8	"time"
9)
10
11func itoa(n int) string { return strconv.Itoa(n) }
12
13// ago renders a short relative date: now, 5m ago, 3h ago, 12d ago, 5mo ago,
14// 2y ago.
15func ago(now, t time.Time) string {
16	if t.IsZero() {
17		return "never"
18	}
19	d := now.Sub(t)
20	switch {
21	case d < time.Minute:
22		return "now"
23	case d < time.Hour:
24		return fmt.Sprintf("%dm ago", int(d.Minutes()))
25	case d < 48*time.Hour:
26		return fmt.Sprintf("%dh ago", int(d.Hours()))
27	case d < 60*24*time.Hour:
28		return fmt.Sprintf("%dd ago", int(d.Hours()/24))
29	case d < 700*24*time.Hour:
30		return fmt.Sprintf("%dmo ago", int(d.Hours()/24/30))
31	}
32	return fmt.Sprintf("%dy ago", int(d.Hours()/24/365))
33}
34
35// absolute is the absolute form shown on hover.
36func absolute(t time.Time) string {
37	return t.UTC().Format("2006-01-02 15:04 UTC")
38}
39
40// rfc3339 is the machine form of a time, "" for the zero time.
41func rfc3339(t time.Time) string {
42	if t.IsZero() {
43		return ""
44	}
45	return t.UTC().Format(time.RFC3339)
46}
47
48func plural(n int, one, many string) string {
49	if n == 1 {
50		return "1 " + one
51	}
52	return itoa(n) + " " + many
53}
54
55// short is the abbreviated form of a commit id.
56func short(id string) string {
57	if len(id) > 7 {
58		return id[:7]
59	}
60	return id
61}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 44

↑↓ moveenter openesc close