事件:'history'
【Event: 'history'】
每当历史数组发生变化时,都会触发 'history' 事件。
【The 'history' event is emitted whenever the history array has changed.】
监听器函数会被调用,并传入一个包含历史记录数组的数组。它会反映所有的更改、添加的行以及由于 historySize 和 removeHistoryDuplicates 导致的删除的行。
【The listener function is called with an array containing the history array.
It will reflect all changes, added lines and removed lines due to
historySize and removeHistoryDuplicates.】
主要目的是允许监听器保存历史记录。监听器也可以更改历史对象。这可能有助于防止某些行被添加到历史记录中,例如密码。
【The primary purpose is to allow a listener to persist the history. It is also possible for the listener to change the history object. This could be useful to prevent certain lines to be added to the history, like a password.】
rl.on('history', (history) => {
console.log(`Received: ${history}`);
});