Skip to content

Commit

Permalink
[tui][core] Migrate color_wheel from tui to core/tui_core
Browse files Browse the repository at this point in the history
  • Loading branch information
nazmulidris committed Sep 25, 2024
1 parent 73fe4a3 commit 8dae43c
Show file tree
Hide file tree
Showing 37 changed files with 201 additions and 178 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,25 @@ in a text editor.

### next release

This is a major release that does not include any new functionality, but is a radical
reorganization of the crates. The reason for paying down this technical debt now is to
ensure that the codebase is easier to maintain and understand, and easier to add new
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.

- Changed:
- Refactor lots of styling related code in preparation for the move to `core`. This will
make it easier to maintain and test the codebase, and clean up the dependencies.

- Removed:
- 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,
making it easier to maintain. The reason they ended up in `r3bl_tui` in the first
place is because it was easier to develop them there, but since then, lots of other
consumers of this functionality have emerged, including crates that are created by
"3rd party developers" (people not R3BL and not part of `r3bl-open-core` repo).

### v0.5.9 (2024-09-12)

- Updated:
Expand Down Expand Up @@ -643,6 +658,12 @@ exhaustively tested and is able to handle many more corner cases.

### next release

This is a major release that does not include any new functionality, but is a radical
reorganization of the crates. The reason for paying down this technical debt now is to
ensure that the codebase is easier to maintain and understand, and easier to add new
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.

- Changed:
- Renamed 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
Expand All @@ -651,6 +672,15 @@ exhaustively tested and is able to handle many more corner cases.
- 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.

- Added:
- 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,
making it easier to maintain. The reason they ended up in `r3bl_tui` in the first
place is because it was easier to develop them there, but since then, lots of other
consumers of this functionality have emerged, including crates that are created by
"3rd party developers" (people not R3BL and not part of `r3bl-open-core` repo).

### v0.9.16 (2024-09-12)

- Updated:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions ansi_color/src/ansi256_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

use crate::{color_utils,
constants::ANSI_COLOR_PALETTE,
Color,
RgbColor,
TransformColor};
use crate::{color_utils,
constants::ANSI_COLOR_PALETTE,
Color,
RgbColor,
TransformColor};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Ansi256Color {
Expand Down
10 changes: 5 additions & 5 deletions ansi_color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,20 @@
#![warn(rust_2018_idioms)]

// Attach.
pub mod ansi256_color;
pub mod ansi_escape_codes;
pub mod ansi_styled_text;
pub mod color;
pub mod rgb_color;
pub mod ansi256_color;
pub mod convert;
pub mod detect_color_support;
pub mod rgb_color;
pub mod transform_color;

pub use ansi256_color::*;
pub use ansi_escape_codes::*;
pub use ansi_styled_text::*;
pub use color::*;
pub use rgb_color::*;
pub use ansi256_color::*;
pub use convert::*;
pub use detect_color_support::*;
pub use transform_color::*;
pub use rgb_color::*;
pub use transform_color::*;
2 changes: 1 addition & 1 deletion ansi_color/src/rgb_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::{convert_rgb_into_ansi256, Ansi256Color, TransformColor};
use crate::{convert_rgb_into_ansi256, Ansi256Color, TransformColor};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RgbColor {
Expand Down
2 changes: 1 addition & 1 deletion cmdr/src/bin/edi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use r3bl_rs_utils_core::{call_if_true,
log_debug,
throws,
try_to_set_log_level,
ColorWheel,
CommonResult,
GradientGenerationPolicy,
TextColorizationPolicy,
UnicodeString};
use r3bl_tui::ColorWheel;

use crate::clap_config::CLIArg;

Expand Down
6 changes: 3 additions & 3 deletions cmdr/src/edi/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ use r3bl_rs_utils_core::{call_if_true,
ANSIBasicColor,
Ansi256GradientIndex,
ChUnit,
ColorWheel,
ColorWheelConfig,
ColorWheelSpeed,
CommonError,
CommonResult,
GradientGenerationPolicy,
Expand All @@ -55,9 +58,6 @@ use r3bl_tui::{box_end,
surface,
App,
BoxedSafeApp,
ColorWheel,
ColorWheelConfig,
ColorWheelSpeed,
ComponentRegistry,
ComponentRegistryMap,
DialogBuffer,
Expand Down
2 changes: 1 addition & 1 deletion cmdr/src/giti/branch/giti_ui_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use std::{env::var, process::Command};

use r3bl_ansi_color::{AnsiStyledText, Color, Style};
use r3bl_rs_utils_core::{log_error,
ColorWheel,
CommonError,
CommonErrorType,
CommonResult,
GradientGenerationPolicy,
TextColorizationPolicy,
UnicodeString};
use r3bl_tui::ColorWheel;
use r3bl_tuify::SLATE_GRAY;

use crate::{giti::ui_strings::UIStrings::{ErrorExecutingCommand,
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ colorgrad = "0.7.0"
[dev-dependencies]
# for assert_eq! macro
pretty_assertions = "1.4.0"
serial_test = "3.1.1"
7 changes: 6 additions & 1 deletion core/src/logging/proper_logging_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
use std::{fs::File, sync::Once};

use chrono::Local;
use r3bl_simple_logger::{format_description, Config, ConfigBuilder, CombinedLogger, LevelFilter, WriteLogger};
use r3bl_simple_logger::{format_description,
CombinedLogger,
Config,
ConfigBuilder,
LevelFilter,
WriteLogger};
use time::UtcOffset;

use crate::{CommonError, CommonErrorType, CommonResult};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@
*/

use r3bl_ansi_color::AnsiStyledText;
use r3bl_rs_utils_core::{ch,
convert_tui_color_into_r3bl_ansi_color,
generate_random_truecolor_gradient,
generate_truecolor_gradient,
get_gradient_array_for,
tui_styled_text,
Ansi256GradientIndex,
AnsiValue,
ChUnit,
ColorUtils,
Defaults,
GradientGenerationPolicy,
GraphemeClusterSegment,
RgbValue,
TextColorizationPolicy,
TuiColor,
TuiStyle,
TuiStyledText,
TuiStyledTexts,
UnicodeString,
DEFAULT_GRADIENT_STOPS,
SPACER};
use serde::{Deserialize, Serialize};

use super::{ColorWheelConfig,
ColorWheelDirection,
ColorWheelSpeed,
GradientKind,
GradientLengthKind};
use crate::{ch,
convert_tui_color_into_r3bl_ansi_color,
generate_random_truecolor_gradient,
generate_truecolor_gradient,
get_gradient_array_for,
tui_styled_text,
Ansi256GradientIndex,
AnsiValue,
ChUnit,
ColorUtils,
Defaults,
GradientGenerationPolicy,
GraphemeClusterSegment,
RgbValue,
TextColorizationPolicy,
TuiColor,
TuiStyle,
TuiStyledText,
TuiStyledTexts,
UnicodeString,
DEFAULT_GRADIENT_STOPS,
SPACER};

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
pub struct ColorWheel {
Expand Down Expand Up @@ -422,7 +422,7 @@ impl ColorWheel {
text: &UnicodeString,
) -> TuiStyledTexts {
mod inner {
use r3bl_rs_utils_core::{TuiColor, TuiStyle};
use super::*;

// Inner function.
pub fn gen_style_fg_color_for(
Expand Down Expand Up @@ -603,10 +603,10 @@ impl ColorWheel {
#[cfg(test)]
mod tests_color_wheel_rgb {
use r3bl_ansi_color::{global_color_support, ColorSupport};
use r3bl_rs_utils_core::assert_eq2;
use serial_test::serial;

use super::*;
use crate::assert_eq2;

mod test_helpers {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/

use r3bl_ansi_color::{global_color_support, ColorSupport};
use r3bl_rs_utils_core::{Ansi256GradientIndex, TuiColor};
use serde::{Deserialize, Serialize};

use super::{Lolcat, LolcatBuilder};
use crate::{Ansi256GradientIndex, TuiColor};

/// For RGB colors:
/// 1. The stops are the colors that will be used to create the gradient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

use std::borrow::Cow;

use r3bl_rs_utils_core::{ColorChangeSpeed, TuiStyledTexts, UnicodeString};
use serde::{Deserialize, Serialize};

use super::Lolcat;
use crate::{ColorChangeSpeed, TuiStyledTexts, UnicodeString};

pub fn colorize_to_styled_texts(
lolcat: &mut Lolcat,
Expand Down Expand Up @@ -63,7 +63,6 @@ pub fn lolcat_each_char_in_unicode_string(
///
/// ```rust
/// use r3bl_rs_utils_core::*;
/// use r3bl_tui::*;
///
/// let mut lolcat = LolcatBuilder::new()
/// .set_color_change_speed(ColorChangeSpeed::Rapid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

use std::fmt::{Debug, Formatter, Result};

use r3bl_rs_utils_core::{tui_styled_text,
ColorUtils,
ColorWheelControl,
RgbValue,
TuiColor,
TuiStyle,
TuiStyledText,
TuiStyledTexts,
UnicodeString};
use serde::{Deserialize, Serialize};

use super::LolcatBuilder;
use crate::{tui_styled_text,
ColorUtils,
ColorWheelControl,
RgbValue,
TuiColor,
TuiStyle,
TuiStyledText,
TuiStyledTexts,
UnicodeString};

/// Please use the [LolcatBuilder] to create this struct (lots of documentation is provided here).
/// Please do not use this struct directly.
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions core/src/tui_core/color_wheel_core/color_wheel_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ impl Display for ColorChangeSpeed {
}

impl From<ColorChangeSpeed> for f64 {
/// The float is added to seed in [Lolcat] after every iteration. If
/// the number is `Rapid` then the changes in color between new lines is
/// quite abrupt. If it is `Slow` then the changes are much much smoother.
/// And so this is the default.
/// The float is added to seed in [crate::Lolcat] after every iteration. If the number
/// is `Rapid` then the changes in color between new lines is quite abrupt. If it is
/// `Slow` then the changes are much much smoother. And so this is the default.
fn from(value: ColorChangeSpeed) -> Self {
match value {
ColorChangeSpeed::Rapid => 1.0,
Expand Down
3 changes: 1 addition & 2 deletions core/src/tui_core/color_wheel_core/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ pub fn convert_tui_color_into_r3bl_ansi_color(color: TuiColor) -> r3bl_ansi_colo

#[cfg(test)]
mod tests_color_converter {
use crate::{ANSIBasicColor, AnsiValue, RgbValue, TuiColor};

use super::*;
use crate::{ANSIBasicColor, AnsiValue, RgbValue, TuiColor};

#[test]
fn test_convert_tui_color_into_r3bl_ansi_color_rgb() {
Expand Down
12 changes: 6 additions & 6 deletions core/src/tui_core/color_wheel_core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

// Attach sources.
pub mod ansi_256_color_gradients;
pub mod color_wheel_control;
pub mod color_utils;
pub mod truecolor_gradient;
pub mod color_wheel_control;
pub mod converter;
pub mod policies;
pub mod defaults;
pub mod policies;
pub mod truecolor_gradient;

// Re-export.
pub use ansi_256_color_gradients::*;
pub use color_wheel_control::*;
pub use color_utils::*;
pub use truecolor_gradient::*;
pub use color_wheel_control::*;
pub use converter::*;
pub use defaults::*;
pub use policies::*;
pub use defaults::*;
pub use truecolor_gradient::*;
2 changes: 1 addition & 1 deletion core/src/tui_core/dimens/ch_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub type ChUnitPrimitiveType = u16;
/// character in a monospace font.
/// - The terminal displaying the Rust binary build using the tui library will ultimately
/// determine the actual width and height of a character.
/// - In order to create amounts of ch units, use the [ch!] macro.
/// - In order to create amounts of ch units, use the [crate::ch!] macro.
#[derive(
Copy,
Clone,
Expand Down
Loading

0 comments on commit 8dae43c

Please sign in to comment.