From 1fec1a500868031a921619ec20a4f32de011996e Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 7 Oct 2023 23:00:28 -0400 Subject: [PATCH] windows cleanup --- Cargo.lock | 1 + veilid-cli/src/ui.rs | 96 +++++++++++-------- .../network_interfaces/sockaddr_tools.rs | 4 +- veilid-flutter/linux/rust.cmake | 13 ++- veilid-flutter/windows/rust.cmake | 13 ++- 5 files changed, 79 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0921220..0fcaf2e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5229,6 +5229,7 @@ dependencies = [ "async-std", "async-tungstenite", "cfg-if 1.0.0", + "chrono", "clap 4.4.4", "config", "crossbeam-channel", diff --git a/veilid-cli/src/ui.rs b/veilid-cli/src/ui.rs index 13e6126d..d8f07351 100644 --- a/veilid-cli/src/ui.rs +++ b/veilid-cli/src/ui.rs @@ -2,7 +2,6 @@ use crate::command_processor::*; use crate::peers_table_view::*; use crate::settings::Settings; use crate::tools::*; -use async_tungstenite::tungstenite::http::header::STRICT_TRANSPORT_SECURITY; use crossbeam_channel::Sender; use cursive::align::*; use cursive::event::*; @@ -15,12 +14,12 @@ use cursive::Cursive; use cursive::CursiveRunnable; use cursive_flexi_logger_view::{CursiveLogWriter, FlexiLoggerView}; // use cursive_multiplex::*; +use chrono::{Datelike, Timelike}; use std::collections::{HashMap, VecDeque}; use std::io::Write; +use std::sync::atomic::{AtomicU64, Ordering}; use std::time::{SystemTime, UNIX_EPOCH}; use thiserror::Error; -use std::sync::atomic::{AtomicU64, Ordering}; -use chrono::{Datelike, Timelike}; ////////////////////////////////////////////////////////////// /// @@ -52,8 +51,6 @@ impl Dirty { pub type UICallback = Box; - - static START_TIME: AtomicU64 = AtomicU64::new(0); struct UIState { @@ -357,7 +354,7 @@ impl UI { cursive_flexi_logger_view::parse_lines_to_log( ColorStyle::primary().into(), - format!("> {} {}", UI::cli_ts(Self::get_start_time()) , text), + format!("> {} {}", UI::cli_ts(Self::get_start_time()), text), ); match Self::run_command(s, text) { Ok(_) => {} @@ -365,7 +362,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Error).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(" {} Error: {}", UI::cli_ts(Self::get_start_time()), e) + format!(" {} Error: {}", UI::cli_ts(Self::get_start_time()), e), ); } } @@ -464,6 +461,31 @@ impl UI { Self::command_processor(s).start_connection(); } + fn copy_to_clipboard_osc52>(s: &mut Cursive, text: S) { + // OSC52 clipboard copy for terminals + if std::io::stdout() + .write_all( + format!( + "\x1B]52;c;{}\x07", + data_encoding::BASE64.encode(text.as_ref().as_bytes()), + ) + .as_bytes(), + ) + .is_ok() + && std::io::stdout().flush().is_ok() + { + let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); + cursive_flexi_logger_view::parse_lines_to_log( + color.into(), + format!( + ">> {} Copied: {}", + UI::cli_ts(Self::get_start_time()), + text.as_ref() + ), + ); + } + } + fn copy_to_clipboard>(s: &mut Cursive, text: S) { if let Ok(mut clipboard) = arboard::Clipboard::new() { // X11/Wayland/other system copy @@ -471,36 +493,24 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()), + format!( + ">> {} Copied: {}", + UI::cli_ts(Self::get_start_time()), + text.as_ref() + ), ); } else { let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> {} Could not copy to clipboard", UI::cli_ts(Self::get_start_time())) + format!( + ">> {} Could not copy to clipboard", + UI::cli_ts(Self::get_start_time()) + ), ); } } else { - // OSC52 clipboard copy for terminals - if std::io::stdout() - .write_all( - format!( - "\x1B]52;c;{}\x07", - data_encoding::BASE64.encode(text.as_ref().as_bytes()), - ) - .as_bytes(), - ) - .is_ok() - && std::io::stdout().flush().is_ok() - { - if std::io::stdout().flush().is_ok() { - let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); - cursive_flexi_logger_view::parse_lines_to_log( - color.into(), - format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()), - ); - } - } + Self::copy_to_clipboard_osc52(s, text) } } @@ -788,14 +798,11 @@ impl UI { } } - - //////////////////////////////////////////////////////////////////////////// // Public functions + #[allow(clippy::format_in_format_args)] pub fn cli_ts(ts: u64) -> String { - //let ts = get_timestamp(); - let now = chrono::DateTime::::from(SystemTime::now()); let date = chrono::DateTime::::from(UNIX_EPOCH + Duration::from_micros(ts)); @@ -806,17 +813,20 @@ impl UI { if show_year || show_month || show_date { UI::set_start_time(); } - format!("{}{}", + format!( + "{}{}", if show_year || show_month || show_date { - format!("Day changed: {:04}/{:02}/{:02} \n",now.year(), now.month(), now.day()) + format!( + "Day changed: {:04}/{:02}/{:02} \n", + now.year(), + now.month(), + now.day() + ) } else { "".to_owned() }, - format!("{:02}:{:02}:{:02}", - now.hour(), - now.minute(), - now.second() - )) + format!("{:02}:{:02}:{:02}", now.hour(), now.minute(), now.second()) + ) } pub fn set_start_time() { @@ -985,7 +995,6 @@ impl UI { // pub fn run(&mut self) { // self.siv.run(); // } - } type CallbackSink = Box; @@ -1088,7 +1097,10 @@ impl UISender { { let inner = self.inner.lock(); let color = *inner.log_colors.get(&log_color).unwrap(); - cursive_flexi_logger_view::parse_lines_to_log(color.into(), format!("{}: {}", UI::cli_ts(UI::get_start_time()), event)); + cursive_flexi_logger_view::parse_lines_to_log( + color.into(), + format!("{}: {}", UI::cli_ts(UI::get_start_time()), event), + ); } let _ = self.cb_sink.send(Box::new(UI::update_cb)); } diff --git a/veilid-core/src/intf/native/network_interfaces/sockaddr_tools.rs b/veilid-core/src/intf/native/network_interfaces/sockaddr_tools.rs index 8f3a5ef7..605c6c32 100644 --- a/veilid-core/src/intf/native/network_interfaces/sockaddr_tools.rs +++ b/veilid-core/src/intf/native/network_interfaces/sockaddr_tools.rs @@ -69,7 +69,7 @@ impl SockAddr { return None; } Some(IpAddr::V4(Ipv4Addr::new( - ((s_addr >> 0) & 255u32) as u8, + (s_addr & 255u32) as u8, ((s_addr >> 8) & 255u32) as u8, ((s_addr >> 16) & 255u32) as u8, ((s_addr >> 24) & 255u32) as u8, @@ -81,7 +81,7 @@ impl SockAddr { if s6_addr[0] == 0xfe && s6_addr[1] == 0x80 { return None; } - Some(IpAddr::V6(Ipv6Addr::from(s6_addr.clone()))) + Some(IpAddr::V6(Ipv6Addr::from(*s6_addr))) } None => None, } diff --git a/veilid-flutter/linux/rust.cmake b/veilid-flutter/linux/rust.cmake index 4ca71b16..5481f710 100644 --- a/veilid-flutter/linux/rust.cmake +++ b/veilid-flutter/linux/rust.cmake @@ -9,12 +9,21 @@ include(FetchContent) FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git - GIT_TAG origin/master # Optionally specify a version tag or branch here + GIT_TAG v0.4.4 # Optionally specify a version tag or branch here ) FetchContent_MakeAvailable(Corrosion) -corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/../../rust/Cargo.toml CRATES veilid-flutter) +execute_process(COMMAND git rev-parse --show-cdup + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE relative_path_to_repository_root) +string(STRIP ${relative_path_to_repository_root} relative_path_to_repository_root) + +get_filename_component(repository_root + "${CMAKE_SOURCE_DIR}/${relative_path_to_repository_root}" + ABSOLUTE) + +corrosion_import_crate(MANIFEST_PATH ${repository_root}/../veilid/Cargo.toml CRATES veilid-flutter) # Flutter-specific diff --git a/veilid-flutter/windows/rust.cmake b/veilid-flutter/windows/rust.cmake index 66c040e2..1d353d5e 100644 --- a/veilid-flutter/windows/rust.cmake +++ b/veilid-flutter/windows/rust.cmake @@ -9,12 +9,21 @@ include(FetchContent) FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git - GIT_TAG v0.2.1 # Optionally specify a version tag or branch here + GIT_TAG v0.4.4 # Optionally specify a version tag or branch here ) FetchContent_MakeAvailable(Corrosion) -corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/../../rust/Cargo.toml CRATES veilid-flutter FEATURES rt-tokio ) +execute_process(COMMAND git rev-parse --show-cdup + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE relative_path_to_repository_root) +string(STRIP ${relative_path_to_repository_root} relative_path_to_repository_root) + +get_filename_component(repository_root + "${CMAKE_SOURCE_DIR}/${relative_path_to_repository_root}" + ABSOLUTE) + +corrosion_import_crate(MANIFEST_PATH ${repository_root}/../veilid/Cargo.toml CRATES veilid-flutter) # Flutter-specific