From f7f9abf9b7f1ccc9107c4dfabd5bf03e1846bde3 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Tue, 3 Dec 2024 00:45:50 +0800 Subject: [PATCH] feat(cli): add exit tips for conn --- cli/src/lib/conn.ts | 3 +++ cli/src/lib/pub.ts | 2 ++ cli/src/utils/exitInfo.ts | 5 +++++ cli/src/utils/logWrapper.ts | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 cli/src/utils/exitInfo.ts diff --git a/cli/src/lib/conn.ts b/cli/src/lib/conn.ts index b60b07cfc..7bc3f1f10 100644 --- a/cli/src/lib/conn.ts +++ b/cli/src/lib/conn.ts @@ -4,6 +4,7 @@ import { parseConnectOptions } from '../utils/parse' import delay from '../utils/delay' import { handleSaveOptions, handleLoadOptions } from '../utils/options' import * as Debug from 'debug' +import { triggerExitInfo } from '../utils/exitInfo' const conn = (options: ConnectOptions) => { const { debug, saveOptions, loadOptions } = options @@ -27,6 +28,7 @@ const conn = (options: ConnectOptions) => { client.on('connect', () => { basicLog.connected() retryTimes = 0 + setTimeout(triggerExitInfo, 1000) }) client.on('error', (err) => { @@ -96,6 +98,7 @@ const benchConn = async (options: BenchConnectOptions) => { if (connectedCount === count) { const end = Date.now() signale.success(`Created ${count} connections in ${(end - start) / 1000}s`) + setTimeout(triggerExitInfo, 1000) } } else { benchLog.reconnected(connectedCount, count, opts.clientId!) diff --git a/cli/src/lib/pub.ts b/cli/src/lib/pub.ts index 1511a18c3..362601e62 100644 --- a/cli/src/lib/pub.ts +++ b/cli/src/lib/pub.ts @@ -15,6 +15,7 @@ import { checkScenarioExists, checkTopicExists, parseConnectOptions, parsePublis import { serializeProtobufToBuffer } from '../utils/protobuf' import { serializeAvroToBuffer } from '../utils/avro' import { loadSimulator } from '../utils/simulate' +import { triggerExitInfo } from '../utils/exitInfo' /** * Processes the outgoing message through two potential stages: @@ -154,6 +155,7 @@ const multiSend = ( client.on('connect', () => { basicLog.enterToPublish() + setTimeout(triggerExitInfo, 1000) retryTimes = 0 isNewConnection && pump(process.stdin, split2(), sender, (err) => { diff --git a/cli/src/utils/exitInfo.ts b/cli/src/utils/exitInfo.ts new file mode 100644 index 000000000..225e67035 --- /dev/null +++ b/cli/src/utils/exitInfo.ts @@ -0,0 +1,5 @@ +import chalk from 'chalk' + +export const triggerExitInfo = () => { + console.log(chalk.dim('- Press Ctrl+C to disconnect and exit')) +} diff --git a/cli/src/utils/logWrapper.ts b/cli/src/utils/logWrapper.ts index a098691e9..c1b9716fb 100644 --- a/cli/src/utils/logWrapper.ts +++ b/cli/src/utils/logWrapper.ts @@ -72,7 +72,7 @@ const basicLog = { }, publishing: () => logWrapper.await('Message publishing...'), published: () => logWrapper.success('Message published'), - enterToPublish: () => logWrapper.success('Connected, press Enter to publish, press Ctrl+C to exit'), + enterToPublish: () => logWrapper.success('Connected, input and press Enter to publish'), error: (err: Error) => logWrapper.fail(err.toString()), close: () => logWrapper.fail('Connection closed'), reconnecting: (retryTimes: number, maxReTryTimes: number) =>