-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add history scrolling when runner closes
* fix: add history settings * fix: history model * fix: persist loop in workspace and confirm all flows go through finish * fix: history execution save on command completion * fix: update constant tests for new history constants * fix: history scroll * fix: make sure history can not exceed max
- Loading branch information
1 parent
9491744
commit dc6647f
Showing
8 changed files
with
230 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { pathExists, readJSON, writeFile } from 'fs-extra' | ||
import { Command } from './runtime' | ||
|
||
export interface HistoricalExecution { | ||
prompt: string | ||
result?: string[] | ||
error: boolean | ||
aborted: boolean | ||
profile: string | ||
when: { | ||
start: number | ||
finish: number | ||
} | ||
code: number | ||
} | ||
|
||
// so why save two seperate histories? | ||
// new execution is the history that is still pending writing | ||
// this gives us the ability to easily scroll without exposing all the data to the front all at once | ||
export class History { | ||
public priorExecution: HistoricalExecution[] = [] | ||
public newExecution: HistoricalExecution[] = [] | ||
public scrollIndex: number = 0 | ||
constructor(public location: string) {} | ||
|
||
async load(): Promise<void> { | ||
const isExist = await pathExists(this.location) | ||
if (!isExist) { | ||
const prettyJSON = JSON.stringify([], null, 2) | ||
|
||
await writeFile(this.location, prettyJSON, 'utf-8') | ||
} else { | ||
this.priorExecution = await readJSON(this.location) | ||
} | ||
} | ||
append(command: Command, start: number, profile: string, saveResult: boolean): void { | ||
this.newExecution.push({ | ||
prompt: command.prompt, | ||
aborted: command.aborted, | ||
result: saveResult ? command.result.stream.map((o) => o.raw) : undefined, | ||
error: command.error, | ||
profile, | ||
when: { | ||
start, | ||
finish: Date.now() | ||
}, | ||
code: command.result.code | ||
}) | ||
} | ||
|
||
async write(max: number): Promise<void> { | ||
const history: Array<HistoricalExecution> = [...this.priorExecution, ...this.newExecution] | ||
|
||
history.sort((historyA, historyB) => historyA.when.start - historyB.when.start) | ||
|
||
const historyFinalList = | ||
max < history.length ? history.slice(history.length - max, history.length) : history | ||
|
||
await writeFile(this.location, JSON.stringify(historyFinalList, null, 2)) | ||
} | ||
|
||
rewind(): HistoricalExecution | undefined { | ||
if (this.scrollIndex >= this.priorExecution.length) { | ||
return | ||
} | ||
const historicalItem = this.priorExecution[this.priorExecution.length - 1 - this.scrollIndex] | ||
|
||
this.scrollIndex++ | ||
|
||
return historicalItem | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.