From aae4a5de7a93089dc0670caf32d5130176be09fe Mon Sep 17 00:00:00 2001 From: Offirmo Date: Sat, 28 Sep 2024 20:32:57 +1000 Subject: [PATCH] +++ --- .../active/view--chat--terminal/doc/demo.js | 9 +++--- .../active/view--chat--terminal/package.json | 3 +- .../active/view--chat--terminal/src/index.js | 30 +++++++++---------- .../active/view--chat--terminal/src/libs.js | 14 ++++++--- .../active/view--chat/src/index.js | 2 +- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/stack--current/5-incubator/active/view--chat--terminal/doc/demo.js b/stack--current/5-incubator/active/view--chat--terminal/doc/demo.js index bb9eeb99..966a23cd 100755 --- a/stack--current/5-incubator/active/view--chat--terminal/doc/demo.js +++ b/stack--current/5-incubator/active/view--chat--terminal/doc/demo.js @@ -1,14 +1,13 @@ -import to_prettified_str from '@offirmo-private/prettify-any' - import { create as create_chat } from '@offirmo-private/view--chat' -import { create as create_tty_chat_ui } from '../src' +import { create as create_tty_chat_ui } from '../src/index.js' +import { to_prettified_str } from '../src/libs.js' -import { get_next_step1 } from '../../view--chat/doc/demo' +import { get_next_step1 } from '../../view--chat/doc/demo.js' ///////////////////////////////////////////////// -const DEBUG = false +const DEBUG = true const no_ui = { setup: async () => {}, diff --git a/stack--current/5-incubator/active/view--chat--terminal/package.json b/stack--current/5-incubator/active/view--chat--terminal/package.json index 672c8c70..c14767f8 100644 --- a/stack--current/5-incubator/active/view--chat--terminal/package.json +++ b/stack--current/5-incubator/active/view--chat--terminal/package.json @@ -24,7 +24,8 @@ "ora": "^8", "p-progress": "^1", "strip-ansi": "^7", - "term-size": "^4" + "term-size": "^4", + "indent-string": "^5" }, "scripts": { diff --git a/stack--current/5-incubator/active/view--chat--terminal/src/index.js b/stack--current/5-incubator/active/view--chat--terminal/src/index.js index f0c1e344..c2741ec3 100644 --- a/stack--current/5-incubator/active/view--chat--terminal/src/index.js +++ b/stack--current/5-incubator/active/view--chat--terminal/src/index.js @@ -1,11 +1,11 @@ import readline from 'node:readline' -const term_size = require('term-size') -const strip_ansi = require('strip-ansi') -const create_ora_spinner = require('ora') -const Gauge = require('gauge') +import term_size from 'term-size' +import strip_ansi from 'strip-ansi' +import create_ora_spinner from 'ora' +import Gauge from 'gauge' -const { to_prettified_str, stylize_string, indent_string, wrap_string } = require('./libs') -import { get_shared_start } from './utils' +import { to_prettified_str, stylize_string, indent_string, wrap_string } from './libs.js' +import { get_shared_start } from './utils.js' const MANY_BOX_HORIZ = '────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────' @@ -332,16 +332,16 @@ function create({DEBUG, shouldCenter}) { function read_string(step) { if (DEBUG) console.log(`↘ read_string(\n${to_prettified_str(step, { outline: true })}\n)`) return new Promise(resolve => { - //rli.clearLine(process.stdout, 0) - rli.prompt() - - rli.question('', answer => { - rli.clearLine(process.stdout, 0) - answer = String(answer).trim() - if (DEBUG) console.log(`[You entered: "${answer}"]`) - resolve(answer) + //rli.clearLine(process.stdout, 0) + rli.prompt() + + rli.question('', answer => { + rli.clearLine(process.stdout, 0) + answer = String(answer).trim() + if (DEBUG) console.log(`[You entered: "${answer}"]`) + resolve(answer) + }) }) - }) .then(answer => { if (step.msgg_as_user) return display_message({ diff --git a/stack--current/5-incubator/active/view--chat--terminal/src/libs.js b/stack--current/5-incubator/active/view--chat--terminal/src/libs.js index cedacba8..e5c954f5 100644 --- a/stack--current/5-incubator/active/view--chat--terminal/src/libs.js +++ b/stack--current/5-incubator/active/view--chat--terminal/src/libs.js @@ -1,18 +1,24 @@ -const to_prettified_str = require('@offirmo-private/prettify-any') +import { + injectꓽlibꓽchalk, + prettifyꓽany as to_prettified_str, +} from '@offirmo-private/prettify-any' -const stylize_string = require('chalk') +import indent_string from 'indent-string' +import stylize_string from 'chalk' +injectꓽlibꓽchalk(stylize_string) // https://github.com/AnAppAMonth/linewrap -const linewrap = require('linewrap') +import linewrap from 'linewrap' function wrap_string(s, size) { return linewrap(size, {skipScheme: 'ansi-color'})(s) } //////////// -module.exports = { +export { to_prettified_str, stylize_string, + indent_string, wrap_string, } diff --git a/stack--current/5-incubator/active/view--chat/src/index.js b/stack--current/5-incubator/active/view--chat/src/index.js index 473a9113..68c11d17 100644 --- a/stack--current/5-incubator/active/view--chat/src/index.js +++ b/stack--current/5-incubator/active/view--chat/src/index.js @@ -1,4 +1,4 @@ -import PromiseWithProgress from 'p-progress' +import { PProgress as PromiseWithProgress } from 'p-progress' import is_promise from 'is-promise' /////////////////////////////////////////////////