-
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.
Improve path display. Bump to v0.1.1
Fix format on Windows.
- Loading branch information
1 parent
ad30788
commit f44f414
Showing
5 changed files
with
55 additions
and
10 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 |
---|---|---|
@@ -1,13 +1,32 @@ | ||
import { platform } from "@tauri-apps/api/os"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
|
||
export function PathHighlight({ path }: { path: string }) { | ||
const [platformName, setPlatformName] = useState<string>(); | ||
const separator = useMemo( | ||
() => (platformName === "win32" ? "\\" : "/"), | ||
[platformName] | ||
); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const p = await platform(); | ||
setPlatformName(p); | ||
})(); | ||
}, []); | ||
function getFileName(p: string) { | ||
return p.split("/").pop(); | ||
return p.split(separator).pop(); | ||
} | ||
function getDirName(p: string) { | ||
return p.split("/").slice(0, -1).join("/"); | ||
return p.split(separator).slice(0, -1).join(separator); | ||
} | ||
return ( | ||
<pre> | ||
{getDirName(path)}/<span className=" text-red-500 dark:text-green-400">{getFileName(path)}</span> | ||
{getDirName(path)} | ||
{separator} | ||
<span className=" text-red-500 dark:text-green-400"> | ||
{getFileName(path)} | ||
</span> | ||
</pre> | ||
); | ||
} |
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