Comments (4)
Thanks!
screen.PostEvent(Event::Custom);
is thread safe and will request a new frame to be drawn on the thread calling screen.Loop().
So I believe what you did works. Could you help me figure out what doesn't work?
Here is an example I built yesterday:
SAtacker/bb-config#7
that you might want to look. Threads aren't easy to deals with, I am exposing the Receiver/Sender utility class that FTXUI uses internally:
https://github.com/ArthurSonzogni/FTXUI/blob/master/include/ftxui/component/receiver.hpp
from ftxui.
yeah ! this is kind of what I am trying now, after reading about the receiver component , just a simple test :
void recv_msg(ftxui::Sender<std::wstring> &sender_1)
{
KlineUtils kutils;
sequence candle_sequence;
string interval = "1m";
string socket_address = "ipc:///home/xavier/ftxtui/" + interval;
zmq::context_t ctx;
zmq::socket_t socket(ctx, zmq::socket_type::pull);
socket.bind(socket_address);
while (true)
{
zmq::message_t message;
socket.recv(message);
string message_str = message.to_string();
nlohmann::json j = nlohmann::json::parse(message_str);
cout << j[299]["c"] << endl;
std::string s = j[299]["c"].dump();
std::wstring w = LR"(CURRENT PRICE: )" + fs::path(s).wstring();
sender_1->Send(w);
cout << "sender sent" << endl;
}
}
void proc_received(Receiver<std::wstring> &receiver){
std::vector<std::wstring> received;
while (receiver->HasPending()) {
std::wstring str;
receiver->Receive(&str);
received.push_back(str);
}
for ( auto v : received){
cout << &v << endl;
}
}
int main(int argc, const char *argv[])
{
Receiver<std::wstring> receiver = MakeReceiver<std::wstring>();
ftxui::Sender<std::wstring> sender_1 = receiver->MakeSender();
thread t1;
t1 = thread(recv_msg,ref(sender_1));
thread t2;
t2 = thread(proc_received, ref(receiver));
t1.join();
t2.join();
The thread where the receiver should be ? receiving and pushing to the vector from the sender doesn't print anything, meaning the while loop is not fiding any pending messages to be delivered ? Thanks !
from ftxui.
If thread2 is quick enough, (receiver->HasPending()) will be false, explaining what you are seeing.
What happen if you use:
while (true) {
std::wstring str;
receiver->Receive(&str);
std::cerr << "received: " << str << std::endl;
}
}
Also, please pass sender_1 ownership by move. Don't use ref(sender_1). Same for receiver.
from ftxui.
Ok yes it makes total sense ! Now I'm getting the messages delivered, I will try to implement a screen and to update it, thanks !
from ftxui.
Related Issues (20)
- input.cpp field length. HOT 2
- Console doesn't clear previous renderer text after new renderer HOT 3
- Canvas background
- Introductory example fails to build HOT 2
- Custom event question HOT 2
- Add example to use system ftxui HOT 3
- "Bug or feature" HOT 3
- fatal error: string_view: No such file or directory HOT 4
- How to check if current terminal supports TUI? HOT 2
- include could not find requested file: .../lib/ftxui/cmake/ftxui-targets.cmake HOT 1
- Is there a way to change the Slider 's color? HOT 1
- [doc-bug] Move Documentation Comments From `.cpp` To `.hpp` For Better LSP Support HOT 1
- Slider Bug; 3 line but only 1 line valid HOT 2
- cursor problem HOT 1
- Allow Canvas re-use for optimization HOT 3
- container is passed to renderer as a lambda return value, causing rendering to fail HOT 5
- How to remove focus from an element when hovering with the mouse pointer? HOT 2
- Run-Time Check Failure: Stack Corruption of 'option' Variable HOT 5
- Adding elements in loop HOT 1
- [HELP] - Menu inside frame goes to the top when unfocused HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ftxui.