Skip to content

Commit

Permalink
[core, tui] Refactor Cargo.toml and remove syntect from core, change …
Browse files Browse the repository at this point in the history
…all ambiguous names to be explicit

This is an attempt to isolate the use of syntect to just 1 crate: r3bl_tui.
It has been removed from the core crate. However, it is not possible to remove
syntect from the lolcat / color_wheel modules as they are intrinsically tied
together. Basically, they need to be able to render output, and for that they
need to be in the r3bl_tui crate which has a dependency on syntect and this
can't be removed.

safemem is no longer maintained, you can see the following output from running
cargo deny check advisories.

180 │ safemem 0.3.3 registry+https://github.com/rust-lang/crates.io-index
    │ ------------------------------------------------------------------- unmaintained advisory detected
    │
    = ID: RUSTSEC-2023-0081
    = Advisory: https://rustsec.org/advisories/RUSTSEC-2023-0081
    = The latest crates.io release was in 2019. The repository has been archived by the author.
    = Announcement: https://github.com/abonander/safemem
    = Solution: No safe upgrade is available!
    = safemem v0.3.3
      └── line-wrap v0.1.1
          └── plist v1.6.0
              └── syntect v5.1.0
                  └── r3bl_tui v0.5.2
                      └── r3bl-cmdr v0.0.11

More info:
- #314
- ebarnard/rust-plist#134
- trishume/syntect#521

This `safemem` issue is resolved since the dependencies of syntect,
`line-wrap` and `plist` are both updated. By pinning the version of
`plist` to `1.6.1` (`cargo update -p plist --precise 1.6.1`) and
checking in `Cargo.toml`, this resolves the `safemem` issue.
  • Loading branch information
nazmulidris committed Apr 15, 2024
1 parent a53a462 commit 5d6772b
Show file tree
Hide file tree
Showing 93 changed files with 1,163 additions and 1,186 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"undos",
"uninteractive",
"unspecial",
"unstaged",
"withmutreturns",
"Zoey"
]
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

7 changes: 7 additions & 0 deletions analytics_schema/src/analytics_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub struct AnalyticsRecord {
pub events: Vec<AnalyticsEvent>,
}

impl Default for AnalyticsRecord {
fn default() -> Self {
Self::new()
}
}

impl AnalyticsRecord {
pub fn new() -> AnalyticsRecord {
let events = Vec::new();
Expand Down Expand Up @@ -53,6 +59,7 @@ pub struct AnalyticsEvent {
impl AnalyticsEvent {
/// This is meant to be called on the client, before the data is sent to the server.
/// The time is not set here since it will be set on the server-side.
#[allow(clippy::new_ret_no_self)]
pub fn new(
proxy_user_id: String,
proxy_machine_id: String,
Expand Down
2 changes: 2 additions & 0 deletions ansi_color/src/detect_color_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod global_color_support {
/// function. In any test in which this function is called, please use the `#[serial]`
/// attribute to annotate that test. Otherwise there will be flakiness in the test results
/// (tests are run in parallel using many threads).
#[allow(clippy::result_unit_err)]
pub fn set_override(value: ColorSupport) {
let it = i8::from(value);
unsafe { COLOR_SUPPORT_GLOBAL.store(it, Ordering::SeqCst) }
Expand All @@ -71,6 +72,7 @@ pub mod global_color_support {
/// - If the value has been set using [global_color_support::set_override], then that
/// value will be returned.
/// - Otherwise, an error will be returned.
#[allow(clippy::result_unit_err)]
pub fn try_get_override() -> Result<ColorSupport, ()> {
let it = unsafe { COLOR_SUPPORT_GLOBAL.load(Ordering::SeqCst) };
ColorSupport::try_from(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ use r3bl_rs_utils_core::{call_if_true,
CommonResult};
use reqwest::{Client, Response};

use crate::DEBUG_ANALYTICS_CLIENT_MOD;

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum AnalyticsAction {
GitiBranchDelete,
Expand All @@ -49,8 +47,8 @@ pub enum AnalyticsAction {
MachineIdProxyCreate,
}

impl AnalyticsAction {
pub fn to_string(&self) -> String {
impl std::fmt::Display for AnalyticsAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[rustfmt::skip]
let action = match self {
AnalyticsAction::GitiAppStart => "giti app start",
Expand All @@ -63,32 +61,34 @@ impl AnalyticsAction {
AnalyticsAction::EdiFileSave => "edi file save",
AnalyticsAction::MachineIdProxyCreate => "proxy machine id create",
};
action.to_string()
write!(f, "{}", action)
}
}

pub mod config_folder {
use std::fmt::{Display, Formatter, Result};

use super::*;
use crate::DEBUG_ANALYTICS_CLIENT_MOD;

pub enum ConfigPaths {
R3BLTopLevelFolderName,
ProxyMachineIdFile,
}

impl ConfigPaths {
pub fn to_string(&self) -> String {
impl Display for ConfigPaths {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let path = match self {
ConfigPaths::R3BLTopLevelFolderName => "r3bl-cmdr",
ConfigPaths::ProxyMachineIdFile => "id",
};
path.to_string()
write!(f, "{}", path)
}
}

/// This is where the config file is stored.
pub fn get_id_file_path(path: PathBuf) -> PathBuf {
let id_file_path = path.join(ConfigPaths::ProxyMachineIdFile.to_string());
id_file_path
path.join(ConfigPaths::ProxyMachineIdFile.to_string())
}

/// This is where the config folder is.
Expand Down Expand Up @@ -172,6 +172,7 @@ pub mod file_io {

pub mod proxy_machine_id {
use super::*;
use crate::DEBUG_ANALYTICS_CLIENT_MOD;

/// Read the file contents from [config_folder::get_id_file_path] and return it as a
/// string if it exists and can be read.
Expand All @@ -190,7 +191,7 @@ pub mod proxy_machine_id {
.to_string(),
);
});
return contents;
contents
}
Err(_) => {
let new_id = friendly_random_id::generate_friendly_random_id();
Expand Down Expand Up @@ -223,13 +224,11 @@ pub mod proxy_machine_id {
);
}
}
return new_id;
new_id
}
}
}
Err(_) => {
return friendly_random_id::generate_friendly_random_id();
}
Err(_) => friendly_random_id::generate_friendly_random_id(),
}
}
}
Expand Down Expand Up @@ -358,6 +357,7 @@ pub mod upgrade_check {

pub mod http_client {
use super::*;
use crate::DEBUG_ANALYTICS_CLIENT_MOD;

pub async fn make_get_request(url: &str) -> Result<Response, reqwest::Error> {
let client = Client::new();
Expand All @@ -371,15 +371,15 @@ pub mod http_client {
.to_string(),
);
});
return Ok(response);
Ok(response)
} else {
// Handle error response.
log_error(
format!("GET request failed: {response:#?}",)
.red()
.to_string(),
);
return response.error_for_status();
response.error_for_status()
}
}

Expand All @@ -398,15 +398,15 @@ pub mod http_client {
.to_string(),
);
});
return Ok(response);
Ok(response)
} else {
// Handle error response.
log_error(
format!("POST request failed: {response:#?}",)
.red()
.to_string(),
);
return response.error_for_status();
response.error_for_status()
}
}
}
24 changes: 0 additions & 24 deletions cmdr/src/analytics_client/mod.rs

