Skip to content

Commit

Permalink
fix: get rid of crossterm and crates dependent on it (#1710)
Browse files Browse the repository at this point in the history
* get rid of crossterm usage in Rust sources

* disable use gstuff::ISATTY in tests

* remove crossterm and dependent packages from dependencies

* update CHANGELOG.md

* add colored output for log

Co-authored-by: Onur <onurozkan.dev@outlook.com>

* add ANSI colors constants, add EOL at the end of log output

* fix clippy warnings

---------

Co-authored-by: Onur <onurozkan.dev@outlook.com>
Reviewed-by: ozkanonur <work@onurozkan.dev>, shamardy <shamardy@yahoo.com>
  • Loading branch information
DeckerSU and onur-ozkan authored Mar 14, 2023
1 parent 159b1b5 commit f8ded55
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 101 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- A bug was fixed in [#1706](https://github.com/KomodoPlatform/atomicDEX-API/pull/1706) where EVM swap transactions were failing if sent before the approval transaction confirmation.
- Tendermint account sequence problem due to running multiple instances were fixed in [#1694](https://github.com/KomodoPlatform/atomicDEX-API/pull/1694)
- Maker/taker pubkeys were added to new columns in `stats_swaps` table in [#1665](https://github.com/KomodoPlatform/atomicDEX-API/pull/1665)
- Get rid of unnecessary / old dependencies: `crossterm`, `crossterm_winapi`, `mio 0.7.13`, `miow`, `ntapi`, `signal-hook`, `signal-hook-mio` in [#1710](https://github.com/KomodoPlatform/atomicDEX-API/pull/1710)

## v1.0.0-beta - 2023-03-08

Expand Down
82 changes: 1 addition & 81 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions mm2src/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ web-sys = { version = "0.3.55", features = ["console", "CloseEvent", "DomExcepti
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
anyhow = "1.0"
chrono = "0.4"
crossterm = "0.20"
gstuff = { version = "0.7", features = ["crossterm", "nightly"] }
gstuff = { version = "0.7", features = ["nightly"] }
hyper = { version = "0.14.11", features = ["client", "http2", "server", "tcp"] }
# using webpki-tokio to avoid rejecting valid certificates
# got "invalid certificate: UnknownIssuer" for https://ropsten.infura.io on iOS using default-features
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ gstuff = { version = "0.7", features = ["nightly"] }
mm2_rpc = { path = "../mm2_rpc" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
gstuff = { version = "0.7", features = ["crossterm", "nightly"] }
gstuff = { version = "0.7", features = ["nightly"] }
2 changes: 1 addition & 1 deletion mm2src/mm2_io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ async-std = { version = "1.5", features = ["unstable"] }
gstuff = { version = "0.7", features = ["nightly"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
gstuff = { version = "0.7", features = ["crossterm", "nightly"] }
gstuff = { version = "0.7", features = ["nightly"] }
2 changes: 1 addition & 1 deletion mm2src/mm2_net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ js-sys = "0.3.27"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
hyper = { version = "0.14.11", features = ["client", "http2", "server", "tcp"] }
gstuff = { version = "0.7", features = ["crossterm", "nightly"] }
gstuff = { version = "0.7", features = ["nightly"] }
2 changes: 1 addition & 1 deletion mm2src/mm2_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ ser_error_derive = { path = "../derives/ser_error_derive" }
gstuff = { version = "0.7", features = ["nightly"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
gstuff = { version = "0.7", features = ["crossterm", "nightly"] }
gstuff = { version = "0.7", features = ["nightly"] }
3 changes: 1 addition & 2 deletions mm2src/mm2_test_helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ gstuff = { version = "0.7", features = ["nightly"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
chrono = "0.4"
crossterm = "0.20"
gstuff = { version = "0.7", features = ["crossterm", "nightly"] }
gstuff = { version = "0.7", features = ["nightly"] }
26 changes: 14 additions & 12 deletions mm2src/mm2_test_helpers/src/for_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use serde_json::{self as json, json, Value as Json};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::env;
use std::io::Write;
use std::net::IpAddr;
use std::num::NonZeroUsize;
use std::process::Child;
Expand All @@ -36,7 +37,6 @@ cfg_native! {
use bytes::Bytes;
use futures::channel::oneshot;
use futures::task::SpawnExt;
use gstuff::ISATTY;
use http::Request;
use regex::Regex;
use std::fs;
Expand Down Expand Up @@ -859,8 +859,9 @@ pub struct RaiiDump {
#[cfg(not(target_arch = "wasm32"))]
impl Drop for RaiiDump {
fn drop(&mut self) {
use crossterm::execute;
use crossterm::style::{Color, Print, SetForegroundColor};
const DARK_YELLOW_ANSI_CODE: &str = "\x1b[33m";
const YELLOW_ANSI_CODE: &str = "\x1b[93m";
const RESET_COLOR_ANSI_CODE: &str = "\x1b[0m";

// `term` bypasses the stdout capturing, we should only use it if the capturing was disabled.
let nocapture = env::args().any(|a| a == "--nocapture");
Expand All @@ -872,15 +873,16 @@ impl Drop for RaiiDump {
let log = String::from_utf8_lossy(&log);
let log = log.trim();

if let (true, true, mut stdout) = (nocapture, *ISATTY, std::io::stdout()) {
execute!(
stdout,
SetForegroundColor(Color::DarkYellow),
Print(format!("vvv {:?} vvv\n", self.log_path)),
SetForegroundColor(Color::Yellow),
Print(log),
)
.expect("Printing to stdout failed");
// If we want to determine is a tty or not here and write logs to stdout only if it's tty,
// we can use something like https://docs.rs/atty/latest/atty/ here, look like it's more cross-platform than gstuff::ISATTY .

if nocapture {
std::io::stdout()
.write_all(format!("{}vvv {:?} vvv\n", DARK_YELLOW_ANSI_CODE, self.log_path).as_bytes())
.expect("Printing to stdout failed");
std::io::stdout()
.write_all(format!("{}{}{}\n", YELLOW_ANSI_CODE, log, RESET_COLOR_ANSI_CODE).as_bytes())
.expect("Printing to stdout failed");
} else {
log!("vvv {:?} vvv\n{}", self.log_path, log);
}
Expand Down

0 comments on commit f8ded55

Please sign in to comment.