How to output stdout into a box? #273
-
I would like to create a chat app, where I have the main message window, an input window and an additional "info" window that just displays in whatever gets sent to stdout and stderr normally. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
FTXUI reads from stdin, and write to stdout. So, if you write to stdout directly it would break the interface. So I recommand not writting to stdout directly, but create your special set of function to write elsewhere. (Note: One can also try to reroute file descriptor. For instance I redirected stdin here) Let's say the data is stored into: std::string data; Then, you can update the data: void Write(const std::string& new_data) {
data += new_data;
} Then you need an DOM Element drawing it:
I guess, you want a component producing the DOM element for every new frame. You can use: auto component = Renderer([&data] {
return text(data)
}); A Elements elements;
for(auto& line : data) {
elements.push_back(text(line));
}
return vbox(std::move(elements)); Or you can continue to store in a std::string and break by new lines dynamically: auto component = Renderer([&data] {
// Break `data` by new lines:
auto lines = lines();
auto start = 0U;
auto end = s.find('\n');
while (end != std::string::npos) {
lines.push_back(text(s.substr(start, end-start)));
start = end + 1;
end = s.find('\n', start);
}
lines.push_back(text(s.substr(start, end)));
return vbox(std::move(lines));
});
|
Beta Was this translation helpful? Give feedback.
-
Maybe you can take Scroller from:
https://github.com/ArthurSonzogni/git-tui/tree/master/src
and wrap your component?
Le dim. 19 juin 2022, 18:51, Amin D. ***@***.***> a écrit :
… Thanks it helped a lot!
I'm trying to make a box with text getting updated which works, but also i
need to make it scrollable which i can't figure out how to do it correctly,
it just makes draws a scrollbar but it cant be controlled. Is there any way
to make such scrollable text area ?
—
Reply to this email directly, view it on GitHub
<#273 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEJ4QRKRF35N3QJPKALSVTVP5FYPANCNFSM5JNK633A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
FTXUI reads from stdin, and write to stdout. So, if you write to stdout directly it would break the interface.
So I recommand not writting to stdout directly, but create your special set of function to write elsewhere.
(Note: One can also try to reroute file descriptor. For instance I redirected stdin here)
Let's say the data is stored into:
Then, you can update the data:
Then you need an DOM Element drawing it:
I guess, you want a component producing the DOM element for every new frame. You can use:
A
text
only support d…