ratatui-org / templates Goto Github PK
View Code? Open in Web Editor NEWTemplates for bootstrapping a Rust TUI application with Ratatui
Home Page: https://ratatui.rs/templates
License: MIT License
Templates for bootstrapping a Rust TUI application with Ratatui
Home Page: https://ratatui.rs/templates
License: MIT License
Hi,
Thanks for providing such a comprehensive template!
I tried to play around with the async counter example, but the text input doesn't work for me.
After some digging I found the issue and there is a quick semi-fix, but a somewhat more annoying issue remains, which also applies to the template and not just the counter example.
The handle_key_events()
function of the Home
Component is never called. This is because the handle_events()
function is overwritten with the handling of the mouse event. Changing the function name to handle_mouse_events()
fixes the issue (with some minor other changes to make the compiler happy).
Typing a lowercase q
in the input field still makes the program quit, even in insert mode. This is because the key presses are passed through the key map and the resulting action is triggered regardless of component state. I think this is a bigger issue, as TUI applications usually quit on q
and often require text input. So I think it's probably best to make the template easily compatible with such applications.
Maybe a possible solution would be to let component cancel actions, or to move the keybinding handling into the component (the keybindings are in the home section of the config, so maybe their logic should also be in the Home component so it can depend on the component state). The handling for the j
,k
,/
,?
keys is already inside the component so they can be handled better. But that raises the question about the case when multiple components need to handle the same key (e.g. two components with text inputs). Maybe full text input should be a first class citizen, that components can trigger, so it's handled outside of components all together?
These ideas are not very thought out and I'm not totally happy with them. I thought I'd first try to get some feedback as you likely have a better overview over how things are and should work.
I'm happy to help with a PR later
When using the "simple" template, "src" folder and files inside are not created
maybe add another template based on russh to build TUI over ssh.
Hello,
After creating a fresh project I am not able to import use tui::text::Line
. It keeps telling me that "there is no Line in text", even though looking at the documentation there is.
It suggests the other widgets that are using Line, but these are not what I'm looking for, I want to use Line::from()
. The following code shows what I'm trying to achieve:
I created a fresh new project, but still have the same issue. It seems that for some reason it is not able to locate the text::Line module.
Do you guys perhaps know why this is happening?(I'm a beginner at rust)
Full Code:
I suspect that this is still a bug as the select can complete on either branch of the select in a non-deterministic fashion. The right way to handle (I think) is to not fail when the sender fails to send. The send failing can indicator that the receiver is closed. See https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.Sender.html
I think there's probably a second bug with this in how cancelations are handled https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.Sender.html#cancel-safety
Originally posted by @joshka in #48 (review)
Can we rename this to ratatui-template
? It'll be consistent with ratatui-async-template
.
I think there's value in having a simple
template with async
for people who are just interested in using async
.
Great template for beginners. However, it panics and the program (terminal) freezes when not focused or when pressing ALT+TAB.
Error:
thread '<unnamed>' panicked at src\event.rs:51:34:
not implemented
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
A keymap that requires holding down "Shift" to generate e.g. "!" or "?" characters will not trigger correctly.
For example, this will fail.
{
"keybindings": {
"StockWatch": {
...
"<?>": "ToggleShowHelp", // Shift-/
"<@>": "DummyAction1", // Shift-1
"<#>": "DummyAction2", // Shift-3
...
},
}
}
But this works:
{
"keybindings": {
"StockWatch": {
...
"<Shift-?>": "ToggleShowHelp",
"<Shift-@>": "DummyAction1",
"<Shift-#>": "DummyAction2",
...
},
}
}
Currently the async template comes up with many dependencies and lot of code. Would be great to keep it minimalist like the simple template
Hi just a small bug, I think you meant to use strip_suffix
for >
, here?
templates/component/template/src/config.rs
Lines 251 to 252 in 966cf2e
I'm trying to see if I one can overwrite the "global" setting of a specific keymap , so that a specific key that's mapped at the config.json can be ignored or changed at the component level based conditionally on the mode
For example, something like this?
{
"keybindings": {
"StockWatch": {
"Insert":{
},
"Default":{
"<q>":"Quit",
"<j>": "ScheduleIncrement",
"<l>": "ToggleShowHelp",
"</>": "EnterInsert",
"<Ctrl-d>": "Quit", // Another way to quit
"<Ctrl-c>": "Quit", // Yet another way to quit
"<Ctrl-z>": "Suspend", // Suspend the application
}
},
}
}
The CI pipeline is failing probably due to the newly added async subtemplate. We need to look into fixing it.
Hi there!
Firstly, this repo is so cool, I wish I knew about it earlier rather than starting from the demo application in the tui-rs repo.
From the README.md it states that app.rs
"holds the states and renders the widgets".
I feel like this is a fine pattern for simple projects but will easily leave app.rs and app struct being overwhelmed.
In the demo application from the ratatui repo they have split this responsibility into 2 files:
I think I found that pattern a bit easier to understand and the code is easier to navigate. In this particular example if both files were combined they'd be quite large. As this is a template I feel like it should try to get users off on the right foot. I've also noticed other users of tui/ratatui follow this pattern; although they may predate this repo and they're generally large applications.
If the maintainers/community agree that this responsibility should be split I'm more than happy to write up a PR for it. Alternatively if this is the pattern that the maintainers want to push, I can make a PR to tui-rs-revival to combine their ui.rs and app.rs for consistency if this is something they care about.
Also I'm pretty new to rust and contributing to open source stuff, so there is a reasonable chance I've overlooked something here and this isn't feasible.
Thanks!
Hello!
I created a small benchmarking tool using your template and modifying it to my need.
Since this repo does not have a license I only added comments like this line to cite your repo.
Is it ok with you?
The former uses io::stderr
and the latter uses a different io::stdout
. Is there any special meaning? Or was it simply an accidental mistake?
There is a typo in a doc comment in tui.rs
in both the simple
and simple-async
templates. The doc comment for the draw
method says
/// [`rendering`]: crate::ui:render
where it should be
/// [`rendering`]: crate::ui::render
(There should be two colons between ui
and render
.)
This leads to an error when Cargo builds the documentation,
warning: unresolved link to `crate::ui:render`
--> src\tui.rs:52:24
|
52 | /// [`rendering`]: crate::ui:render
| ^^^^^^^^^^^^^^^^ no item named `ui:render` in module `ratatui_simple_template`
|
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.