-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fb61c1
commit 1aa2c5e
Showing
4 changed files
with
109 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TaskManager } from '@jujulego/tasks'; | ||
import { Box, Text } from 'ink'; | ||
|
||
import { useFlatTaskTree } from '@/src/ui/hooks/useFlatTaskTree.ts'; | ||
import TaskSpinner from '@/src/ui/task-spinner.tsx'; | ||
import TaskTreeStats from '@/src/ui/task-tree-stats.tsx'; | ||
|
||
// Types | ||
export interface TaskTreeFullSpinnerProps { | ||
readonly manager: TaskManager; | ||
} | ||
|
||
// Component | ||
export default function TaskTreeFullSpinner({ manager }: TaskTreeFullSpinnerProps) { | ||
const flat = useFlatTaskTree(manager); | ||
|
||
// Render | ||
return ( | ||
<> | ||
<Box flexDirection="column"> | ||
{ flat.map(({ task, level }) => ( | ||
<Box key={task.id} marginLeft={level * 2} flexShrink={0}> | ||
<TaskSpinner task={task} /> | ||
</Box> | ||
)) } | ||
</Box> | ||
<Text> | ||
<TaskTreeStats manager={manager} /> | ||
</Text> | ||
</> | ||
); | ||
} |
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,65 @@ | ||
import { TaskManager } from '@jujulego/tasks'; | ||
import { Box, Text, useInput } from 'ink'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
|
||
import { useStdoutDimensions } from '@/src/ui/hooks/useStdoutDimensions.ts'; | ||
import { useFlatTaskTree } from '@/src/ui/hooks/useFlatTaskTree.ts'; | ||
import TaskSpinner from '@/src/ui/task-spinner.tsx'; | ||
import TaskTreeStats from '@/src/ui/task-tree-stats.tsx'; | ||
|
||
// Types | ||
export interface TaskTreeScrollableSpinnerProps { | ||
readonly manager: TaskManager; | ||
} | ||
|
||
// Component | ||
export default function TaskTreeScrollableSpinner({ manager }: TaskTreeScrollableSpinnerProps) { | ||
const { rows: termHeight } = useStdoutDimensions(); | ||
|
||
// Extract all tasks | ||
const flat = useFlatTaskTree(manager); | ||
|
||
const maxHeight = useMemo( | ||
() => Math.min(termHeight - 4, flat.length), | ||
[termHeight, flat] | ||
); | ||
|
||
// Manage scroll | ||
const [start, setStart] = useState(0); | ||
|
||
const slice = useMemo( | ||
() => flat.slice(start, start + maxHeight), | ||
[flat, start, maxHeight] | ||
); | ||
|
||
useEffect(() => { | ||
if (start + maxHeight > flat.length) { | ||
setStart(Math.max(flat.length - maxHeight, 0)); | ||
} | ||
}, [start, flat, maxHeight]); | ||
|
||
useInput((_, key) => { | ||
if (key.upArrow) { | ||
setStart((old) => Math.max(0, old - 1)); | ||
} else if (key.downArrow) { | ||
setStart((old) => Math.min(flat.length - maxHeight, old + 1)); | ||
} | ||
}); | ||
|
||
// Render | ||
return ( | ||
<> | ||
<Box flexDirection="column"> | ||
{ slice.map(({ task, level }) => ( | ||
<Box key={task.id} marginLeft={level * 2} flexShrink={0}> | ||
<TaskSpinner task={task} /> | ||
</Box> | ||
)) } | ||
</Box> | ||
<Text> | ||
<TaskTreeStats manager={manager} /> | ||
{ (maxHeight < flat.length) && (<Text color="grey"> - use keyboard arrows to scroll</Text>) } | ||
</Text> | ||
</> | ||
); | ||
} |
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