Skip to content
This repository has been archived by the owner on Nov 25, 2023. It is now read-only.

Commit

Permalink
fix filetree display, add pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jul 29, 2021
1 parent d091163 commit 9cba7a9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
33 changes: 16 additions & 17 deletions components/FileTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Box, Spacer, Text} from 'ink'
import prettyBytes from 'pretty-bytes'
import {ITreeRepresentation} from '../domain/registry'
import {STATUS} from '../domain/trie'
import useStdoutDimensions from "ink-use-stdout-dimensions";

interface IStatusIndicatorProps {
status: STATUS;
Expand Down Expand Up @@ -33,9 +34,9 @@ const Legend = () => (
</Box>
)

const isFileQueued = (file: ITreeRepresentation) => file.stats.numTransfers <= 1 && !file.stats.hasEnded
const isFileQueued = (file: ITreeRepresentation) => file.stats.numTransfers === 0 && !file.stats.hasEnded

const fmtPercentage = (number: number) => `${(number * 100).toFixed(2)}%`
const fmtPercentage = (number: number) => `${(number * 100).toFixed(1)}%`

interface IFileTreeProps {
registry: ITreeRepresentation[];
Expand All @@ -58,30 +59,28 @@ const FullTreeFile = ({file}: {file: ITreeRepresentation}) => (
)

const TruncatedTreeFile = ({file}: {file: ITreeRepresentation}) => (
<Box>
<Box width="100%" paddingLeft={file.padding}>
<Box width="80%">
<Text
color={file.isDir ? 'cyan' : 'white'}
dimColor={isFileQueued(file)}
wrap="truncate"
>
{file.name}
</Text>
</Box>
<Spacer/>
<Text>{file.isDir ? '' : `${fmtPercentage(file.stats.totalTransferred / file.size)} of ${prettyBytes(file.size)}`}</Text>
<Box width="100%" paddingLeft={file.padding}>
<Box width="80%">
<Text
color={file.isDir ? 'cyan' : 'white'}
dimColor={isFileQueued(file)}
wrap="truncate"
>
{file.name}
</Text>
</Box>
<Spacer/>
<Text>{file.isDir ? '' : `${fmtPercentage(file.stats.totalTransferred / file.size)} of ${prettyBytes(file.size)}`}</Text>
</Box>
)

// File tree display component
const DISPLAY_NUM = 25
const FileTree = ({registry, full}: IFileTreeProps) => {
const DISPLAY_NUM = Math.max(useStdoutDimensions()[1] - 12, 1);
const emptyMessage = full
? <Text color="yellow">No files found</Text>
: <Text bold color="green">All files synced</Text>
const files = full ? registry : registry.filter(file => file.status !== STATUS.synced).sort((a, b) => b.size - a.size)
const files = full ? registry : registry.filter(file => file.status !== STATUS.synced).sort((a, b) => isFileQueued(a) ? 1 : b.size - a.size)
return (
<Box flexDirection="column" marginY={1}>
<Text bold color="blue">Files</Text>
Expand Down
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"dev": "pastel dev",
"prepare": "husky install && pastel build",
"test": "xo && ava",
"lint": "xo --fix"
"lint": "xo --fix",
"pkg": "pkg package.json -o dist/cli"
},
"files": [
"build"
Expand All @@ -39,6 +40,7 @@
"ink": "^3.0.8",
"ink-select-input": "^4.2.0",
"ink-spinner": "^4.0.2",
"ink-use-stdout-dimensions": "^1.0.5",
"nanoid": "^3.1.23",
"p-queue": "^6.6.2",
"parse-gitignore": "^1.0.1",
Expand Down Expand Up @@ -111,5 +113,19 @@
"nodeArguments": [
"--loader=ts-node/esm/transpile-only"
]
},
"pkg": {
"assets": [
"./node_modules/opn/xdg-open",
"./node_modules/utp-native/prebuilds/**",
"./node_modules/sodium-native/prebuilds/**",
"./node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js",
"build/**"
],
"targets": [
"node14-linux-x64",
"node14-macos-x64",
"node14-win-x64"
]
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5510,6 +5510,11 @@ ink-spinner@^4.0.2:
dependencies:
cli-spinners "^2.3.0"

ink-use-stdout-dimensions@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/ink-use-stdout-dimensions/-/ink-use-stdout-dimensions-1.0.5.tgz#7739876c00284840601c4150aa84eb7adc143de2"
integrity sha512-rVsqnw4tQEAJUoknU09+zHdDf30GJdkumkHr0iz/TOYMYEZJkYqziQSGJAM+Z+M603EDfO89+Nxyn/Ko2Zknfw==

ink@^3.0.8:
version "3.0.9"
resolved "https://registry.yarnpkg.com/ink/-/ink-3.0.9.tgz#57950c7ffe02cb1b2b1537465f6b8d26f7728957"
Expand Down

0 comments on commit 9cba7a9

Please sign in to comment.