src/share/say.bend
ezx@1.11.0.0 · 184 lines · 31 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16import Base
17import ezx@1.11.0.0/src/pkg/path.bend as P
18
19
20
21
22type Spin is Data:
23 Spin{dev: String, pid: String, msg: String}
24
25
26
27def brief.go(short: Bool, +rev: String) -> String:
28 match short:
29 case True{}:
30 rev
31 case False{}:
32 String.take(rev, 12n)
33
34
35def brief(+rev: String) -> String:
36 brief.go(Nat.is_le(String.length(rev), 12n), rev)
37
38
39
40def label.go(empty: Bool, +hash: String, +name: String) -> String:
41 match empty:
42 case True{}:
43 hash
44 case False{}:
45 name
46
47
48def label(+hash: String, +entry: String) -> String:
49 +name = P.unbend(P.base(entry))
50 label.go(String.is_empty(name), hash, name)
51
52
53def dep.git(+name: String, +url: String) -> String:
54 "dep " ++ name ++ ": git fetch (" ++ url ++ ")"
55
56
57def dep.hub(+name: String) -> String:
58 "dep " ++ name ++ ": hub fetch"
59
60
61def reused(+name: String) -> String:
62 name ++ ": cached"
63
64
65def resolving() -> String:
66 "resolving deps"
67
68def resolving.at(+name: String) -> String:
69 "resolving " ++ name
70
71def git.fetch(+url: String) -> String:
72 "git fetch (" ++ url ++ ")"
73
74
75def building(+name: String) -> String:
76 "building " ++ name
77
78
79def linking(+at: String) -> String:
80 "linking " ++ at
81
82
83def installed(+name: String, +at: String) -> String:
84 "installed " ++ name ++ " -> " ++ at
85
86
87def linked(+name: String, +at: String) -> String:
88 "linked " ++ name ++ " -> " ++ at
89
90
91def hashing(+rev: String) -> String:
92 "hashing " ++ brief(rev)
93
94
95def tty.at(+path: String) -> Bool:
96 Bool.or(String.starts_with(path, "/dev/pts/"),
97 Bool.or(String.eq(path, "/dev/console"), String.starts_with(path, "/dev/tty")))
98
99def tty.out(on: Bool, +out: String) -> String:
100 match on:
101 case True{}:
102 out
103 case False{}:
104 ""
105
106
107def tty.pick.go(on: Bool, +err: String, +out: String) -> String:
108 match on:
109 case True{}:
110 err
111 case False{}:
112 tty.out(tty.at(out), out)
113
114def tty.pick(+err: String, +out: String) -> String:
115 tty.pick.go(tty.at(err), err, out)
116
117
118
119def hub.miss(+why: String) -> Bool:
120 Bool.and(String.contains(why, "/manifest:"),
121 String.ends_with(why, "the server answered 404"))
122
123def hub.explain.go(miss: Bool, +hash: String, +url: String, +why: String) -> String:
124 match miss:
125 case True{}:
126 "ez: " ++ hash ++ ": the hub has no manifest for this package (" ++ url ++
127 " answered 404). Re-lock with `ez lock`, fix the dependency, or vendor it offline (`ez add`)."
128 case False{}:
129 "ez: " ++ why
130
131def hub.explain(+hash: String, +url: String, +why: String) -> String:
132 hub.explain.go(hub.miss(why), hash, url, why)
133
134
135def drift.where(bare: Bool, +tag: String, +rev: String) -> String:
136 match bare:
137 case True{}:
138 "commit " ++ rev
139 case False{}:
140 "tagged commit " ++ tag ++ " (" ++ rev ++ ")"
141
142
143
144
145def drift(+name: String, +tag: String, +rev: String, +old: String, +new: String) -> String:
146 "ez: " ++ name ++ ": the tree hash of " ++
147 drift.where(String.is_empty(tag), tag, rev) ++
148 " no longer matches the pin (the package moved, or the hash is wrong: " ++
149 old ++ " on the pin, " ++ new ++
150 " in the tree). `ez lock --upgrade` cannot fix a drifted pin. Update the dependency hash, re-add the package, or check the tag."
151
152
153def stuck(+name: String) -> String:
154 "ez: " ++ name ++
155 ": the pin drifted. `ez lock --upgrade` cannot fix a drifted pin. Update the dependency hash, re-add the package, or check the tag."
156
157
158
159def has.tools(+text: String) -> Bool:
160 String.contains(text, "[tools.")
161
162
163
164def hint(tools: Bool) -> String:
165 match tools:
166 case True{}:
167 "hint: `sync` is not a command; use `ez tool sync`"
168 case False{}:
169 "hint: `sync` is not a command. Use `ez lock` to resolve dependencies, or `ez tool install <target>` to link a binary."
170
171
172
173def probe() -> String:
174 "ppid=; while read -r k v; do case $k in PPid:) ppid=$v;; esac; done < /proc/self/status; readlink /proc/$ppid/fd/$1 2>/dev/null"
175
176
177
178
179def frames() -> String:
180 "ppid=; while read -r k v; do case $k in PPid:) ppid=$v;; esac; done < /proc/self/status; [ -n \"$ppid\" ] || exit 0; while [ -d /proc/$ppid ]; do printf '\\r%s %s' '⠋' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠙' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠹' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠸' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠼' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠴' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠦' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠧' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠇' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠏' \"$2\" >\"$1\"; sleep 0.08; done"
181
182
183def settle() -> String:
184 "printf '\\r\\033[K%s\\n' \"$2\" >\"$1\""