secrez 2.2.0-beta.3 → 2.2.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secrez",
3
- "version": "2.2.0-beta.3",
3
+ "version": "2.2.0-beta.4",
4
4
  "license": "MIT",
5
5
  "nyc": {
6
6
  "include": "src",
@@ -27,6 +27,22 @@ function terminalRows() {
27
27
  return process.stdout.rows || 24;
28
28
  }
29
29
 
30
+ function terminalColumns() {
31
+ return Math.max(2, process.stdout.columns || 80);
32
+ }
33
+
34
+ // The footer is drawn on its own rows, one column short of the edge.
35
+ // A character in the last column wraps, and a wrap on the last row scrolls
36
+ // the viewport, which moves the text above the footer.
37
+ function statusChunks(status, columns) {
38
+ const width = Math.max(1, columns - 1);
39
+ const chunks = [];
40
+ for (let i = 0; i < status.length; i += width) {
41
+ chunks.push(status.slice(i, i + width));
42
+ }
43
+ return chunks.length ? chunks : [""];
44
+ }
45
+
30
46
  function keyAction(key) {
31
47
  if (key.ctrl) {
32
48
  if (key.name === "a") return "first";
@@ -185,17 +201,23 @@ const Editor = {
185
201
 
186
202
  render() {
187
203
  const rows = terminalRows();
188
- const statusRow = Math.max(0, rows - 1);
204
+ const columns = terminalColumns();
205
+ const chunks = statusChunks(EDITOR_STATUS, columns);
206
+ const statusTop = Math.max(0, rows - chunks.length);
189
207
  const { lines, cursorX, cursorY } = this;
190
- this.out.write(
191
- clearViewport() +
192
- lines.join("\n") +
193
- esc.cursorTo(0, statusRow) +
208
+ let out = clearViewport() + lines.join("\n");
209
+ chunks.forEach((chunk, i) => {
210
+ out +=
211
+ esc.cursorTo(0, statusTop + i) +
212
+ esc.eraseLine +
194
213
  "\x1b[2m" +
195
- EDITOR_STATUS +
196
- "\x1b[0m" +
197
- esc.cursorTo(cursorX, cursorY)
198
- );
214
+ chunk +
215
+ "\x1b[0m";
216
+ });
217
+ const cursorRow = Math.min(cursorY, Math.max(0, statusTop - 1));
218
+ const cursorCol = Math.min(cursorX, columns - 1);
219
+ out += esc.cursorTo(cursorCol, cursorRow);
220
+ this.out.write(out);
199
221
  },
200
222
  };
201
223