|
4 | 4 | //! desktop.
|
5 | 5 | //! Implements functions listed here: https://docs.python.org/3/library/builtins.html.
|
6 | 6 |
|
7 |
| -use crate::convert; |
8 | 7 | use js_sys::{self, Array};
|
9 | 8 | use rustpython_vm::obj::{objstr, objtype};
|
10 | 9 | use rustpython_vm::pyobject::{IdProtocol, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol};
|
11 | 10 | use rustpython_vm::VirtualMachine;
|
12 |
| -use wasm_bindgen::{prelude::*, JsCast}; |
13 |
| -use web_sys::{self, console, HtmlTextAreaElement}; |
| 11 | +use web_sys::{self, console}; |
14 | 12 |
|
15 | 13 | pub(crate) fn window() -> web_sys::Window {
|
16 | 14 | web_sys::window().expect("Window to be available")
|
17 | 15 | }
|
18 | 16 |
|
19 |
| -// The HTML id of the textarea element that act as our STDOUT |
20 |
| - |
21 |
| -pub fn print_to_html(text: &str, selector: &str) -> Result<(), JsValue> { |
22 |
| - let document = window().document().expect("Document to be available"); |
23 |
| - let element = document |
24 |
| - .query_selector(selector)? |
25 |
| - .ok_or_else(|| js_sys::TypeError::new("Couldn't get element"))?; |
26 |
| - let textarea = element |
27 |
| - .dyn_ref::<HtmlTextAreaElement>() |
28 |
| - .ok_or_else(|| js_sys::TypeError::new("Element must be a textarea"))?; |
29 |
| - |
30 |
| - let value = textarea.value(); |
31 |
| - |
32 |
| - let scroll_height = textarea.scroll_height(); |
33 |
| - let scrolled_to_bottom = scroll_height - textarea.scroll_top() == textarea.client_height(); |
34 |
| - |
35 |
| - textarea.set_value(&format!("{}{}", value, text)); |
36 |
| - |
37 |
| - if scrolled_to_bottom { |
38 |
| - textarea.scroll_with_x_and_y(0.0, scroll_height.into()); |
39 |
| - } |
40 |
| - |
41 |
| - Ok(()) |
42 |
| -} |
43 |
| - |
44 | 17 | pub fn format_print_args(vm: &mut VirtualMachine, args: PyFuncArgs) -> Result<String, PyObjectRef> {
|
45 | 18 | // Handle 'sep' kwarg:
|
46 | 19 | let sep_arg = args
|
@@ -93,12 +66,6 @@ pub fn format_print_args(vm: &mut VirtualMachine, args: PyFuncArgs) -> Result<St
|
93 | 66 | Ok(output)
|
94 | 67 | }
|
95 | 68 |
|
96 |
| -pub fn builtin_print_html(vm: &mut VirtualMachine, args: PyFuncArgs, selector: &str) -> PyResult { |
97 |
| - let output = format_print_args(vm, args)?; |
98 |
| - print_to_html(&output, selector).map_err(|err| convert::js_to_py(vm, err))?; |
99 |
| - Ok(vm.get_none()) |
100 |
| -} |
101 |
| - |
102 | 69 | pub fn builtin_print_console(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
103 | 70 | let arr = Array::new();
|
104 | 71 | for arg in args.args {
|
|
0 commit comments