v0.1.0 28f9d6e

number.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package template
4
5import (
6	"math"
7	"strconv"
8	"strings"
9)
10
11// JSNumberString formats x like JavaScript's Number.prototype.toString: the
12// shortest decimal that round-trips, positional for decimal exponents from -7
13// to 20, exponent notation beyond. The reference uses it for the text of a
14// number token.
15func JSNumberString(x float64) string {
16	switch {
17	case math.IsNaN(x):
18		return "NaN"
19	case x == 0:
20		return "0"
21	case math.IsInf(x, 1):
22		return "Infinity"
23	case math.IsInf(x, -1):
24		return "-Infinity"
25	}
26	sign := ""
27	if x < 0 {
28		sign = "-"
29		x = -x
30	}
31	s := strconv.FormatFloat(x, 'e', -1, 64)
32	mant, expStr, _ := strings.Cut(s, "e")
33	exp, _ := strconv.Atoi(expStr)
34	digits := strings.Replace(mant, ".", "", 1)
35	k := len(digits)
36	n := exp + 1
37	switch {
38	case k <= n && n <= 21:
39		return sign + digits + strings.Repeat("0", n-k)
40	case 0 < n && n <= 21:
41		return sign + digits[:n] + "." + digits[n:]
42	case -6 < n && n <= 0:
43		return sign + "0." + strings.Repeat("0", -n) + digits
44	}
45	e := n - 1
46	esign := "+"
47	if e < 0 {
48		esign = "-"
49		e = -e
50	}
51	if k == 1 {
52		return sign + digits + "e" + esign + strconv.Itoa(e)
53	}
54	return sign + digits[:1] + "." + digits[1:] + "e" + esign + strconv.Itoa(e)
55}

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 1

Tags 3

↑↓ moveenter openesc close