Skip to content
Snippets Groups Projects
Unverified Commit ec994a4e authored by Arthur Sonzogni's avatar Arthur Sonzogni Committed by GitHub
Browse files

Add support for emscripten screen resize. (#463)

parent 3ec765e1
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ current (development) ...@@ -11,6 +11,7 @@ current (development)
requested requested
- Bugfix: Forward the selected/focused area from the child in gridbox. - Bugfix: Forward the selected/focused area from the child in gridbox.
- Bugfix: Fix incorrect Canvas computed dimensions. - Bugfix: Fix incorrect Canvas computed dimensions.
- Bugfix: Support `vscroll_indicator` with a zero inner size.
### Component: ### Component:
- Feature: Add the `Modal` component. - Feature: Add the `Modal` component.
...@@ -20,6 +21,8 @@ current (development) ...@@ -20,6 +21,8 @@ current (development)
### Screen ### Screen
- Feature: add `Box::Union(a,b) -> Box` - Feature: add `Box::Union(a,b) -> Box`
- Bugfix: Fix resetting `dim` clashing with resetting of `bold`.
- Feature: Add emscripten screen resize support.
3.0.0 3.0.0
----- -----
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<title>FTXUI examples WebAssembly</title> <title>FTXUI examples WebAssembly</title>
<script src="https://cdn.jsdelivr.net/npm/xterm@4.18.0/lib/xterm.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/xterm@4.18.0/lib/xterm.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-webgl@0.11.4/lib/xterm-addon-webgl.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/xterm-addon-webgl@0.11.4/lib/xterm-addon-webgl.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.5.0/lib/xterm-addon-fit.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@4.11.0/css/xterm.css"></link> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@4.11.0/css/xterm.css"></link>
<!--Add COOP/COEP via a ServiceWorker to use SharedArrayBuffer--> <!--Add COOP/COEP via a ServiceWorker to use SharedArrayBuffer-->
<script> <script>
...@@ -79,9 +80,12 @@ ...@@ -79,9 +80,12 @@
} }
} }
const term = new Terminal(); const term = new Terminal();
term.open(document.querySelector('#terminal')); const term_element = document.querySelector('#terminal');
term.resize(140,43); term.open(term_element);
term.loadAddon(new (WebglAddon.WebglAddon)());
const webgl_addon = new (WebglAddon.WebglAddon)();
term.loadAddon(webgl_addon);
const onBinary = e => { const onBinary = e => {
for(c of e) for(c of e)
stdin_buffer.push(c.charCodeAt(0)); stdin_buffer.push(c.charCodeAt(0));
...@@ -93,7 +97,23 @@ ...@@ -93,7 +97,23 @@
FS.init(stdin, stdout, stderr); FS.init(stdin, stdout, stderr);
}, },
postRun: [], postRun: [],
onRuntimeInitialized: () => {}, onRuntimeInitialized: () => {
// Handle screen resize:
const fit_addon = new (FitAddon.FitAddon)();
term.loadAddon(fit_addon);
fit_addon.fit();
const resize_handler = () => {
const {cols, rows} = fit_addon.proposeDimensions();
term.resize(cols, rows);
window.Module._ftxui_on_resize(cols, rows);
};
const resize_observer = new ResizeObserver(resize_handler);
resize_observer.observe(term_element);
resize_handler();
// Disable scrollbar
term.write('\x1b[?47h')
},
}; };
const words = example.split('/') const words = example.split('/')
...@@ -137,9 +157,11 @@ ...@@ -137,9 +157,11 @@
} }
#terminal { #terminal {
padding:10px; width:100%;
height: 500px;
height: calc(clamp(200px, 100vh - 300px, 900px));
overflow: hidden;
border:none; border:none;
background-color:black;
padding:auto; padding:auto;
} }
......
...@@ -135,6 +135,17 @@ void EventListener(std::atomic<bool>* quit, Sender<Task> out) { ...@@ -135,6 +135,17 @@ void EventListener(std::atomic<bool>* quit, Sender<Task> out) {
} }
} }
extern "C" {
EMSCRIPTEN_KEEPALIVE
void ftxui_on_resize(int columns, int rows) {
Terminal::SetFallbackSize({
columns,
rows,
});
std::raise(SIGWINCH);
}
}
#else #else
#include <sys/time.h> // for timeval #include <sys/time.h> // for timeval
......
...@@ -38,7 +38,10 @@ Dimensions& FallbackSize() { ...@@ -38,7 +38,10 @@ Dimensions& FallbackSize() {
constexpr int fallback_width = 80; constexpr int fallback_width = 80;
constexpr int fallback_height = 24; constexpr int fallback_height = 24;
#endif #endif
static Dimensions g_fallback_size{fallback_width, fallback_height}; static Dimensions g_fallback_size{
fallback_width,
fallback_height,
};
return g_fallback_size; return g_fallback_size;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment