MCPcopy Create free account
hub / github.com/arctic-cli/interface / getScannerState

Function getScannerState

packages/arctic/src/cli/cmd/tui/ui/spinner.ts:25–104  ·  view source on GitHub ↗
(
  frameIndex: number,
  totalChars: number,
  options: Pick<AdvancedGradientOptions, "direction" | "holdFrames">,
)

Source from the content-addressed store, hash-verified

23}
24
25function getScannerState(
26 frameIndex: number,
27 totalChars: number,
28 options: Pick<AdvancedGradientOptions, "direction" | "holdFrames">,
29): ScannerState {
30 const { direction = "forward", holdFrames = {} } = options
31
32 if (direction === "bidirectional") {
33 const forwardFrames = totalChars
34 const holdEndFrames = holdFrames.end ?? 0
35 const backwardFrames = totalChars - 1
36
37 if (frameIndex < forwardFrames) {
38 // Moving forward
39 return {
40 activePosition: frameIndex,
41 isHolding: false,
42 holdProgress: 0,
43 holdTotal: 0,
44 movementProgress: frameIndex,
45 movementTotal: forwardFrames,
46 isMovingForward: true,
47 }
48 } else if (frameIndex < forwardFrames + holdEndFrames) {
49 // Holding at end
50 return {
51 activePosition: totalChars - 1,
52 isHolding: true,
53 holdProgress: frameIndex - forwardFrames,
54 holdTotal: holdEndFrames,
55 movementProgress: 0,
56 movementTotal: 0,
57 isMovingForward: true,
58 }
59 } else if (frameIndex < forwardFrames + holdEndFrames + backwardFrames) {
60 // Moving backward
61 const backwardIndex = frameIndex - forwardFrames - holdEndFrames
62 return {
63 activePosition: totalChars - 2 - backwardIndex,
64 isHolding: false,
65 holdProgress: 0,
66 holdTotal: 0,
67 movementProgress: backwardIndex,
68 movementTotal: backwardFrames,
69 isMovingForward: false,
70 }
71 } else {
72 // Holding at start
73 return {
74 activePosition: 0,
75 isHolding: true,
76 holdProgress: frameIndex - forwardFrames - holdEndFrames - backwardFrames,
77 holdTotal: holdFrames.start ?? 0,
78 movementProgress: 0,
79 movementTotal: 0,
80 isMovingForward: false,
81 }
82 }

Callers 2

calculateColorIndexFunction · 0.85
createKnightRiderTrailFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected