v0.28.0 fca9155

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, 5 min ago, 3h ago, 12d ago, 5mo
14// ago, 2y ago. Minutes are "min", so that they never read as months.
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("%d min 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
48// grouped writes a count with thousands separated by a thin space: 12 345.
49func grouped(n int) string {
50	s := itoa(n)
51	if n < 0 || len(s) <= 3 {
52		return s
53	}
54	var b []byte
55	for i := range len(s) {
56		if i > 0 && (len(s)-i)%3 == 0 {
57			b = append(b, "\u202f"...)
58		}
59		b = append(b, s[i])
60	}
61	return string(b)
62}
63
64// viewLabel names a diff layout on the button of the view menu.
65func viewLabel(view string) string {
66	if view == "split" {
67		return "Split"
68	}
69	return "Unified"
70}
71
72func plural(n int, one, many string) string {
73	if n == 1 {
74		return "1 " + one
75	}
76	return itoa(n) + " " + many
77}
78
79// short is the abbreviated form of a commit id.
80func short(id string) string {
81	if len(id) > 7 {
82		return id[:7]
83	}
84	return id
85}

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 4

Tags 45

↑↓ moveenter openesc close