v0.3.0 9fdf386

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// cursorText is the initial text of the cursor position in the status bar.
14func cursorText(n int) string {
15	if n == 0 {
16		return "0/0"
17	}
18	return "1/" + itoa(n)
19}
20
21// ago renders a short relative date: now, 5m ago, 3h ago, 12d ago, 5mo ago,
22// 2y ago.
23func ago(now, t time.Time) string {
24	if t.IsZero() {
25		return "never"
26	}
27	d := now.Sub(t)
28	switch {
29	case d < time.Minute:
30		return "now"
31	case d < time.Hour:
32		return fmt.Sprintf("%dm ago", int(d.Minutes()))
33	case d < 48*time.Hour:
34		return fmt.Sprintf("%dh ago", int(d.Hours()))
35	case d < 60*24*time.Hour:
36		return fmt.Sprintf("%dd ago", int(d.Hours()/24))
37	case d < 700*24*time.Hour:
38		return fmt.Sprintf("%dmo ago", int(d.Hours()/24/30))
39	}
40	return fmt.Sprintf("%dy ago", int(d.Hours()/24/365))
41}
42
43// absolute is the absolute form shown on hover.
44func absolute(t time.Time) string {
45	return t.UTC().Format("2006-01-02 15:04 UTC")
46}
47
48// rfc3339 is the machine form of a time, "" for the zero time.
49func rfc3339(t time.Time) string {
50	if t.IsZero() {
51		return ""
52	}
53	return t.UTC().Format(time.RFC3339)
54}
55
56func plural(n int, one, many string) string {
57	if n == 1 {
58		return "1 " + one
59	}
60	return itoa(n) + " " + many
61}
62
63// short is the abbreviated form of a commit id.
64func short(id string) string {
65	if len(id) > 7 {
66		return id[:7]
67	}
68	return id
69}

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