Skip to content

Commit

Permalink
Split into features
Browse files Browse the repository at this point in the history
  • Loading branch information
azat committed Dec 20, 2023
1 parent e458e5a commit 0f1ecb3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

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

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ license = "MIT"
version = "0.5.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# TODO: convert this into feature set, but I'm not sure that it is easy right now (see [1]).
# [1]: https://github.com/rust-lang/cargo/issues/1197
[target.'cfg(not(target_family = "windows"))'.dependencies]
cursive = { version = "*", default-features = false, features = ["termion-backend"] }
skim = "*"
[target.'cfg(target_family = "windows")'.dependencies]
# crossterm backend does not support Alt-<Key> bindings (interpret as just <Key>)
cursive = { version = "*", default-features = false, features = ["crossterm-backend"] }

[dependencies]
# Basic
Expand Down Expand Up @@ -37,7 +44,6 @@ warp = "*"
clap = { version = "*", features = ["derive", "env"] }
clap_complete = { version = "*" }
# UI
cursive = { version = "*", default-features = false, features = ["termion-backend"] }
cursive_buffered_backend = "0.6.1"
cursive-syntect = "*"
# Patches:
Expand All @@ -47,7 +53,6 @@ cursive_table_view = { git = "https://github.com/azat-rust/cursive_table_view",
# - Fix for date format - https://github.com/deinstapel/cursive-flexi-logger-view/pull/13
cursive-flexi-logger-view = { git = "https://github.com/azat-rust/cursive-flexi-logger-view", branch = "next" }
syntect = "*"
skim = "*"
#
# Drivers
#
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod utils;

// utils
pub use utils::edit_query;
#[cfg(not(target_family = "windows"))]
pub use utils::fuzzy_actions;
pub use utils::highlight_sql;
pub use utils::open_graph_in_browser;
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ async fn main() -> Result<()> {
panic_hook(info);
}));

#[cfg(not(target_family = "windows"))]
let backend = cursive::backends::termion::Backend::init()?;
#[cfg(target_family = "windows")]
let backend = cursive::backends::crossterm::Backend::init()?;

let buffered_backend = Box::new(cursive_buffered_backend::BufferedBackend::new(backend));
let mut siv = cursive::CursiveRunner::new(cursive::Cursive::new(), buffered_backend);

Expand Down
7 changes: 5 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::ActionDescription;
use anyhow::{Context, Error, Result};
use cursive::utils::markup::StyledString;
use cursive_syntect;
use skim::prelude::*;
use std::collections::HashMap;
use std::env;
use std::fs;
Expand All @@ -12,13 +10,18 @@ use syntect::{highlighting::ThemeSet, parsing::SyntaxSet};
use tempfile::Builder;
use urlencoding::encode;

#[cfg(not(target_family = "windows"))]
use {crate::ActionDescription, skim::prelude::*};

#[cfg(not(target_family = "windows"))]
impl SkimItem for ActionDescription {
fn text(&self) -> Cow<str> {
return Cow::Borrowed(&self.text);
}
}

// TODO: render from the bottom
#[cfg(not(target_family = "windows"))]
pub fn fuzzy_actions(actions: Vec<ActionDescription>) -> Option<String> {
let options = SkimOptionsBuilder::default()
.height(Some("30%"))
Expand Down
4 changes: 4 additions & 0 deletions src/view/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
view,
};
use anyhow::Result;
#[cfg(not(target_family = "windows"))]
use chdig::fuzzy_actions;
use cursive::{
event::{Event, EventResult, Key},
Expand Down Expand Up @@ -50,6 +51,7 @@ pub trait Navigation {
fn show_help_dialog(&mut self);
fn show_views(&mut self);
fn show_actions(&mut self);
#[cfg(not(target_family = "windows"))]
fn show_fuzzy_actions(&mut self);
fn show_server_flamegraph(&mut self, tui: bool);

Expand Down Expand Up @@ -205,6 +207,7 @@ impl Navigation for Cursive {

context.add_global_action(self, "Views", Key::F2, |siv| siv.show_views());
context.add_global_action(self, "Show actions", Key::F8, |siv| siv.show_actions());
#[cfg(not(target_family = "windows"))]
context.add_global_action(self, "Fuzzy actions", Event::CtrlChar('p'), |siv| {
siv.show_fuzzy_actions()
});
Expand Down Expand Up @@ -481,6 +484,7 @@ impl Navigation for Cursive {
}
}

#[cfg(not(target_family = "windows"))]
fn show_fuzzy_actions(&mut self) {
let context = self.user_data::<ContextArc>().unwrap().clone();
let actions;
Expand Down

0 comments on commit 0f1ecb3

Please sign in to comment.