eyeprolog 1.6.23 → 1.6.24

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
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.23",
6
+ "version": "1.6.24",
7
7
  "description": "EyeProlog turns facts and rules into answers and proofs.",
8
8
  "type": "module",
9
9
  "main": "./index.js",
package/src/repl.js CHANGED
@@ -146,7 +146,18 @@ class LineReader {
146
146
  async read(prompt) {
147
147
  this.currentPrompt = prompt;
148
148
  this.readline.setPrompt(prompt);
149
- this.output.write(prompt);
149
+ // On a terminal, let readline render the prompt rather than writing it
150
+ // here. setPrompt tells readline how wide the prompt is, but only
151
+ // prompt() makes readline the thing that drew it; writing the same
152
+ // characters directly leaves readline redrawing the line from a column it
153
+ // does not believe the prompt occupies. The cursor can then travel back
154
+ // over the prompt, and a refresh can paint the line where the prompt
155
+ // already is.
156
+ //
157
+ // Without a terminal there is no line editor to own the prompt, and it
158
+ // still has to reach the transcript, so there it is written directly.
159
+ if (this.terminal) this.readline.prompt();
160
+ else this.output.write(prompt);
150
161
  const result = await this.nextLine();
151
162
  return result.done ? null : result.value;
152
163
  }
@@ -3832,7 +3832,12 @@ c4 ?- call((!;1)).
3832
3832
  assertEqual(result.status, 0, 'exit status');
3833
3833
  assertIncludes(result.stdout, 'X = foo, Y = bar.', 'conjunction reads');
3834
3834
  assertIncludes(result.stdout, 'Z = end_of_file.', 'Ctrl-D read result');
3835
- assertIncludes(result.stdout, '?- true.', 'top level resumes after Ctrl-D');
3835
+ // On a terminal readline owns the prompt, so it redraws the line with
3836
+ // cursor-positioning escapes between the prompt and the echoed query.
3837
+ // This assertion is about the top level resuming, not about which
3838
+ // control sequences the line editor uses to place the cursor.
3839
+ const plain = result.stdout.replaceAll(/\u001b\[[0-9;]*[A-Za-z]/g, '');
3840
+ assertIncludes(plain, '?- true.', 'top level resumes after Ctrl-D');
3836
3841
  assertIncludes(result.stdout, ' true.', 'post-EOF query executes');
3837
3842
  },
3838
3843
  },
@@ -3892,7 +3897,13 @@ c4 ?- call((!;1)).
3892
3897
  ]);
3893
3898
  assertEqual(result.error?.code, undefined, 'terminal interrupt timeout');
3894
3899
  assertEqual(result.status, 130, 'SIGINT exit status');
3895
- assertIncludes(result.stdout, '?- put_code(82), put_code(69), put_code(65), put_code(68), put_code(89), repeat, fail.', 'terminal query echo');
3900
+ // Readline owns the prompt on a terminal and places the cursor with
3901
+ // escapes; the echo is what matters here, not how it was drawn.
3902
+ assertIncludes(
3903
+ result.stdout.replaceAll(/\u001b\[[0-9;]*[A-Za-z]/g, ''),
3904
+ '?- put_code(82), put_code(69), put_code(65), put_code(68), put_code(89), repeat, fail.',
3905
+ 'terminal query echo',
3906
+ );
3896
3907
  assertIncludes(result.stdout, 'READY', 'query entered computation');
3897
3908
  },
3898
3909
  },