-
Notifications
You must be signed in to change notification settings - Fork 147
Add render demo to landing page #1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ling0x
wants to merge
14
commits into
ratatui:main
Choose a base branch
from
ling0x:ling/landing-page-enhancement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4fc1a29
chore: npm run format
ling0x b7acf3c
feat: install tachyonfx-renderer
ling0x 0af5b42
refactor: change fire effect color
ling0x 627b60d
refactor: adjust aspect ratio of showcase card to avoid clipping the …
ling0x 1cf148b
refactor: add label to code example showcase
ling0x fa732dc
refactor: tackle flash of unstyled content
ling0x e66c050
chore: npm run format
ling0x d9a6b9c
refactor: create script and npm command to generate ansi code example…
ling0x 902fd6e
refactor: tachyonfx animation
ling0x 52fbee9
refactor: padding adjustment
ling0x 054ab29
refactor: code effect change and error handling for WebGL context
ling0x 94bcf94
refactor: update tachyonfx renderer version and simplify effect code
ling0x 0ca1131
chore: formatting
ling0x fe44f7e
chore: formatting
ling0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,35 @@ | ||
| const pink = `\x1b[38;2;199;146;234m`; | ||
| const green = `\x1b[38;2;173;219;103m`; | ||
| const blue = `\x1b[38;2;130;170;255m`; | ||
| const white = `\x1b[38;2;214;222;235m`; | ||
| const cyan = `\x1b[38;2;127;219;202m`; | ||
| const indent = `\x1b[48;2;1;22;39m \x1b[0m`; | ||
| const blankLine = `\x1b[48;2;1;22;39m \x1b[0m`; | ||
|
|
||
| export const CODE_EXAMPLE = `${blankLine} | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${pink}use\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}ratatui\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}style\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}Stylize\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${pink}use\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}ratatui\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}widgets\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}{\x1b[0m\x1b[48;2;1;22;39m${white}Block\x1b[0m\x1b[48;2;1;22;39m${white},\x1b[0m\x1b[48;2;1;22;39m${white} Paragraph\x1b[0m\x1b[48;2;1;22;39m${white}}\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${pink}fn\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${blue}main\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${cyan}->\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${green}Result\x1b[0m\x1b[48;2;1;22;39m${white}<\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white}, \x1b[0m\x1b[48;2;1;22;39m${green}Box\x1b[0m\x1b[48;2;1;22;39m${white}<\x1b[0m\x1b[48;2;1;22;39m${pink}dyn \x1b[0m\x1b[48;2;1;22;39m${green}std\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${green}error\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}Error\x1b[0m\x1b[48;2;1;22;39m${white}>\x1b[0m\x1b[48;2;1;22;39m${white}>\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}{ \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}ratatui\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${blue}run\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${pink}|\x1b[0m\x1b[48;2;1;22;39m${green}terminal\x1b[0m\x1b[48;2;1;22;39m${pink}|\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}{ \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${green} terminal\x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}draw\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${pink}|\x1b[0m\x1b[48;2;1;22;39m${green}frame\x1b[0m\x1b[48;2;1;22;39m${pink}|\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}{ \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${pink}let\x1b[0m\x1b[48;2;1;22;39m${green} block \x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;127;219;202m=\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}Block\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${blue}bordered\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}title\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;217;245;221m"\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;236;196;141mWelcome\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;217;245;221m"\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${pink}let\x1b[0m\x1b[48;2;1;22;39m${green} greeting \x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;127;219;202m=\x1b[0m\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}Paragraph\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${blue}new\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;217;245;221m"\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;236;196;141mHello, Ratatui! 🐭\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;217;245;221m"\x1b[0m\x1b[48;2;1;22;39m${white}) \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}centered\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white}) \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}yellow\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white}) \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}block\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${green}block\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${green} frame\x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}render_widget\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${green}greeting\x1b[0m\x1b[48;2;1;22;39m${white},\x1b[0m\x1b[48;2;1;22;39m${green} frame\x1b[0m\x1b[48;2;1;22;39m${pink}.\x1b[0m\x1b[48;2;1;22;39m${blue}area\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}}\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;127;219;202m?\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}std\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}thread\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${blue}sleep\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white}std\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}time\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${white}Duration\x1b[0m\x1b[48;2;1;22;39m${pink}::\x1b[0m\x1b[48;2;1;22;39m${blue}from_secs\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;247;140;108m5\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white}; \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m\x1b[38;2;173;219;103mOk\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white}(\x1b[0m\x1b[48;2;1;22;39m${white})\x1b[0m\x1b[48;2;1;22;39m${white}) \x1b[0m | ||
| ${blankLine} | ||
| ${indent}\x1b[48;2;1;22;39m${white} \x1b[0m\x1b[48;2;1;22;39m${white}}\x1b[0m\x1b[48;2;1;22;39m${white}) \x1b[0m | ||
| ${indent}\x1b[48;2;1;22;39m${white}} \x1b[0m | ||
| ${blankLine}`; |
This file contains hidden or 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,84 @@ | ||
| --- | ||
| // TachyonFX Code Animation | ||
|
|
||
| import { readFile } from "fs/promises"; | ||
| import RatatuiVersion from "./RatatuiVersion.astro"; | ||
| import CopyButton from "./CopyButton.astro"; | ||
| import CodeExampleLabel from "./CodeExampleLabel.astro"; | ||
|
|
||
| // Read file at build time | ||
| const code = await readFile("./code/tutorials/quickstart-ratatui/src/main.rs", "utf-8"); | ||
| --- | ||
|
|
||
| <div class="relative max-sm:hidden"> | ||
| <RatatuiVersion /> | ||
| <CopyButton code={code} class="absolute top-0 right-0" /> | ||
| <div id="tachyon-canvas" class="bg-[#011627]"></div> | ||
| <CodeExampleLabel /> | ||
| </div> | ||
|
|
||
| <script> | ||
| import init, { createRenderer, RendererConfig } from "tachyonfx-renderer"; | ||
| import wasmUrl from "tachyonfx-renderer/tachyonfx_renderer_bg.wasm?url"; | ||
| import { CODE_EXAMPLE } from "../assets/code-example-ansi.ts"; | ||
|
|
||
| const FIRE_EFFECT = `let content_area = Rect::new(0, 0, 80, 27); | ||
ling0x marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let screen_bg = Color::from_u32(0x020617); | ||
| let content_bg = Color::from_u32(0x1E293B); | ||
|
|
||
| let style = Style::default() | ||
| .fg(content_bg) | ||
| .bg(screen_bg); | ||
|
|
||
| let boot_timer = (300, Interpolation::CircIn); | ||
| let timer = (900, QuadIn); | ||
|
|
||
| let startup = fx::evolve((EvolveSymbolSet::Shaded, style), boot_timer) | ||
| .with_pattern(RadialPattern::with_transition((0.5, 0.5), 10.0)) | ||
| .with_area(content_area); | ||
|
|
||
| // the effect runs reversed() so that the symbols appear | ||
| // to flicker out; since it's reversed, the applied pattern | ||
| // is the same as DissolvePattern if the effect wasn't reversed | ||
| let inner_fire_fx = fx::evolve_from((EvolveSymbolSet::Quadrants, style), timer) | ||
| .with_pattern(CoalescePattern::new()) | ||
| .with_area(content_area) | ||
| .reversed(); | ||
|
|
||
| // moving the rendered area upwards to mimic of fire | ||
| let fire = fx::translate(inner_fire_fx, Offset { x: 0, y: -22 }, timer) | ||
| .with_area(content_area); | ||
|
|
||
| let fade_in_text = fade_from(screen_bg, screen_bg, timer) | ||
| .with_filter(CellFilter::Text) | ||
| .with_area(content_area) | ||
| .with_pattern(CoalescePattern::new()); | ||
|
|
||
|
|
||
| fx::prolong_start(300, fx::sequence(&[ | ||
| startup, | ||
| fx::parallel(&[ | ||
| fx::fade_from(screen_bg, screen_bg, 300), | ||
| fire, | ||
| fade_in_text, | ||
| ]) | ||
| ])) | ||
| `; | ||
|
|
||
| async function initTachyon() { | ||
| try { | ||
| await init(wasmUrl); | ||
|
|
||
| const config = new RendererConfig("tachyon-canvas") | ||
| .withDsl(FIRE_EFFECT) | ||
| .withCanvas(CODE_EXAMPLE); | ||
|
|
||
| const renderer = createRenderer(config); | ||
| document.getElementById("code-label")?.classList.remove("opacity-0"); | ||
| } catch (error) { | ||
| console.error("Error:", error); | ||
| } | ||
| } | ||
|
|
||
| initTachyon(); | ||
| </script> | ||
This file contains hidden or 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,24 @@ | ||
| --- | ||
| // Footer label for landing page code sample | ||
| --- | ||
|
|
||
| <div | ||
| class="absolute right-3 bottom-3 text-sm text-slate-500 opacity-0 transition-opacity" | ||
| id="code-label" | ||
| > | ||
| (Powered by{" "} | ||
ling0x marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <a | ||
| class="bg-slate-950 px-1 text-slate-300 hover:bg-slate-800" | ||
| href="https://github.com/orhun/ratzilla" | ||
| target="_blank">Ratzilla</a | ||
| > | ||
| {" "} | ||
| with{" "} | ||
| <a | ||
| class="bg-slate-950 px-1 text-slate-300 hover:bg-slate-800" | ||
| href="https://github.com/webassembly" | ||
| target="_blank" | ||
| > | ||
| WebAssembly</a | ||
| >) | ||
| </div> | ||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.