perf: hoist keyMap constant, dedup selection toggles, split stdinHandler
- Move keyMap to module-level KEY_MAP constant (was recreated per keystroke) - Extract toggleRowSelection() to replace 4x duplicated toggle logic - Extract refreshMockSessions() to deduplicate demo setup in index.ts - Split stdinHandler into processGridInput/processPickerInput - Extract collapseProject helper from nested left/right key handling - Add shared syntheticKey() and clearChildren() helpers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
33
src/index.ts
33
src/index.ts
@@ -10,6 +10,7 @@ import { loadGitMetadata } from "./data/git"
|
||||
import { loadSessions } from "./data/sessions"
|
||||
import { generateMockProjects, generateMockSessions, generateMockBusySessions } from "./data/mock"
|
||||
import { detectActiveSessions, updateProjectSessions, generateMockActiveSessions, checkTransitions, snapshotBusy, playDoneSound, bounceDock, getSessionStatus, populateMockSessionStatus } from "./data/monitor"
|
||||
import type { Project } from "./lib/types"
|
||||
import { getUsageSummary } from "./data/usage"
|
||||
import { getSessions, refreshAlive } from "./pty/session-manager"
|
||||
import { stopAllCaptures } from "./pty/capture"
|
||||
@@ -19,6 +20,18 @@ import { updateAll, rebuildDisplayRows, updateUsagePanel, updateColumnHeaders }
|
||||
import { stdinHandler } from "./input/handlers"
|
||||
import { resizeGridPanes } from "./grid/view-switch"
|
||||
|
||||
function refreshMockSessions(projects: Project[]) {
|
||||
generateMockActiveSessions(projects)
|
||||
generateMockBusySessions(projects)
|
||||
for (const p of projects) {
|
||||
if (p.activeSessions > 0 && !p.sessions) {
|
||||
p.sessions = generateMockSessions(p.path)
|
||||
p.sessionCount = p.sessions.length
|
||||
}
|
||||
populateMockSessionStatus(p)
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
process.stdout.write("\x1b[2J\x1b[H")
|
||||
process.stdout.write("\x1b[1m cladm\x1b[0m\n")
|
||||
@@ -165,15 +178,7 @@ async function main() {
|
||||
|
||||
// Live session monitoring
|
||||
if (app.demoMode) {
|
||||
generateMockActiveSessions(app.projects)
|
||||
generateMockBusySessions(app.projects)
|
||||
for (const p of app.projects) {
|
||||
if (p.activeSessions > 0 && !p.sessions) {
|
||||
p.sessions = generateMockSessions(p.path)
|
||||
p.sessionCount = p.sessions.length
|
||||
}
|
||||
populateMockSessionStatus(p)
|
||||
}
|
||||
refreshMockSessions(app.projects)
|
||||
app.prevBusySnapshot = snapshotBusy(app.projects)
|
||||
updateAll()
|
||||
} else {
|
||||
@@ -197,15 +202,7 @@ async function main() {
|
||||
|
||||
if (app.demoMode) {
|
||||
for (const p of app.projects) { p.activeSessions = 0; p.busySessions = 0 }
|
||||
generateMockActiveSessions(app.projects)
|
||||
generateMockBusySessions(app.projects)
|
||||
for (const p of app.projects) {
|
||||
if (p.activeSessions > 0 && !p.sessions) {
|
||||
p.sessions = generateMockSessions(p.path)
|
||||
p.sessionCount = p.sessions.length
|
||||
}
|
||||
populateMockSessionStatus(p)
|
||||
}
|
||||
refreshMockSessions(app.projects)
|
||||
const transitioned = checkTransitions(app.projects, app.prevBusySnapshot)
|
||||
app.prevBusySnapshot = snapshotBusy(app.projects)
|
||||
if (transitioned.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user