(ctx: &mut ScriptContext<'_, API>, view: &EditorView)
| 92 | let visible = match level.as_str() { |
| 93 | "error" => !state.output_hide_error, |
| 94 | "warn" => !state.output_hide_warn, |
| 95 | _ => !state.output_hide_info, |
| 96 | }; |
| 97 | visible && (filter.is_empty() || text.to_ascii_lowercase().contains(&filter)) |
| 98 | }) |
| 99 | .map(|((text, level), repeat)| { |
| 100 | let icon = match level.as_str() { "error" => "[x]", "warn" => "[!]", _ => "[i]" }; |
| 101 | let text = text.replace('\n', " "); |
| 102 | if *repeat > 1 { format!("{icon} {text} x{repeat}") } else { format!("{icon} {text}") } |
| 103 | }) |
| 104 | .collect::<Vec<_>>(); |
| 105 | if lines.len() > 24 { |
| 106 | lines.drain(0..lines.len() - 24); |
| 107 | } |
| 108 | if lines.is_empty() { "No output".to_string() } else { lines.join("\n") } |
| 109 | } |
| 110 | |
| 111 | pub fn clear_editor_output<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>) { |
| 112 | let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 113 | state.output_messages.clear(); |
| 114 | state.output_levels.clear(); |
| 115 | state.output_repeats.clear(); |
| 116 | state.output_seen_log.clone_from(&state.log); |
| 117 | }); |
| 118 | refresh_all(ctx); |
| 119 | } |
| 120 | |
| 121 | pub fn update_editor_output_filter<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>) { |
| 122 | let value = read_text_box(ctx, "output_filter_box").unwrap_or_default(); |
| 123 | let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 124 | state.output_filter = value; |
| 125 | state.focused_inspector_box = "output_filter_box".to_string(); |
| 126 | }); |
| 127 | refresh_all(ctx); |
| 128 | } |
| 129 | |
| 130 | pub fn toggle_editor_output_level<API: ScriptAPI + ?Sized>( |
| 131 | ctx: &mut ScriptContext<'_, API>, |
| 132 | level: &str, |
| 133 | ) { |
| 134 | let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| match level { |
| 135 | "error" => state.output_hide_error = !state.output_hide_error, |
| 136 | "warn" => state.output_hide_warn = !state.output_hide_warn, |
| 137 | _ => state.output_hide_info = !state.output_hide_info, |
| 138 | }); |
| 139 | refresh_all(ctx); |
| 140 | } |
| 141 | |
| 142 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 143 | pub struct EditorCommand { |
| 144 | pub id: &'static str, |
| 145 | pub label: &'static str, |
| 146 | pub hint: &'static str, |
| 147 | } |
| 148 | |
| 149 | pub fn editor_commands(query: &str) -> Vec<EditorCommand> { |
| 150 | const COMMANDS: [EditorCommand; 12] = [ |
| 151 | EditorCommand { id: "save", label: "Save Scene", hint: "Ctrl+S" }, |
no test coverage detected