Skip to content

Commit 5a72c7c

Browse files
committed
style: import to the top, docstrings
1 parent 05b1fa2 commit 5a72c7c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/backend/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ratatui::{
99
layout::Size,
1010
style::{Color, Modifier},
1111
};
12+
use unicode_width::UnicodeWidthStr;
1213
use web_sys::{
1314
wasm_bindgen::{JsCast, JsValue},
1415
window, Document, Element, HtmlCanvasElement, Window,
@@ -19,7 +20,6 @@ pub struct CssAttribute {
1920
pub value: Option<&'static str>,
2021
}
2122

22-
use unicode_width::UnicodeWidthStr;
2323
/// Creates a new `<span>` element with the given cell.
2424
pub(crate) fn create_span(document: &Document, cell: &Cell) -> Result<Element, Error> {
2525
let span = document.create_element("span")?;
@@ -123,6 +123,7 @@ fn parse_inline_style(css: &str) -> Vec<(String, String)> {
123123
.collect()
124124
}
125125

126+
/// Build a css string from an array of (field, value) css style attributes.
126127
fn build_inline_style(styles: &[(String, String)]) -> String {
127128
let mut s = String::new();
128129
for (k, v) in styles {
@@ -131,6 +132,9 @@ fn build_inline_style(styles: &[(String, String)]) -> String {
131132
s
132133
}
133134

135+
/// Replace the `style` attribute by the given css string in the given Element.
136+
///
137+
/// If the css string is empty, removes completly the `style` attribute.
134138
fn set_or_remove_style_attribute(elem: &Element, css: String) -> Result<(), JsValue> {
135139
if css.is_empty() {
136140
elem.remove_attribute("style")

0 commit comments

Comments
 (0)