This file was deleted.

11 changes: 5 additions & 6 deletions cmdr/src/bin/edi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ async fn main() -> CommonResult<()> {
);
launcher::run_app(Some(cli_arg.file_paths[0].clone())).await?;
}
_ => match edi_ui_templates::handle_multiple_files_not_supported_yet(cli_arg)
{
Some(file_path) => {
_ => {
if let Some(file_path) =
edi_ui_templates::handle_multiple_files_not_supported_yet(cli_arg)
{
report_analytics::start_task_to_generate_event(
"".to_string(),
AnalyticsAction::EdiFileOpenMultiple,
);
launcher::run_app(Some(file_path)).await?;
}
_ => {}
},
}
}

// Stop logging.
Expand All @@ -95,7 +95,6 @@ async fn main() -> CommonResult<()> {

pub mod edi_ui_templates {
use r3bl_ansi_color::{AnsiStyledText, Style};
use r3bl_cmdr::upgrade_check;
use r3bl_tuify::{select_from_list,
SelectionMode,
StyleSheet,
Expand Down
23 changes: 7 additions & 16 deletions cmdr/src/bin/giti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
//! <https://developerlife.com/2023/09/17/tuify-clap/>

use clap::Parser;
use giti::{branch::{checkout::try_checkout_branch, delete::try_delete_branch},
*};
use r3bl_ansi_color::{AnsiStyledText, Style};
use r3bl_cmdr::{color_constants::DefaultColors::{FrozenBlue, GuardsRed, MoonlightBlue},
giti::{self,
clap_config::clap_config::{BranchSubcommand,
CLIArg,
CLICommand}},
giti::{clap_config::*, *},
report_analytics,
upgrade_check,
AnalyticsAction};
Expand Down Expand Up @@ -107,7 +102,7 @@ pub fn launch_giti(cli_arg: CLIArg) {
);
log_error(err_msg.clone());
AnsiStyledText {
text: &format!("{err_msg}",),
text: &err_msg.to_string(),
style: &[Style::Foreground(GuardsRed.as_ansi_color())],
}
.println();
Expand All @@ -125,21 +120,17 @@ pub fn try_run_command(
..
} => match command_to_run_with_each_selection {
Some(subcommand) => match subcommand {
BranchSubcommand::Delete => return try_delete_branch(),
BranchSubcommand::Delete => try_delete_branch(),
BranchSubcommand::Checkout => {
return try_checkout_branch(maybe_branch_name.clone())
}
BranchSubcommand::New => {
return try_make_new_branch(maybe_branch_name.clone())
try_checkout_branch(maybe_branch_name.clone())
}
BranchSubcommand::New => try_make_new_branch(maybe_branch_name.clone()),
},
_ => {
return user_typed_giti_branch();
}
_ => user_typed_giti_branch(),
},
CLICommand::Commit {} => unimplemented!(),
CLICommand::Remote {} => unimplemented!(),
};
}
}

fn user_typed_giti_branch() -> CommonResult<CommandSuccessfulResponse> {
Expand Down

0 comments on commit 5d6772b

Please sign in to comment.