Skip to content

Commit

Permalink
refactor(core): re-export formatting symbols from cursive_core
Browse files Browse the repository at this point in the history
This should have been done from the beginning, since we operate on these symbols in several places for formatting. This would also help a migration away from `cursive`, since now only two modules have direct dependencies on `cursive`/`cursive_core`:

- git-branchless-lib for general output formatting.
- git-branchless-undo for the interactive undo UI.
  • Loading branch information
arxanas committed Jul 6, 2024
1 parent 235f224 commit 94889b3
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 77 deletions.
10 changes: 1 addition & 9 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion git-branchless-invoke/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ version = "0.9.0"
[dependencies]
clap = { workspace = true, features = ["derive"] }
color-eyre = { workspace = true }
cursive_core = { workspace = true }
eyre = { workspace = true }
git-branchless-opts = { workspace = true }
git2 = { workspace = true }
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-invoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ use std::path::PathBuf;
use std::time::SystemTime;

use clap::{CommandFactory, FromArgMatches, Parser};
use cursive_core::theme::BaseColor;
use cursive_core::utils::markup::StyledString;
use eyre::Context;
use git_branchless_opts::{ColorSetting, GlobalArgs};
use lib::core::config::env_vars::{get_git_exec_path, get_path_to_git};
use lib::core::effects::Effects;
use lib::core::formatting::Glyphs;
use lib::core::formatting::{BaseColor, Glyphs, StyledString};
use lib::git::GitRunInfo;
use lib::git::{Repo, RepoError};
use lib::util::{ExitCode, EyreExitOr};
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ chrono = { workspace = true }
color-eyre = { workspace = true }
concolor = { workspace = true }
console = { workspace = true }
cursive = { workspace = true }
cursive_core = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
futures = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions git-branchless-lib/src/core/check_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use std::ffi::{OsStr, OsString};
use std::fmt::Write;
use std::time::{SystemTime, UNIX_EPOCH};

use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use eyre::Context;
use itertools::Itertools;
use tracing::instrument;

