diff --git a/CHANGELOG.md b/CHANGELOG.md index 48fec49ff..6804fa52f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -665,23 +665,25 @@ ensure that the codebase is easier to maintain and understand, and easier to add features to in the future. The separation of concerns is now much clearer, and they reflect how the functionality is used in the real world. +- Removed: + - Remove the dependency on `r3bl_simple_logger` and archive it. You can read the details + in its [CHANGELOG entry](#archived-2024-09-27). Tokio tracing is now used under the + covers. + - Remove all the functions like `log_debug`, `log_info`, etc. and favor directly using + tokio tracing macros for logging, eg: `tracing::debug!`, `tracing::info!`, etc. + - Changed: - - Renamed the `debug!` macro, which is confusing, since it clashes with logging, to + - Rename the `debug!` macro, which is confusing, since it clashes with logging, to `console_log!`. This macro is used in many places in the codebase for quick formatted output to console (via `eprintln!`). The code to format the output is in the `console_log_impl.rs` file. - Reorganize the `src` folder to make sure that there aren't any top level files, and that everything is in a module. This is to make it easier to add new modules in the future. -- Removed: - - The dependency on `r3bl_simple_logger` has been removed and that entire crate has been - archived. You can read the details in its [CHANGELOG entry](#archived-2024-09-27). - Tokio tracing is now used under the covers. - - Added: - - The actual logging API is left as is, and a new variant is also included, so you are - free to choose to keep using the old API, or directly using tokio tracing, or a mix of - both! See `logging_api.rs` for more details. + - Simplify the actual logging API into a single function, and allow use of tokio + tracing, macros for for logging, eg: `tracing::debug!`, `tracing::info!`, etc. See + `logging_api.rs` for more details. - Move the `color_wheel` module into `r3bl_rs_utils_core` crate. This is to ensure that it is possible to import just color wheel and lolcat related functionality without having to import the entire `r3bl_tui` crate. And de-tangles the dependency tree, diff --git a/cmdr/src/bin/edi.rs b/cmdr/src/bin/edi.rs index a5276e8ea..41014cd03 100644 --- a/cmdr/src/bin/edi.rs +++ b/cmdr/src/bin/edi.rs @@ -21,7 +21,6 @@ use clap::Parser; use r3bl_ansi_color::{AnsiStyledText, Style}; use r3bl_cmdr::{edi::launcher, report_analytics, upgrade_check, AnalyticsAction}; use r3bl_rs_utils_core::{call_if_true, - log_debug, throws, try_initialize_global_logging, ColorWheel, @@ -44,8 +43,7 @@ async fn main() -> CommonResult<()> { let enable_logging = cli_arg.global_options.enable_logging; call_if_true!(enable_logging, { try_initialize_global_logging(tracing_core::LevelFilter::DEBUG).ok(); - log_debug("Start logging...".to_string()); - log_debug(format!("cli_args {:?}", cli_arg)); + tracing::debug!("Start logging... cli_args {:?}", cli_arg); }); // Check analytics reporting. @@ -90,7 +88,7 @@ async fn main() -> CommonResult<()> { // Stop logging. call_if_true!(enable_logging, { - log_debug("Stop logging...".to_string()); + tracing::debug!("Stop logging..."); }); // Exit message. diff --git a/cmdr/src/bin/giti.rs b/cmdr/src/bin/giti.rs index 26f73b6fa..0ac524d61 100644 --- a/cmdr/src/bin/giti.rs +++ b/cmdr/src/bin/giti.rs @@ -35,7 +35,6 @@ use r3bl_cmdr::{color_constants::DefaultColors::{FrozenBlue, GuardsRed, Moonligh upgrade_check, AnalyticsAction}; use r3bl_rs_utils_core::{call_if_true, - log_debug, throws, try_initialize_global_logging, CommonResult}; @@ -52,8 +51,7 @@ async fn main() -> CommonResult<()> { let enable_logging = cli_arg.global_options.enable_logging; call_if_true!(enable_logging, { try_initialize_global_logging(tracing_core::LevelFilter::DEBUG).ok(); - log_debug("Start logging...".to_string()); - log_debug(format!("cli_args {:?}", cli_arg)); + tracing::debug!("Start logging... cli_args {:?}", cli_arg); }); // Check analytics reporting. @@ -70,7 +68,7 @@ async fn main() -> CommonResult<()> { launch_giti(cli_arg); call_if_true!(enable_logging, { - log_debug("Stop logging...".to_string()); + tracing::debug!("Stop logging..."); }); }) } diff --git a/cmdr/src/edi/app_main.rs b/cmdr/src/edi/app_main.rs index 3efc6f552..ea7409d49 100644 --- a/cmdr/src/edi/app_main.rs +++ b/cmdr/src/edi/app_main.rs @@ -22,7 +22,6 @@ use r3bl_rs_utils_core::{call_if_true, ch, get_tui_style, get_tui_styles, - log_debug, position, requested_size_percent, send_signal, @@ -151,8 +150,7 @@ mod app_main_constructor { impl Default for AppMain { fn default() -> Self { call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct edi::AppMain"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct edi::AppMain"); }); Self } @@ -216,10 +214,9 @@ mod app_main_impl_app_trait { match result_open { Ok(_) => { call_if_true!(DEBUG_TUI_MOD, { - log_debug( - format!("\nπŸ“£ Opened feedback link: {link_url:?}") - .green() - .to_string(), + tracing::debug!( + "\nπŸ“£ Opened feedback link: {}", + format!("{link_url:?}").green() ); }); } @@ -407,8 +404,7 @@ mod modal_dialog_ask_for_filename_to_save_file { ); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸ“£ activate modal simple: {:?}", has_focus); - log_debug(msg); + tracing::debug!("πŸ“£ activate modal simple: {:?}", has_focus); }); }); } @@ -464,10 +460,8 @@ mod modal_dialog_ask_for_filename_to_save_file { let user_input_file_path = text.trim().to_string(); if !user_input_file_path.is_empty() { call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("\nπŸ’ΎπŸ’ΎπŸ’Ύ About to save the new buffer with given filename: {user_input_file_path:?}") - .magenta() - .to_string(); - log_debug(msg); + tracing::debug!("\nπŸ’ΎπŸ’ΎπŸ’Ύ About to save the new buffer with given filename: {}", + format!("{user_input_file_path:?}").magenta()); }); let maybe_editor_buffer = state.get_mut_editor_buffer( @@ -526,11 +520,7 @@ mod modal_dialog_ask_for_filename_to_save_file { ); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!( - "πŸͺ™ {}", - "construct DialogComponent (simple) { on_dialog_press }" - ); - log_debug(msg); + tracing::debug!("πŸͺ™ construct DialogComponent (simple) [ on_dialog_press ]",); }); } } @@ -606,10 +596,7 @@ mod populate_component_registry { has_focus.set_id(id); call_if_true!(DEBUG_TUI_MOD, { - { - let msg = format!("πŸͺ™ {} = {:?}", "init has_focus", has_focus.get_id()); - log_debug(msg); - } + tracing::debug!("πŸͺ™ {} = {:?}", "init has_focus", has_focus.get_id()); }); } @@ -638,8 +625,7 @@ mod populate_component_registry { ComponentRegistry::put(component_registry_map, id, boxed_editor_component); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct EditorComponent { on_buffer_change }"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct EditorComponent [ on_buffer_change ]"); }); } } diff --git a/core/src/logging/logging_api.rs b/core/src/logging/logging_api.rs index 855ca648a..4e5e618e5 100644 --- a/core/src/logging/logging_api.rs +++ b/core/src/logging/logging_api.rs @@ -55,8 +55,3 @@ pub fn try_initialize_global_logging( ok!() } - -// TODO: remove all usages of this -pub fn log_debug(arg: String) { - tracing::debug!(arg); -} diff --git a/tui/examples/demo/ex_editor/app_main.rs b/tui/examples/demo/ex_editor/app_main.rs index 765ee0b85..afc57a224 100644 --- a/tui/examples/demo/ex_editor/app_main.rs +++ b/tui/examples/demo/ex_editor/app_main.rs @@ -19,7 +19,6 @@ use r3bl_rs_utils_core::{call_if_true, ch, get_tui_style, get_tui_styles, - log_debug, position, requested_size_percent, send_signal, @@ -121,8 +120,7 @@ mod constructor { impl Default for AppMain { fn default() -> Self { call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct ex_rc::AppMain"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct ex_rc::AppMain"); }); Self } @@ -441,8 +439,7 @@ mod modal_dialogs { ); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸ“£ activate modal simple: {:?}", has_focus); - log_debug(msg); + tracing::debug!("πŸ“£ activate modal simple: {:?}", has_focus); }); }); } @@ -478,8 +475,7 @@ mod modal_dialogs { ); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸ“£ activate modal autocomplete: {:?}", has_focus); - log_debug(msg); + tracing::debug!("πŸ“£ activate modal autocomplete: {:?}", has_focus); }); Ok(()) @@ -567,10 +563,7 @@ mod populate_component_registry { has_focus.set_id(id); call_if_true!(DEBUG_TUI_MOD, { - { - let msg = format!("πŸͺ™ {} = {:?}", "init has_focus", has_focus.get_id()); - log_debug(msg); - } + tracing::debug!("πŸͺ™ init has_focus = {:?}", has_focus.get_id()); }); } @@ -599,8 +592,7 @@ mod populate_component_registry { ComponentRegistry::put(component_registry_map, id, boxed_editor_component); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct EditorComponent { on_buffer_change }"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct EditorComponent [ on_buffer_change ]"); }); } @@ -683,11 +675,7 @@ mod populate_component_registry { ); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!( - "πŸͺ™ {}", - "construct DialogComponent (simple) { on_dialog_press }" - ); - log_debug(msg); + tracing::debug!("πŸͺ™ construct DialogComponent (simple) [ on_dialog_press ]"); }); } @@ -770,11 +758,9 @@ mod populate_component_registry { ); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!( - "πŸͺ™ {}", - "construct DialogComponent (autocomplete) { on_dialog_press }" + tracing::debug!( + "πŸͺ™ construct DialogComponent (autocomplete) [ on_dialog_press ]" ); - log_debug(msg); }); } } diff --git a/tui/examples/demo/ex_pitch/app_main.rs b/tui/examples/demo/ex_pitch/app_main.rs index 0d9cdbed9..57498c5f9 100644 --- a/tui/examples/demo/ex_pitch/app_main.rs +++ b/tui/examples/demo/ex_pitch/app_main.rs @@ -20,7 +20,6 @@ use std::fmt::Debug; use r3bl_rs_utils_core::{call_if_true, ch, get_tui_styles, - log_debug, position, requested_size_percent, send_signal, @@ -103,8 +102,7 @@ mod constructor { impl Default for AppMain { fn default() -> Self { call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct ex_pitch::AppWithLayout"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct ex_pitch::AppWithLayout"); }); Self } @@ -303,10 +301,7 @@ mod populate_component_registry { // Switch focus to the editor component if focus is not set. has_focus.set_id(id); call_if_true!(DEBUG_TUI_MOD, { - { - let msg = format!("πŸͺ™ {} = {:?}", "init has_focus", has_focus.get_id()); - log_debug(msg); - } + tracing::debug!("πŸͺ™ init has_focus = {:?}", has_focus.get_id()); }); } @@ -339,8 +334,7 @@ mod populate_component_registry { ComponentRegistry::put(component_registry_map, id, boxed_editor_component); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct EditorComponent { on_buffer_change }"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct EditorComponent [ on_buffer_change ]"); }); } } diff --git a/tui/examples/demo/ex_rc/app_main.rs b/tui/examples/demo/ex_rc/app_main.rs index e56b92a50..833ff1b1a 100644 --- a/tui/examples/demo/ex_rc/app_main.rs +++ b/tui/examples/demo/ex_rc/app_main.rs @@ -21,7 +21,6 @@ use chrono::{DateTime, Local}; use r3bl_rs_utils_core::{call_if_true, ch, get_tui_styles, - log_debug, position, requested_size_percent, send_signal, @@ -189,8 +188,7 @@ mod constructor { impl Default for AppMain { fn default() -> Self { call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct ex_rc::AppWithLayout"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct ex_rc::AppWithLayout"); }); Self { data: AppData { @@ -431,8 +429,7 @@ mod populate_component_registry { has_focus.set_id(id); call_if_true!(DEBUG_TUI_MOD, { { - let msg = format!("πŸͺ™ {} = {:?}", "init has_focus", has_focus.get_id()); - log_debug(msg); + tracing::debug!("πŸͺ™ init has_focus = {:?}", has_focus.get_id()); } }); } @@ -466,8 +463,7 @@ mod populate_component_registry { ComponentRegistry::put(component_registry_map, id, boxed_editor_component); call_if_true!(DEBUG_TUI_MOD, { - let msg = format!("πŸͺ™ {}", "construct EditorComponent { on_buffer_change }"); - log_debug(msg); + tracing::debug!("πŸͺ™ construct EditorComponent [ on_buffer_change ]"); }); } } diff --git a/tui/src/tui/dialog/dialog_component/dialog_component_struct.rs b/tui/src/tui/dialog/dialog_component/dialog_component_struct.rs index ddc442424..f08b67179 100644 --- a/tui/src/tui/dialog/dialog_component/dialog_component_struct.rs +++ b/tui/src/tui/dialog/dialog_component/dialog_component_struct.rs @@ -18,8 +18,7 @@ use std::fmt::Debug; use r3bl_rs_utils_core::{call_if_true, - common::{CommonError, CommonErrorType, CommonResult}, - log_debug}; + common::{CommonError, CommonErrorType, CommonResult}}; use crate::{Component, DialogEngine, @@ -173,9 +172,10 @@ where has_focus.reset_modal_id(); call_if_true!(DEBUG_TUI_MOD, { - let msg = - format!("🐝 restore focus to non modal: {:?}", has_focus); - log_debug(msg); + tracing::debug!( + "🐝 restore focus to non modal: {:?}", + has_focus + ); }); // Run the handler (if any) w/ `dialog_choice`. diff --git a/tui/src/tui/dialog/dialog_engine/dialog_engine_api.rs b/tui/src/tui/dialog/dialog_engine/dialog_engine_api.rs index 267f0d0c0..ddbb8989b 100644 --- a/tui/src/tui/dialog/dialog_engine/dialog_engine_api.rs +++ b/tui/src/tui/dialog/dialog_engine/dialog_engine_api.rs @@ -34,8 +34,7 @@ use r3bl_rs_utils_core::{ch, UnicodeString, SPACER}; -use crate::{editor_buffer_clipboard_support::system_clipboard_service_provider::SystemClipboard, - render_ops, +use crate::{render_ops, render_pipeline, render_tui_styled_texts_into, BorderGlyphCharacter, @@ -63,6 +62,7 @@ use crate::{editor_buffer_clipboard_support::system_clipboard_service_provider:: RenderPipeline, SpecialKey, SurfaceBounds, + SystemClipboard, ZOrder}; #[derive(Debug)] diff --git a/tui/src/tui/editor/editor_buffer/editor_buffer_clipboard_support.rs b/tui/src/tui/editor/editor_buffer/editor_buffer_clipboard_support.rs index 272af31e7..ea8e5262c 100644 --- a/tui/src/tui/editor/editor_buffer/editor_buffer_clipboard_support.rs +++ b/tui/src/tui/editor/editor_buffer/editor_buffer_clipboard_support.rs @@ -18,12 +18,12 @@ use std::error::Error; use crossterm::style::Stylize; -use r3bl_rs_utils_core::{call_if_true, ch, log_debug, UnicodeString}; +use r3bl_rs_utils_core::{call_if_true, ch, UnicodeString}; use super::EditorBuffer; use crate::{EditorArgsMut, EditorEngineInternalApi, DEBUG_TUI_COPY_PASTE}; -type ClipboardResult = Result>; +pub type ClipboardResult = Result>; /// Abstraction for the clipboard service for dependency injection. This trait is /// implemented by both a test clipboard service and a system clipboard service. @@ -62,15 +62,10 @@ pub fn copy_to_clipboard( clipboard_service_provider.try_to_put_content_into_clipboard(vec_str.join("\n")); if let Err(error) = result { call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug( - format!( - "\nπŸ“‹πŸ“‹πŸ“‹ Failed to copy selected text to clipboard: {0}", - /* 0 */ - format!("{error}").white(), - ) - .on_dark_red() - .to_string(), - ) + tracing::debug!( + "\nπŸ“‹πŸ“‹πŸ“‹ Failed to copy selected text to clipboard: {}", + format!("{error}").white().on_dark_red(), + ); }); } } @@ -117,97 +112,20 @@ pub fn paste_from_clipboard( } call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug( - format!( - "\nπŸ“‹πŸ“‹πŸ“‹ Text was pasted from clipboard: \n{0}", - /* 0 */ - clipboard_text.clone().dark_red() - ) - .black() - .on_green() - .to_string(), - ) + tracing::debug!( + "\nπŸ“‹πŸ“‹πŸ“‹ Text was pasted from clipboard: \n{}", + clipboard_text.to_string().black().on_green() + ); }); } Err(error) => { call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug( - format!( - "\nπŸ“‹πŸ“‹πŸ“‹ Failed to paste the text from clipboard: {0}", - /* 0 */ - format!("{error}").white(), - ) - .on_dark_red() - .to_string(), - ) + tracing::debug!( + "\nπŸ“‹πŸ“‹πŸ“‹ Failed to paste the text from clipboard: {}", + format!("{error}").white().on_dark_red(), + ); }); } } } - -pub mod test_clipboard_service_provider { - use super::{ClipboardResult, ClipboardService}; - - #[derive(Debug, Default)] - pub struct TestClipboard { - pub content: String, - } - - impl ClipboardService for TestClipboard { - fn try_to_put_content_into_clipboard( - &mut self, - content: String, - ) -> ClipboardResult<()> { - self.content = content; - Ok(()) - } - - fn try_to_get_content_from_clipboard(&mut self) -> ClipboardResult { - Ok(self.content.clone()) - } - } -} - -pub mod system_clipboard_service_provider { - use copypasta_ext::{copypasta::ClipboardProvider, x11_fork::ClipboardContext}; - use crossterm::style::Stylize; - use r3bl_rs_utils_core::{call_if_true, log_debug, throws}; - - use super::{ClipboardResult, ClipboardService}; - use crate::DEBUG_TUI_COPY_PASTE; - - pub struct SystemClipboard; - - impl ClipboardService for SystemClipboard { - fn try_to_put_content_into_clipboard( - &mut self, - content: String, - ) -> ClipboardResult<()> { - throws!({ - let mut ctx = ClipboardContext::new()?; - ctx.set_contents(content.clone())?; - - call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug( - format!( - "\nπŸ“‹πŸ“‹πŸ“‹ Selected Text was copied to clipboard: \n{0}", - /* 0 */ - content.dark_red() - ) - .black() - .on_green() - .to_string(), - ) - }); - }) - } - - fn try_to_get_content_from_clipboard(&mut self) -> ClipboardResult { - let mut ctx = ClipboardContext::new()?; - let content = ctx.get_contents()?; - - Ok(content) - } - } -} diff --git a/tui/src/tui/editor/editor_buffer/editor_buffer_selection_support.rs b/tui/src/tui/editor/editor_buffer/editor_buffer_selection_support.rs index f8887beb4..711357d96 100644 --- a/tui/src/tui/editor/editor_buffer/editor_buffer_selection_support.rs +++ b/tui/src/tui/editor/editor_buffer/editor_buffer_selection_support.rs @@ -20,7 +20,6 @@ use std::cmp; use crossterm::style::Stylize; use r3bl_rs_utils_core::{call_if_true, ch, - log_debug, position, CaretLocationInRange, CaretMovementDirection, @@ -59,10 +58,9 @@ impl EditorBufferApi { ), ); - call_if_true!( - DEBUG_TUI_COPY_PASTE, - log_debug(format!("\nπŸ•πŸ•πŸ• new selection: \n\t{}", new_range)) - ); + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!("\nπŸ•πŸ•πŸ• new selection: \n\t{}", new_range); + }); return; }; @@ -75,33 +73,32 @@ impl EditorBufferApi { end_display_col_index: range_end, } = range; - call_if_true!( - DEBUG_TUI_COPY_PASTE, - log_debug(format!( - "\nπŸ•πŸ•πŸ• {0}:\n\t{1}: {2}, {3}: {4}\n\t{5}: {6}, {7}: {8}\n\t{9}: {10}, {11}: {12}, {13}: {14}", - /* 0 */ "modify_existing_range_at_row_index", - /* 1 */ "range_start", - /* 2 */ range_start, - /* 3 */ "range_end", - /* 4 */ range_end, - /* 5 */ "previous", - /* 6 */ previous, - /* 7 */ "current", - /* 8 */ current, - /* 9 */ "previous", - /* 10 */ format!("{:?}", range.locate_column(previous)).black().on_dark_yellow(), - /* 11 */ "current", - /* 12 */ format!("{:?}", range.locate_column(current)).black().on_dark_cyan(), - /* 13 */ "direction", - /* 14 */ - format!( - "{:?}", - SelectionRange::caret_movement_direction_left_right(previous, current) + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!( + "\nπŸ•πŸ•πŸ• {0}:\n\t{1}: {2}, {3}: {4}\n\t{5}: {6}, {7}: {8}\n\t{9}: {10}, {11}: {12}, {13}: {14}", + /* 0 */ "modify_existing_range_at_row_index", + /* 1 */ "range_start", + /* 2 */ range_start, + /* 3 */ "range_end", + /* 4 */ range_end, + /* 5 */ "previous", + /* 6 */ previous, + /* 7 */ "current", + /* 8 */ current, + /* 9 */ "previous", + /* 10 */ format!("{:?}", range.locate_column(previous)).black().on_dark_yellow(), + /* 11 */ "current", + /* 12 */ format!("{:?}", range.locate_column(current)).black().on_dark_cyan(), + /* 13 */ "direction", + /* 14 */ + format!( + "{:?}", + SelectionRange::caret_movement_direction_left_right(previous, current) + ) + .black() + .on_dark_green(), ) - .black() - .on_dark_green(), - )) - ); + }); // BOOKM: For reference, algo for left, right selection // Handle the movement of the caret and apply the appropriate changes to the range. @@ -231,7 +228,7 @@ impl EditorBufferApi { .has_caret_movement_direction_changed(caret_vertical_movement_direction); call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug(format!( + tracing::debug!( "\nπŸ“œπŸ“œπŸ“œ {0}\n\t{1}, {2}\n\t{3}\n\t{4}\n\t{5}\n\t{6}\n\t{7}", /* 0: heading */ "handle multiline caret movement" @@ -268,7 +265,7 @@ impl EditorBufferApi { ) .yellow() .on_dark_grey(), - )); + ) }); match ( @@ -386,9 +383,8 @@ impl EditorBufferApi { ), // Catchall. _ => { - call_if_true!( - DEBUG_TUI_COPY_PASTE, - log_debug(format!( + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!( "\nπŸ“œπŸ“œπŸ“œβšΎβšΎβšΎ {0}", /* 0: heading */ "handle multiline caret movement Catchall" @@ -396,8 +392,8 @@ impl EditorBufferApi { .bold() .yellow() .on_dark_green(), - )) - ); + ) + }); } } } @@ -485,7 +481,7 @@ impl EditorBufferApi { let (lines, _, _, selection_map) = editor_buffer.get_mut(); call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug(format!( + tracing::debug!( "\nπŸ“œπŸ”ΌπŸ”½ {0}\n\t{1}, {2}, {3}, {4}", /* 0 */ "handle multiline caret movement hit top or bottom of document" @@ -500,7 +496,7 @@ impl EditorBufferApi { format!("row_index: {}", row_index).green().on_dark_grey(), /* 4 */ format!("{:?}", selection_map).magenta().on_dark_grey(), - )) + ) }); match current.col_index.cmp(&previous.col_index) { diff --git a/tui/src/tui/editor/editor_buffer/editor_buffer_struct.rs b/tui/src/tui/editor/editor_buffer/editor_buffer_struct.rs index 081af559e..eaa403caa 100644 --- a/tui/src/tui/editor/editor_buffer/editor_buffer_struct.rs +++ b/tui/src/tui/editor/editor_buffer/editor_buffer_struct.rs @@ -22,7 +22,6 @@ use common_math::format_with_commas; use r3bl_rs_utils_core::{call_if_true, ch, common_math, - log_debug, position, ChUnit, Position, @@ -243,12 +242,12 @@ pub mod history { // Normal history insertion. editor_buffer.history.push_content(content_copy); - if DEBUG_TUI_COPY_PASTE { - log_debug(format!( + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!( "🍎🍎🍎 add_content_to_undo_stack editor_buffer: {:?}", editor_buffer - )); - } + ); + }); } pub fn undo(editor_buffer: &mut EditorBuffer) { @@ -261,9 +260,9 @@ pub mod history { editor_buffer.editor_content.caret_display_position = retain_caret_position; } - if DEBUG_TUI_COPY_PASTE { - log_debug(format!("🍎🍎🍎 undo editor_buffer: {:?}", editor_buffer)); - } + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!("🍎🍎🍎 undo editor_buffer: {:?}", editor_buffer); + }); } pub fn redo(editor_buffer: &mut EditorBuffer) { @@ -274,9 +273,9 @@ pub mod history { editor_buffer.editor_content = content; } - if DEBUG_TUI_COPY_PASTE { - log_debug(format!("🍎🍎🍎 redo editor_buffer: {:?}", editor_buffer)); - } + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!("🍎🍎🍎 redo editor_buffer: {:?}", editor_buffer); + }); } impl EditorBufferHistory { @@ -546,11 +545,9 @@ mod constructor { ) -> Self { // Potentially do any other initialization here. call_if_true!(DEBUG_TUI_MOD, { - let msg = format!( - "πŸͺ™ {}", - "construct EditorBuffer { lines, caret, lolcat, file_extension }" + tracing::debug!( + "πŸͺ™ construct EditorBuffer [ lines, caret, lolcat, file_extension ]" ); - log_debug(msg); }); Self { diff --git a/tui/src/tui/editor/editor_buffer/mod.rs b/tui/src/tui/editor/editor_buffer/mod.rs index 3ac326532..5996ecbaf 100644 --- a/tui/src/tui/editor/editor_buffer/mod.rs +++ b/tui/src/tui/editor/editor_buffer/mod.rs @@ -20,8 +20,11 @@ pub mod editor_buffer_clipboard_support; pub mod editor_buffer_selection_support; pub mod editor_buffer_struct; pub mod selection_map; +pub mod system_clipboard_service_provider; // Re-export. +pub use editor_buffer_clipboard_support::*; pub use editor_buffer_selection_support::*; pub use editor_buffer_struct::*; pub use selection_map::*; +pub use system_clipboard_service_provider::*; \ No newline at end of file diff --git a/tui/src/tui/editor/editor_buffer/system_clipboard_service_provider.rs b/tui/src/tui/editor/editor_buffer/system_clipboard_service_provider.rs new file mode 100644 index 000000000..f5db59adb --- /dev/null +++ b/tui/src/tui/editor/editor_buffer/system_clipboard_service_provider.rs @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 R3BL LLC + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use copypasta_ext::{copypasta::ClipboardProvider, x11_fork::ClipboardContext}; +use crossterm::style::Stylize; +use r3bl_rs_utils_core::{call_if_true, throws}; + +use super::{ClipboardResult, ClipboardService}; +use crate::DEBUG_TUI_COPY_PASTE; + +pub struct SystemClipboard; + +impl ClipboardService for SystemClipboard { + fn try_to_put_content_into_clipboard( + &mut self, + content: String, + ) -> ClipboardResult<()> { + throws!({ + let mut ctx = ClipboardContext::new()?; + ctx.set_contents(content.clone())?; + + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!( + "\nπŸ“‹πŸ“‹πŸ“‹ Selected Text was copied to clipboard: \n{}", + format!("{content}").black().on_green(), + ); + }); + }) + } + + fn try_to_get_content_from_clipboard(&mut self) -> ClipboardResult { + let mut ctx = ClipboardContext::new()?; + let content = ctx.get_contents()?; + + Ok(content) + } +} + +pub mod test_fixtures { + use super::{ClipboardResult, ClipboardService}; + + #[derive(Debug, Default)] + pub struct TestClipboard { + pub content: String, + } + + impl ClipboardService for TestClipboard { + fn try_to_put_content_into_clipboard( + &mut self, + content: String, + ) -> ClipboardResult<()> { + self.content = content; + Ok(()) + } + + fn try_to_get_content_from_clipboard(&mut self) -> ClipboardResult { + Ok(self.content.clone()) + } + } +} diff --git a/tui/src/tui/editor/editor_component/editor_component_struct.rs b/tui/src/tui/editor/editor_component/editor_component_struct.rs index bf7ca46f7..3961ad1d6 100644 --- a/tui/src/tui/editor/editor_component/editor_component_struct.rs +++ b/tui/src/tui/editor/editor_component/editor_component_struct.rs @@ -20,8 +20,7 @@ use std::fmt::Debug; use r3bl_rs_utils_core::{throws_with_return, CommonResult}; use tokio::sync::mpsc::Sender; -use crate::{editor_buffer_clipboard_support::system_clipboard_service_provider::SystemClipboard, - BoxedSafeComponent, +use crate::{BoxedSafeComponent, Component, EditorBuffer, EditorEngine, @@ -37,6 +36,7 @@ use crate::{editor_buffer_clipboard_support::system_clipboard_service_provider:: InputEvent, RenderPipeline, SurfaceBounds, + SystemClipboard, TerminalWindowMainThreadSignal, DEFAULT_SYN_HI_FILE_EXT}; diff --git a/tui/src/tui/editor/editor_component/editor_event.rs b/tui/src/tui/editor/editor_component/editor_event.rs index 3dc03f9c9..ad496f68b 100644 --- a/tui/src/tui/editor/editor_component/editor_event.rs +++ b/tui/src/tui/editor/editor_component/editor_event.rs @@ -18,7 +18,7 @@ use std::fmt::Debug; use crossterm::style::Stylize; -use r3bl_rs_utils_core::{call_if_true, log_debug, Size}; +use r3bl_rs_utils_core::{call_if_true, Size}; use serde::{Deserialize, Serialize}; use crate::{editor_buffer::EditorBuffer, @@ -89,10 +89,10 @@ impl TryFrom for EditorEvent { fn try_from(input_event: InputEvent) -> Result { call_if_true!(DEBUG_TUI_COPY_PASTE, { - log_debug(format!( + tracing::debug!( "\nπŸ₯πŸ₯πŸ₯ EditorEvent::try_from: {}", - format!("{}", input_event).red().on_white() - )); + format!("{input_event}").red().on_white() + ); }); match input_event { diff --git a/tui/src/tui/editor/editor_engine/editor_engine_api.rs b/tui/src/tui/editor/editor_engine/editor_engine_api.rs index 369545a02..e98a50036 100644 --- a/tui/src/tui/editor/editor_engine/editor_engine_api.rs +++ b/tui/src/tui/editor/editor_engine/editor_engine_api.rs @@ -18,7 +18,6 @@ use crossterm::style::Stylize; use r3bl_rs_utils_core::{call_if_true, ch, - log_debug, position, throws, throws_with_return, @@ -241,9 +240,8 @@ impl EditorEngineApi { // BOOKM: Render using syntect first, then custom MD parser. - call_if_true!( - DEBUG_TUI_MOD, - log_debug(format!( + call_if_true!(DEBUG_TUI_MOD, { + tracing::debug!( "\nπŸ‰πŸ‰πŸ‰\n\t{0}\n\t{1}\n\t{2}\nπŸ‰πŸ‰πŸ‰", /* 0 */ format!( @@ -266,8 +264,8 @@ impl EditorEngineApi { ) .to_string() .green(), - )) - ); + ) + }); match editor_buffer.is_file_extension_default() { // Render using custom MD parser. @@ -331,15 +329,14 @@ impl EditorEngineApi { } }; - call_if_true!( - DEBUG_TUI_COPY_PASTE, - log_debug(format!( - "\nπŸ‰πŸ‰πŸ‰ selection_str_slice: \n\t{0}, \n\trange: {1}, \n\tscroll_offset: {2}", - /* 0 */ selection.to_string().black().on_white(), - /* 1 */ range_of_display_col_indices, - /* 2 */ scroll_offset, - )) - ); + call_if_true!(DEBUG_TUI_COPY_PASTE, { + tracing::debug!( + "\nπŸ‰πŸ‰πŸ‰ selection_str_slice: \n\t{0}, \n\trange: {1}, \n\tscroll_offset: {2}", + /* 0 */ selection.to_string().black().on_white(), + /* 1 */ range_of_display_col_indices, + /* 2 */ scroll_offset, + ) + }); let position = { // Convert scroll adjusted to raw. @@ -518,13 +515,13 @@ mod syn_hi_r3bl_path { )?; call_if_true!(DEBUG_TUI_SYN_HI, { - log_debug(format!( + tracing::debug!( "\n🎯🎯🎯\neditor_buffer.lines.len(): {} vs md_document.lines.len(): {}\n{}\n{}🎯🎯🎯", editor_buffer.get_lines().len().to_string().cyan(), lines.len().to_string().yellow(), editor_buffer.get_as_string_with_comma_instead_of_newlines().cyan(), lines.pretty_print_debug().yellow(), - )); + ) }); for (row_index, line) in lines diff --git a/tui/src/tui/editor/test_editor.rs b/tui/src/tui/editor/test_editor.rs index 7e8361c6f..ffe567afb 100644 --- a/tui/src/tui/editor/test_editor.rs +++ b/tui/src/tui/editor/test_editor.rs @@ -19,7 +19,7 @@ mod test_config_options { use r3bl_rs_utils_core::{assert_eq2, position, UnicodeString}; - use crate::{editor_buffer_clipboard_support::test_clipboard_service_provider::TestClipboard, + use crate::{system_clipboard_service_provider::test_fixtures::TestClipboard, test_fixtures::mock_real_objects_for_editor, CaretDirection, CaretKind, @@ -145,7 +145,7 @@ mod test_config_options { mod test_editor_ops { use r3bl_rs_utils_core::{assert_eq2, ch, position, size, UnicodeString}; - use crate::{editor_buffer_clipboard_support::test_clipboard_service_provider::TestClipboard, + use crate::{system_clipboard_service_provider::test_fixtures::TestClipboard, test_fixtures::{assert, mock_real_objects_for_editor}, CaretDirection, CaretKind, @@ -1649,7 +1649,7 @@ mod selection_tests { use r3bl_rs_utils_core::{assert_eq2, ch, SelectionRange}; - use crate::{editor_buffer_clipboard_support::test_clipboard_service_provider::TestClipboard, + use crate::{system_clipboard_service_provider::test_fixtures::TestClipboard, test_fixtures::mock_real_objects_for_editor, CaretDirection, EditorBuffer, @@ -1883,7 +1883,7 @@ mod selection_tests { mod clipboard_tests { use r3bl_rs_utils_core::{assert_eq2, UnicodeString}; - use crate::{editor_buffer_clipboard_support::test_clipboard_service_provider::TestClipboard, + use crate::{system_clipboard_service_provider::test_fixtures::TestClipboard, test_fixtures::mock_real_objects_for_editor, CaretDirection, EditorBuffer, diff --git a/tui/src/tui/md_parser/fragment/parse_fragments_in_a_line.rs b/tui/src/tui/md_parser/fragment/parse_fragments_in_a_line.rs index 999c57ab9..eeafee6d3 100644 --- a/tui/src/tui/md_parser/fragment/parse_fragments_in_a_line.rs +++ b/tui/src/tui/md_parser/fragment/parse_fragments_in_a_line.rs @@ -29,7 +29,7 @@ use crossterm::style::Stylize; use nom::{branch::alt, combinator::map, IResult}; -use r3bl_rs_utils_core::{call_if_true, log_debug}; +use r3bl_rs_utils_core::call_if_true; use crate::{parse_fragment_plain_text_no_new_line, parse_fragment_starts_with_backtick_err_on_new_line, @@ -94,10 +94,14 @@ pub fn parse_inline_fragments_until_eol_or_eoi( }; call_if_true!(DEBUG_MD_PARSER, { - log_debug(format!("\nπŸ“£πŸ“£πŸ“£\n input: {:?}", input).green().to_string()); + tracing::debug!("\nπŸ“£πŸ“£πŸ“£\n input: {}", format!("{input:?}").green()); match it { - Ok(ref element) => log_debug(format!("βœ…βœ…βœ… OK {:#?}", element).magenta().to_string()), - Err(ref error) => log_debug(format!("πŸŸ₯πŸŸ₯πŸŸ₯ NO {:#?}", error)), + Ok(ref element) => { + tracing::debug!("βœ…βœ…βœ… OK {}", format!("{element:#?}").magenta()); + }, + Err(ref error) => { + tracing::debug!("πŸŸ₯πŸŸ₯πŸŸ₯ NO {}", format!("{error:#?}").red()); + }, } }); diff --git a/tui/src/tui/terminal_lib_backends/render_pipeline_to_offscreen_buffer.rs b/tui/src/tui/terminal_lib_backends/render_pipeline_to_offscreen_buffer.rs index 7dd69e4fb..8df45396e 100644 --- a/tui/src/tui/terminal_lib_backends/render_pipeline_to_offscreen_buffer.rs +++ b/tui/src/tui/terminal_lib_backends/render_pipeline_to_offscreen_buffer.rs @@ -17,7 +17,6 @@ use r3bl_rs_utils_core::{call_if_true, ch, - log_debug, ChUnit, CommonError, CommonErrorType, @@ -61,8 +60,7 @@ impl RenderPipeline { } call_if_true!(DEBUG_TUI_COMPOSITOR, { - let msg = format!("offscreen_buffer: \n🌟🌟🌟\n{my_offscreen_buffer:#?}"); - log_debug(msg); + tracing::debug!("offscreen_buffer: \n🌟🌟🌟\n{my_offscreen_buffer:#?}"); }); my_offscreen_buffer @@ -175,7 +173,7 @@ pub fn print_plain_text( } call_if_true!(DEBUG_TUI_COMPOSITOR, { - let msg = format!( + tracing::debug!( "\nπŸš€πŸš€πŸš€ print_plain_text(): insertion at: display_row_index: {}, display_col_index: {}, window_size: {:?}, text: '{}', @@ -186,7 +184,6 @@ pub fn print_plain_text( text.string, text.display_width ); - log_debug(msg); }); // Try to get the line at `row_index`. @@ -233,15 +230,13 @@ pub fn print_plain_text( call_if_true!( DEBUG_TUI_COMPOSITOR, if maybe_style.is_some() { - let msg = format!( + tracing::debug!( "\nπŸ”΄πŸ”΄πŸ”΄\n[row: {display_row_index}, col: {display_col_index}] - style: {maybe_style:?}", ); - log_debug(msg); } else { - let msg = format!( + tracing::debug!( "\n🟣🟣🟣\n[row: {display_row_index}, col: {display_col_index}] - style: None", ); - log_debug(msg); } ); diff --git a/tuify/examples/main_interactive.rs b/tuify/examples/main_interactive.rs index 7c07066a9..bc282c8b6 100644 --- a/tuify/examples/main_interactive.rs +++ b/tuify/examples/main_interactive.rs @@ -18,10 +18,7 @@ use std::{io::Result, vec}; use r3bl_ansi_color::{AnsiStyledText, Color, Style as RStyle}; -use r3bl_rs_utils_core::{call_if_true, - log_debug, - throws, - try_initialize_global_logging}; +use r3bl_rs_utils_core::{call_if_true, throws, try_initialize_global_logging}; use r3bl_tuify::{components::style::StyleSheet, get_size, get_terminal_width, @@ -36,8 +33,7 @@ fn main() -> Result<()> { throws!({ call_if_true!(DEVELOPMENT_MODE, { try_initialize_global_logging(tracing_core::LevelFilter::DEBUG).ok(); - log_debug("Start logging...".to_string()); - log_debug(format!("terminal window size: {:?}", get_size()?).to_string()); + tracing::debug!("Start logging... terminal window size: {:?}", get_size()?) }); // Get display size. @@ -136,7 +132,7 @@ fn main() -> Result<()> { } call_if_true!(DEVELOPMENT_MODE, { - log_debug("Stop logging...".to_string()); + tracing::debug!("Stop logging..."); }); }); } @@ -222,7 +218,7 @@ fn single_line_header() { None => println!("User did not select anything"), } call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("user_input: {:?}", user_input).to_string()); + tracing::debug!("user_input: {user_input:?}"); }); } @@ -302,7 +298,7 @@ fn multiple_select_13_items_vph_5( None => println!("User did not select anything"), } call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("user_input: {:?}", user_input).to_string()); + tracing::debug!("user_input: {user_input:?}"); }); } @@ -341,7 +337,7 @@ fn multiple_select_2_items_vph_5( None => println!("User did not select anything"), } call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("user_input: {:?}", user_input).to_string()); + tracing::debug!("user_input: {user_input:?}"); }); } @@ -383,7 +379,7 @@ fn single_select_13_items_vph_5( None => println!("User did not select anything"), } call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("user_input: {:?}", user_input).to_string()); + tracing::debug!("user_input: {user_input:?}"); }); } @@ -421,7 +417,7 @@ fn single_select_2_items_vph_5( None => println!("User did not select anything"), } call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("user_input: {:?}", user_input).to_string()); + tracing::debug!("user_input: {user_input:?}"); }); } diff --git a/tuify/src/bin/rt.rs b/tuify/src/bin/rt.rs index f9277b25e..ff1faea1e 100644 --- a/tuify/src/bin/rt.rs +++ b/tuify/src/bin/rt.rs @@ -23,10 +23,7 @@ use std::{io::{stdin, BufRead, Result}, use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum}; use crossterm::style::Stylize; -use r3bl_rs_utils_core::{call_if_true, - log_debug, - throws, - try_initialize_global_logging}; +use r3bl_rs_utils_core::{call_if_true, throws, try_initialize_global_logging}; use r3bl_tuify::{get_size, get_terminal_width, is_stdin_piped, @@ -104,9 +101,8 @@ fn main() -> Result<()> { call_if_true!(enable_logging, { try_initialize_global_logging(tracing_core::LevelFilter::DEBUG).ok(); - log_debug("Start logging...".to_string()); - log_debug(format!("terminal window size: {:?}", get_size()?).to_string()); - log_debug(format!("cli_args {:?}", cli_args)); + tracing::debug!("Start logging... terminal window size: {:?}", get_size()?); + tracing::debug!("cli_args {cli_args:?}") }); match cli_args.command { @@ -158,7 +154,7 @@ fn main() -> Result<()> { } } call_if_true!(enable_logging, { - log_debug("Stop logging...".to_string()); + tracing::debug!("Stop logging..."); }); }); } @@ -205,7 +201,7 @@ fn show_tui( .collect::>(); call_if_true!(enable_logging, { - log_debug(format!("lines: {:?}", lines)); + tracing::debug!("lines: {lines:?}"); }); // Early return, nothing to do. No content found in stdin. @@ -303,11 +299,7 @@ fn show_tui( }; call_if_true!(enable_logging, { - log_debug( - format!("selected_items: {:?}", selected_items) - .cyan() - .to_string(), - ); + tracing::debug!("selected_items: {}", format!("{selected_items:?}").cyan()); }); for selected_item in selected_items { @@ -402,13 +394,9 @@ fn get_possible_values_for_subcommand_and_option( .collect::>(); call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!( - "{subcommand}, {option} - possible_values: {:?}", - possible_values - ) - .green() - .to_string(), + tracing::debug!( + "{subcommand}, {option} - possible_values: {}", + format!("{possible_values:?}").green() ); }); diff --git a/tuify/src/components/select_component.rs b/tuify/src/components/select_component.rs index a0ec602ab..95ee84774 100644 --- a/tuify/src/components/select_component.rs +++ b/tuify/src/components/select_component.rs @@ -27,7 +27,7 @@ use crossterm::{cursor::{MoveToColumn, MoveToNextLine, MoveToPreviousLine}, Stylize}, terminal::{Clear, ClearType}}; use r3bl_ansi_color::AnsiStyledText; -use r3bl_rs_utils_core::{call_if_true, ch, log_debug, throws, ChUnit, UnicodeString}; +use r3bl_rs_utils_core::{call_if_true, ch, throws, ChUnit, UnicodeString}; use crate::{apply_style, get_crossterm_color_based_on_terminal_capabilities, @@ -114,14 +114,14 @@ impl FunctionComponent> for SelectComponent { }; call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!( - "🍎🍎🍎\n render()::state: \n\t[raw_caret_row_index: {}, scroll_offset_row_index: {}], \n\theader_viewport_height: {}, items_viewport_height:{}, viewport_width:{}", - state.raw_caret_row_index, state.scroll_offset_row_index, header_viewport_height, items_viewport_height, viewport_width - ) - .blue() - .to_string(), - ); + tracing::debug!( + "🍎🍎🍎\n render()::state: \n\t[raw_caret_row_index: {}, scroll_offset_row_index: {}], \n\theader_viewport_height: {}, items_viewport_height:{}, viewport_width:{}", + format!("{}", state.raw_caret_row_index).blue(), + format!("{}", state.scroll_offset_row_index).blue(), + format!("{}", header_viewport_height).blue(), + format!("{}", items_viewport_height).blue(), + format!("{}", viewport_width).blue() + ); }); self.allocate_viewport_height_space(state)?; diff --git a/tuify/src/function_component.rs b/tuify/src/function_component.rs index 95162ebd3..8affefce4 100644 --- a/tuify/src/function_component.rs +++ b/tuify/src/function_component.rs @@ -20,7 +20,7 @@ use std::io::{Result, Write}; use crossterm::{cursor::{MoveToNextLine, MoveToPreviousLine}, queue, terminal::{Clear, ClearType}}; -use r3bl_rs_utils_core::{call_if_true, log_debug, throws, ChUnit, Size}; +use r3bl_rs_utils_core::{call_if_true, throws, ChUnit, Size}; use crate::{ResizeHint, DEVELOPMENT_MODE}; @@ -64,10 +64,7 @@ pub trait FunctionComponent { fn clear_viewport_for_resize(&mut self, state: &mut S) -> Result<()> { throws!({ call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!( - "\nπŸ₯‘πŸ₯‘πŸ₯‘\nresize hint: {:?}", - state.get_resize_hint() - )); + tracing::debug!("\nπŸ₯‘πŸ₯‘πŸ₯‘\nresize hint: {:?}", state.get_resize_hint()); }); let viewport_height = match state.get_resize_hint() { diff --git a/tuify/src/keypress.rs b/tuify/src/keypress.rs index 63920a0a5..e85354cc4 100644 --- a/tuify/src/keypress.rs +++ b/tuify/src/keypress.rs @@ -22,7 +22,7 @@ use crossterm::event::{read, KeyEventKind, KeyEventState, KeyModifiers}; -use r3bl_rs_utils_core::{call_if_true, ch, log_debug, Size}; +use r3bl_rs_utils_core::{call_if_true, ch, Size}; use crate::DEVELOPMENT_MODE; @@ -64,7 +64,7 @@ fn read_key_press_unix() -> KeyPress { match result_event { Ok(event) => { call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("got event: {:?}", event).to_string()); + tracing::debug!("got event: {event:?}"); }); match event { @@ -109,7 +109,7 @@ fn read_key_press_windows() -> KeyPress { match result_event { Ok(event) => { call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!("got event: {:?}", event).to_string()); + tracing::debug!("got event: {event:?}"); }); match event { diff --git a/tuify/src/public_api.rs b/tuify/src/public_api.rs index 57eaaf4ba..a0b3e685a 100644 --- a/tuify/src/public_api.rs +++ b/tuify/src/public_api.rs @@ -20,7 +20,7 @@ use std::io::stdout; use clap::ValueEnum; use crossterm::style::Stylize; use r3bl_ansi_color::AnsiStyledText; -use r3bl_rs_utils_core::{call_if_true, ch, log_debug, Size}; +use r3bl_rs_utils_core::{call_if_true, ch, Size}; use crate::{enter_event_loop, get_size, @@ -151,13 +151,9 @@ fn sanitize_height(items: &[String], requested_height: usize) -> usize { fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResult { call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!( - "πŸ”†πŸ”†πŸ”† *before* keypress: locate_cursor_in_viewport(): {:?}", - state.locate_cursor_in_viewport() - ) - .magenta() - .to_string(), + tracing::debug!( + "πŸ”†πŸ”†πŸ”† *before* keypress: locate_cursor_in_viewport(): {}", + format!("{:?}", state.locate_cursor_in_viewport()).magenta() ); }); @@ -170,11 +166,11 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu row_count, }) => { call_if_true!(DEVELOPMENT_MODE, { - let msg = format!( + tracing::debug!( "\n🍎🍎🍎\nNew size width:{} x height:{}", - col_count, row_count + format!("{col_count}").green(), + format!("{row_count}").green(), ); - log_debug(msg.red().to_string()); }); state.set_resize_hint(Size { col_count, @@ -186,7 +182,7 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Down. KeyPress::Down => { call_if_true!(DEVELOPMENT_MODE, { - log_debug("Down".black().bold().on_green().to_string()); + tracing::debug!("Down"); }); let caret_location = state.locate_cursor_in_viewport(); match caret_location { @@ -208,10 +204,9 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu } } call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!("enter_event_loop()::state: {:?}", state) - .blue() - .to_string(), + tracing::debug!( + "enter_event_loop()::state: {}", + format!("{state:?}").blue() ); }); @@ -221,7 +216,7 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Up. KeyPress::Up => { call_if_true!(DEVELOPMENT_MODE, { - log_debug("Up".black().bold().on_green().to_string()); + tracing::debug!("Up"); }); match state.locate_cursor_in_viewport() { @@ -252,10 +247,9 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Enter on multi-select. KeyPress::Enter if selection_mode == SelectionMode::Multiple => { call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!("Enter: {:?}", state.selected_items) - .green() - .to_string(), + tracing::debug!( + "Enter: {}", + format!("{:?}", state.selected_items).green() ); }); if state.selected_items.is_empty() { @@ -268,10 +262,9 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Enter. KeyPress::Enter => { call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!("Enter: {}", state.get_focused_index()) - .green() - .to_string(), + tracing::debug!( + "Enter: {}", + format!("{:?}", state.get_focused_index()).green() ); }); let selection_index: usize = ch!(@to_usize state.get_focused_index()); @@ -285,7 +278,7 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Escape or Ctrl + c. KeyPress::Esc | KeyPress::CtrlC => { call_if_true!(DEVELOPMENT_MODE, { - log_debug("Esc".red().to_string()); + tracing::debug!("Esc"); }); EventLoopResult::ExitWithoutResult } @@ -293,10 +286,9 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Space on multi-select. KeyPress::Space if selection_mode == SelectionMode::Multiple => { call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!("Space: {}", state.get_focused_index()) - .magenta() - .to_string(), + tracing::debug!( + "Space: {}", + format!("{:?}", state.get_focused_index()).magenta() ); }); let selection_index: usize = ch!(@to_usize state.get_focused_index()); @@ -322,7 +314,7 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Noop, default behavior on Space KeyPress::Noop | KeyPress::Space => { call_if_true!(DEVELOPMENT_MODE, { - log_debug("Noop".yellow().to_string()); + tracing::debug!("Noop"); }); EventLoopResult::Continue } @@ -330,20 +322,16 @@ fn keypress_handler(state: &mut State<'_>, key_press: KeyPress) -> EventLoopResu // Error. KeyPress::Error => { call_if_true!(DEVELOPMENT_MODE, { - log_debug("Exit with error".red().to_string()); + tracing::debug!("Exit with error"); }); EventLoopResult::ExitWithError } }; call_if_true!(DEVELOPMENT_MODE, { - log_debug( - format!( - "πŸ‘‰ *after* keypress: locate_cursor_in_viewport(): {:?}", - state.locate_cursor_in_viewport() - ) - .blue() - .to_string(), + tracing::debug!( + "πŸ‘‰ *after* keypress: locate_cursor_in_viewport(): {}", + format!("{:?}", state.locate_cursor_in_viewport()).blue() ); }); diff --git a/tuify/src/scroll.rs b/tuify/src/scroll.rs index 385ada81b..0fef093fa 100644 --- a/tuify/src/scroll.rs +++ b/tuify/src/scroll.rs @@ -61,7 +61,7 @@ //! ``` use crossterm::style::Stylize; -use r3bl_rs_utils_core::{call_if_true, ch, log_debug, ChUnit}; +use r3bl_rs_utils_core::{call_if_true, ch, ChUnit}; use crate::DEVELOPMENT_MODE; @@ -94,10 +94,14 @@ pub fn locate_cursor_in_viewport( get_scroll_adjusted_row_index(raw_caret_row_index, scroll_offset_row_index); call_if_true!(DEVELOPMENT_MODE, { - log_debug(format!( + tracing::debug!( "locate_cursor_in_viewport(): raw_caret_row_index: {}, scroll_offset_row_index: {}, abs_row_index: {}, display_height: {}, items_size: {}", - raw_caret_row_index, scroll_offset_row_index, abs_row_index, display_height, items_size - ).green().to_string()); + format!("{raw_caret_row_index}").green(), + format!("{scroll_offset_row_index}").green(), + format!("{abs_row_index}").green(), + format!("{display_height}").green(), + format!("{items_size}").green() + ); }); // Note the ordering of the statements below matters.