Skip to content

Commit

Permalink
fix: word wrapping with line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuur committed Mar 16, 2023
1 parent bce3301 commit 2359da1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"commander": "^10.0.0",
"conf": "^11.0.1",
"dotenv": "^16.0.3",
"fast-word-wrap": "^1.0.1",
"jsonfile": "^6.1.0",
"md5": "^2.3.0",
"minimist": "^1.2.8",
Expand All @@ -27,7 +26,8 @@
"pretty-ms": "^8.0.0",
"term-size": "^3.0.2",
"update-notifier": "^6.0.2",
"wordcount": "^1.1.1"
"wordcount": "^1.1.1",
"wrap-text": "^1.0.9"
},
"publishConfig": {
"access": "public"
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/loop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import readline from 'readline';

import wrap from 'fast-word-wrap';
import clipboard from 'node-clipboardy';
import pc from 'picocolors';
import prettyMilliseconds from 'pretty-ms';
Expand All @@ -11,7 +10,7 @@ import { conf, packageJson, settings } from './settings.js';
import { commandList, COMMAND_PREFIX, exitCmd, runCommand } from './commands.js';
import { askChatGPT, conversation } from './openai.js';
import { formatUsage } from './usage.js';
import { clearLine, errorMsg } from './utils.js';
import { clearLine, errorMsg, wrap } from './utils.js';

const promptText = pc.green('You: ');

Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import readline from 'readline';
import wrapText from 'wrap-text';

import pc from 'picocolors';

Expand All @@ -11,3 +12,9 @@ export function errorMsg(str) {
clearLine();
console.error(`${pc.red('Error')}: ${str}`);
}

export const wrap = (str, width) =>
str
.split('\n')
.map((line) => wrapText(line, width))
.join('\n');

0 comments on commit 2359da1

Please sign in to comment.