use crate::core::config::get_auto_switch_branches;
use crate::core::formatting::{BaseColor, StyledString};
use crate::git::{
update_index, CategorizedReferenceName, GitRunInfo, MaybeZeroOid, NonZeroOid, ReferenceName,
Repo, Stage, UpdateIndexCommand, WorkingCopySnapshot,
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-lib/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ use std::ffi::OsString;
use std::fmt::Write;
use std::path::PathBuf;

use cursive::theme::{BaseColor, Effect, Style};
use cursive::utils::markup::StyledString;
use eyre::Context;
use tracing::{instrument, warn};

use crate::core::formatting::StyledStringBuilder;
use crate::core::formatting::{BaseColor, Effect, Style, StyledString, StyledStringBuilder};
use crate::git::{ConfigRead, GitRunInfo, GitRunOpts, Repo};

use super::effects::Effects;
Expand Down
7 changes: 3 additions & 4 deletions git-branchless-lib/src/core/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use std::fmt::Display;

use cursive::theme::{Effect, Style};
use cursive::utils::markup::StyledString;
use cursive::utils::span::Span;
pub use cursive_core::theme::{BaseColor, Color, ColorType, Effect, Style};
pub use cursive_core::utils::markup::StyledString;
pub use cursive_core::utils::span::Span;

/// Pluralize a quantity, as appropriate. Example:
///
Expand Down Expand Up @@ -369,7 +369,6 @@ fn render_style_as_ansi(content: &str, style: Style) -> eyre::Result<String> {
let Style { effects, color } = style;
let output = {
use console::style;
use cursive::theme::{BaseColor, Color, ColorType};
let output = content.to_string();
match color.front {
ColorType::Palette(_) => {
Expand Down
12 changes: 5 additions & 7 deletions git-branchless-lib/src/core/node_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::sync::{Arc, Mutex};
use std::time::SystemTime;

use bstr::{ByteSlice, ByteVec};
use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use lazy_static::lazy_static;
use regex::Regex;
use tracing::instrument;
Expand All @@ -18,15 +16,15 @@ use crate::core::config::{
get_commit_descriptors_branches, get_commit_descriptors_differential_revision,
get_commit_descriptors_relative_time,
};
use crate::core::eventlog::{Event, EventCursor, EventReplayer};
use crate::core::formatting::Glyphs;
use crate::core::formatting::{BaseColor, StyledString, StyledStringBuilder};
use crate::core::repo_ext::RepoReferencesSnapshot;
use crate::core::rewrite::find_rewrite_target;
use crate::git::{
CategorizedReferenceName, Commit, NonZeroOid, ReferenceName, Repo, ResolvedReferenceInfo,
};

use super::eventlog::{Event, EventCursor, EventReplayer};
use super::formatting::{Glyphs, StyledStringBuilder};
use super::repo_ext::RepoReferencesSnapshot;
use super::rewrite::find_rewrite_target;

/// An object which can be rendered in the smartlog.
#[derive(Clone, Debug)]
pub enum NodeObject<'repo> {
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-lib/src/git/object.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::path::Path;

use bstr::{BString, ByteSlice};
use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use git2::message_trailers_bytes;
use tracing::instrument;

use crate::core::formatting::{Glyphs, StyledStringBuilder};
use crate::core::formatting::{BaseColor, Glyphs, StyledString, StyledStringBuilder};
use crate::core::node_descriptors::{
render_node_descriptors, CommitMessageDescriptor, CommitOidDescriptor, NodeObject, Redactor,
};
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-lib/src/git/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ use std::{io, time};

use bstr::ByteVec;
use chrono::NaiveDateTime;
use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use git2::DiffOptions;
use itertools::Itertools;
use thiserror::Error;
use tracing::{instrument, warn};

use crate::core::effects::{Effects, OperationType};
use crate::core::eventlog::EventTransactionId;
use crate::core::formatting::Glyphs;
use crate::core::formatting::{BaseColor, Glyphs, StyledString};
use crate::git::config::{Config, ConfigRead};
use crate::git::object::Blob;
use crate::git::oid::{make_non_zero_oid, MaybeZeroOid, NonZeroOid};
Expand Down
1 change: 0 additions & 1 deletion git-branchless-navigation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repository = "https://github.com/arxanas/git-branchless"
version = "0.9.0"

[dependencies]
cursive = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-opts = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions git-branchless-navigation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use std::ffi::OsString;
use std::fmt::Write;
use std::time::SystemTime;

use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;

use lib::core::check_out::{check_out_commit, CheckOutCommitOptions, CheckoutTarget};
use lib::core::repo_ext::RepoExt;
use lib::util::{ExitCode, EyreExitOr};
Expand All @@ -32,7 +29,7 @@ use lib::core::config::get_next_interactive;
use lib::core::dag::{sorted_commit_set, CommitSet, Dag};
use lib::core::effects::Effects;
use lib::core::eventlog::{EventLogDb, EventReplayer};
use lib::core::formatting::Pluralize;
use lib::core::formatting::{BaseColor, Pluralize, StyledString};
use lib::core::node_descriptors::{
BranchesDescriptor, CommitMessageDescriptor, CommitOidDescriptor,
DifferentialRevisionDescriptor, NodeDescriptor, Redactor, RelativeTimeDescriptor,
Expand Down
2 changes: 0 additions & 2 deletions git-branchless-record/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ repository = "https://github.com/arxanas/git-branchless"
version = "0.9.0"

[dependencies]
cursive = { version = "0.20.0", default-features = false, features = [ "crossterm-backend", ] }
cursive_buffered_backend = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-invoke = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion git-branchless-smartlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repository = "https://github.com/arxanas/git-branchless"
version = "0.9.0"

[dependencies]
cursive_core = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-invoke = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions git-branchless-smartlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,13 @@ mod render {
use std::cmp::Ordering;
use std::collections::HashSet;

use cursive_core::theme::{BaseColor, Effect};
use cursive_core::utils::markup::StyledString;
use tracing::instrument;

use lib::core::dag::{CommitSet, Dag};
use lib::core::effects::Effects;
use lib::core::formatting::{set_effect, Pluralize};
use lib::core::formatting::{Glyphs, StyledStringBuilder};
use lib::core::formatting::{
set_effect, BaseColor, Effect, Glyphs, Pluralize, StyledString, StyledStringBuilder,
};
use lib::core::node_descriptors::{render_node_descriptors, NodeDescriptor};
use lib::git::{NonZeroOid, Repo};

Expand Down
1 change: 0 additions & 1 deletion git-branchless-submit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version = "0.9.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cursive_core = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-invoke = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions git-branchless-submit/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::env;
use std::fmt::{Debug, Write};
use std::hash::Hash;

use cursive_core::theme::Effect;
use cursive_core::utils::markup::StyledString;
use indexmap::IndexMap;
use itertools::Itertools;
use lib::core::config::get_main_branch_name;
Expand All @@ -15,6 +13,7 @@ use lib::core::dag::Dag;
use lib::core::effects::Effects;
use lib::core::effects::OperationType;
use lib::core::eventlog::EventLogDb;
use lib::core::formatting::{Effect, StyledString};
use lib::core::repo_ext::RepoExt;
use lib::core::repo_ext::RepoReferencesSnapshot;
use lib::git::CategorizedReferenceName;
Expand Down
3 changes: 1 addition & 2 deletions git-branchless-submit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::fmt::{Debug, Write};
use std::time::SystemTime;

use branch_forge::BranchForge;
use cursive_core::theme::{BaseColor, Effect, Style};
use git_branchless_invoke::CommandContext;
use git_branchless_test::{RawTestOptions, ResolvedTestOptions, Verbosity};
use github::GithubForge;
Expand All @@ -27,7 +26,7 @@ use lazy_static::lazy_static;
use lib::core::dag::{union_all, CommitSet, Dag};
use lib::core::effects::Effects;
use lib::core::eventlog::{EventLogDb, EventReplayer};
use lib::core::formatting::{Pluralize, StyledStringBuilder};
use lib::core::formatting::{BaseColor, Effect, Pluralize, Style, StyledStringBuilder};
use lib::core::repo_ext::{RepoExt, RepoReferencesSnapshot};
use lib::git::{GitRunInfo, NonZeroOid, Repo};
use lib::try_exit_code;
Expand Down
7 changes: 4 additions & 3 deletions git-branchless-submit/src/phabricator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::process::{Command, Stdio};
use std::str::FromStr;
use std::time::SystemTime;

use cursive_core::theme::Effect;
use cursive_core::utils::markup::StyledString;
use git_branchless_opts::Revset;
use git_branchless_test::{
run_tests, FixInfo, ResolvedTestOptions, TestOutput, TestResults, TestStatus,
Expand All @@ -21,7 +19,10 @@ use lib::core::check_out::CheckOutCommitOptions;
use lib::core::dag::{CommitSet, Dag};
use lib::core::effects::{Effects, OperationType, WithProgress};
use lib::core::eventlog::EventLogDb;
use lib::core::formatting::StyledStringBuilder;
use lib::core::formatting::{
Effect, StyledString,
StyledStringBuilder,
};
use lib::core::rewrite::{
execute_rebase_plan, BuildRebasePlanError, BuildRebasePlanOptions, ExecuteRebasePlanOptions,
ExecuteRebasePlanResult, RebasePlanBuilder, RebasePlanPermissions, RepoResource,
Expand Down
1 change: 0 additions & 1 deletion git-branchless-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ version = "0.9.0"
bstr = { workspace = true }
clap = { workspace = true }
crossbeam = { workspace = true }
cursive = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
fslock = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions git-branchless-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use std::time::SystemTime;
use bstr::ByteSlice;
use clap::ValueEnum;
use crossbeam::channel::{Receiver, RecvError};
use cursive::theme::{BaseColor, Effect, Style};
use cursive::utils::markup::StyledString;

use eyre::WrapErr;
use fslock::LockFile;
Expand All @@ -43,7 +41,10 @@ use lib::core::effects::{icons, Effects, OperationIcon, OperationType};
use lib::core::eventlog::{
EventLogDb, EventReplayer, EventTransactionId, BRANCHLESS_TRANSACTION_ID_ENV_VAR,
};
use lib::core::formatting::{Glyphs, Pluralize, StyledStringBuilder};
use lib::core::formatting::{
BaseColor, Effect, Glyphs, Pluralize, Style, StyledString,
StyledStringBuilder,
};
use lib::core::repo_ext::RepoExt;
use lib::core::rewrite::{
execute_rebase_plan, BuildRebasePlanOptions, ExecuteRebasePlanOptions, ExecuteRebasePlanResult,
Expand Down
Loading

0 comments on commit 94889b3

Please sign in to comment.