Search Apps Documentation Source Content File Folder Download Copy Actions Download

format.gno

0.98 Kb ยท 57 lines
 1package boards2
 2
 3import (
 4	"strconv"
 5	"strings"
 6
 7	"gno.land/p/moul/md"
 8
 9	"gno.land/r/sys/users"
10)
11
12func padLeft(s string, length int) string {
13	if len(s) >= length {
14		return s
15	}
16	return strings.Repeat(" ", length-len(s)) + s
17}
18
19func padZero(u64 uint64, length int) string {
20	s := strconv.Itoa(int(u64))
21	if len(s) >= length {
22		return s
23	}
24	return strings.Repeat("0", length-len(s)) + s
25}
26
27func indentBody(indent string, body string) string {
28	var (
29		res   string
30		lines = strings.Split(body, "\n")
31	)
32	for i, line := range lines {
33		if i > 0 {
34			res += "\n"
35		}
36		res += indent + line
37	}
38	return res
39}
40
41func summaryOf(text string, length int) string {
42	lines := strings.SplitN(text, "\n", 2)
43	line := lines[0]
44	if len(line) > length {
45		line = line[:(length-3)] + "..."
46	} else if len(lines) > 1 {
47		line = line + "..."
48	}
49	return line
50}
51
52func userLink(addr address) string {
53	if u := users.ResolveAddress(addr); u != nil {
54		return md.UserLink(u.Name())
55	}
56	return md.UserLink(addr.String())
57}