From 2dbb178603118164e784bbcef35d3c03830d7c56 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Mon, 10 Apr 2023 23:16:32 +0100 Subject: [PATCH] change back to no extra crate --- Cargo.lock | 11 +--- Cargo.toml | 6 +- atuin-syntect/Cargo.toml | 15 ----- atuin-syntect/src/style.rs | 61 ------------------ src/command/client/search.rs | 1 + src/command/client/search/history_list.rs | 39 +---------- src/command/client/search/interactive.rs | 26 +++----- .../default_nonewlines.packdump | Bin .../client/search/search_syntect/mod.rs | 3 +- 9 files changed, 20 insertions(+), 142 deletions(-) delete mode 100644 atuin-syntect/Cargo.toml delete mode 100644 atuin-syntect/src/style.rs rename {atuin-syntect/src => src/command/client/search/search_syntect}/default_nonewlines.packdump (100%) rename atuin-syntect/src/lib.rs => src/command/client/search/search_syntect/mod.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 022be060..7a60a3f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,7 +82,6 @@ dependencies = [ "atuin-client", "atuin-common", "atuin-server", - "atuin-syntect", "base64 0.20.0", "bitflags", "cassowary", @@ -101,11 +100,13 @@ dependencies = [ "interim", "itertools", "log", + "once_cell", "rpassword", "runtime-format", "semver", "serde", "serde_json", + "syntect", "tiny-bip39", "tokio", "tracing-subscriber", @@ -189,14 +190,6 @@ dependencies = [ "whoami", ] -[[package]] -name = "atuin-syntect" -version = "14.0.0" -dependencies = [ - "once_cell", - "syntect", -] - [[package]] name = "autocfg" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 588f1de3..27046750 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ buildflags = ["--release"] atuin = { path = "/usr/bin/atuin" } [workspace] -members = ["./atuin-client", "./atuin-server", "./atuin-common", "./atuin-syntect"] +members = ["./atuin-client", "./atuin-server", "./atuin-common"] [features] # TODO(conradludgate) @@ -47,7 +47,6 @@ server = ["atuin-server", "tracing-subscriber"] atuin-server = { path = "atuin-server", version = "14.0.0", optional = true } atuin-client = { path = "atuin-client", version = "14.0.0", optional = true, default-features = false } atuin-common = { path = "atuin-common", version = "14.0.0" } -atuin-syntect = { path = "atuin-syntect", version = "14.0.0" } log = "0.4" env_logger = "0.10.0" @@ -76,6 +75,9 @@ futures-util = "0.3" fuzzy-matcher = "0.3.7" colored = "2.0.0" +syntect = { version = "5.0.0", default-features = false, features = ["dump-load", "parsing", "regex-fancy"] } +once_cell = "1" + # ratatui bitflags = "1.3" cassowary = "0.3" diff --git a/atuin-syntect/Cargo.toml b/atuin-syntect/Cargo.toml deleted file mode 100644 index 0b08b4f4..00000000 --- a/atuin-syntect/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "atuin-syntect" -version = "14.0.0" -authors = ["Ellie Huxtable "] -edition = "2018" -license = "MIT" -description = "common library for atuin" -homepage = "https://atuin.sh" -repository = "https://github.com/ellie/atuin" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -syntect = { version = "5.0.0", default-features = false, features = ["dump-load", "parsing", "regex-fancy"] } -once_cell = "1" diff --git a/atuin-syntect/src/style.rs b/atuin-syntect/src/style.rs deleted file mode 100644 index 5e23534e..00000000 --- a/atuin-syntect/src/style.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! `style` contains the primitives used to control how your user interface will look. - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Color { - Black, - Red, - Green, - Yellow, - Blue, - Magenta, - Cyan, - Gray, - DarkGray, - LightRed, - LightGreen, - LightYellow, - LightBlue, - LightMagenta, - LightCyan, - White, - Rgb(u8, u8, u8), -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct Style { - pub fg: Option, - pub bg: Option, -} - -impl Style { - /// Changes the foreground color. - /// - /// ## Examples - /// - /// ```rust - /// # use ratatui::style::{Color, Style}; - /// let style = Style::default().fg(Color::Blue); - /// let diff = Style::default().fg(Color::Red); - /// assert_eq!(style.patch(diff), Style::default().fg(Color::Red)); - /// ``` - pub fn fg(mut self, color: Color) -> Style { - self.fg = Some(color); - self - } - - /// Changes the background color. - /// - /// ## Examples - /// - /// ```rust - /// # use ratatui::style::{Color, Style}; - /// let style = Style::default().bg(Color::Blue); - /// let diff = Style::default().bg(Color::Red); - /// assert_eq!(style.patch(diff), Style::default().bg(Color::Red)); - /// ``` - pub fn bg(mut self, color: Color) -> Style { - self.bg = Some(color); - self - } -} diff --git a/src/command/client/search.rs b/src/command/client/search.rs index f125b8bf..bd3cf231 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -16,6 +16,7 @@ mod duration; mod engines; mod history_list; mod interactive; +mod search_syntect; pub use duration::{format_duration, format_duration_into}; #[allow(clippy::struct_excessive_bools)] diff --git a/src/command/client/search/history_list.rs b/src/command/client/search/history_list.rs index c99cc3f5..15057088 100644 --- a/src/command/client/search/history_list.rs +++ b/src/command/client/search/history_list.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, time::Duration}; +use super::search_syntect::{ParsedSyntax, Theme}; use crate::ratatui::{ buffer::Buffer, layout::Rect, @@ -7,7 +8,6 @@ use crate::ratatui::{ widgets::{Block, StatefulWidget, Widget}, }; use atuin_client::history::History; -use atuin_syntect::{ParsedSyntax, Theme}; use super::format_duration; @@ -172,9 +172,7 @@ impl DrawState<'_> { let selected = self.y as usize + self.state.offset == self.state.selected; let with_select = move |style: Style| { if selected { - style - .bg(map_color(theme.selection)) - .add_modifier(Modifier::BOLD) + style.bg(theme.selection).add_modifier(Modifier::BOLD) } else { style } @@ -185,7 +183,7 @@ impl DrawState<'_> { if t.is_empty() { self.x += 1; } else { - self.draw(t, with_select(map_style(style))); + self.draw(t, with_select(style)); } }); } else { @@ -209,34 +207,3 @@ impl DrawState<'_> { self.x += self.buf.set_stringn(cx, cy, s, w, style).0 - cx; } } - -fn map_color(c: atuin_syntect::Color) -> Color { - match c { - atuin_syntect::Color::Black => Color::Black, - atuin_syntect::Color::Red => Color::Red, - atuin_syntect::Color::Green => Color::Green, - atuin_syntect::Color::Yellow => Color::Yellow, - atuin_syntect::Color::Blue => Color::Blue, - atuin_syntect::Color::Magenta => Color::Magenta, - atuin_syntect::Color::Cyan => Color::Cyan, - atuin_syntect::Color::Gray => Color::Gray, - atuin_syntect::Color::DarkGray => Color::DarkGray, - atuin_syntect::Color::LightRed => Color::LightRed, - atuin_syntect::Color::LightGreen => Color::LightGreen, - atuin_syntect::Color::LightYellow => Color::LightYellow, - atuin_syntect::Color::LightBlue => Color::LightBlue, - atuin_syntect::Color::LightMagenta => Color::LightMagenta, - atuin_syntect::Color::LightCyan => Color::LightCyan, - atuin_syntect::Color::White => Color::White, - atuin_syntect::Color::Rgb(r, g, b) => Color::Rgb(r, g, b), - } -} - -fn map_style(c: atuin_syntect::Style) -> Style { - Style { - fg: c.fg.map(map_color), - bg: c.bg.map(map_color), - add_modifier: Modifier::empty(), - sub_modifier: Modifier::empty(), - } -} diff --git a/src/command/client/search/interactive.rs b/src/command/client/search/interactive.rs index e4ae5ba8..d9ffc39d 100644 --- a/src/command/client/search/interactive.rs +++ b/src/command/client/search/interactive.rs @@ -4,7 +4,6 @@ use std::{ time::Duration, }; -use atuin_syntect::{ParsedSyntax, Theme, ShellSyntax, get_syntax, get_theme}; use crossterm::{ event::{self, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent}, execute, terminal, @@ -12,10 +11,6 @@ use crossterm::{ use eyre::Result; use futures_util::FutureExt; use semver::Version; -// use syntect::{ -// dumps::from_uncompressed_data, -// parsing::{ScopeStackOp, SyntaxReference, SyntaxSet}, -// }; use unicode_width::UnicodeWidthStr; use atuin_client::{ @@ -28,23 +23,21 @@ use super::{ cursor::Cursor, engines::{SearchEngine, SearchState}, history_list::{HistoryList, ListState, PREFIX_LENGTH}, + search_syntect::{get_syntax, get_theme, ParsedSyntax, ShellSyntax, Theme}, +}; +use crate::ratatui::{ + backend::{Backend, CrosstermBackend}, + layout::{Alignment, Constraint, Direction, Layout}, + style::{Color, Modifier, Style}, + text::{Span, Spans, Text}, + widgets::{Block, BorderType, Borders, Paragraph}, + Frame, Terminal, TerminalOptions, Viewport, }; use crate::{command::client::search::engines, VERSION}; -use crate::{ - ratatui::{ - backend::{Backend, CrosstermBackend}, - layout::{Alignment, Constraint, Direction, Layout}, - style::{Color, Modifier, Style}, - text::{Span, Spans, Text}, - widgets::{Block, BorderType, Borders, Paragraph}, - Frame, Terminal, TerminalOptions, Viewport, - }, -}; const RETURN_ORIGINAL: usize = usize::MAX; const RETURN_QUERY: usize = usize::MAX - 1; - struct State { history_count: i64, update_needed: Option, @@ -621,4 +614,3 @@ pub async fn history( #[allow(clippy::let_and_return)] res } - diff --git a/atuin-syntect/src/default_nonewlines.packdump b/src/command/client/search/search_syntect/default_nonewlines.packdump similarity index 100% rename from atuin-syntect/src/default_nonewlines.packdump rename to src/command/client/search/search_syntect/default_nonewlines.packdump diff --git a/atuin-syntect/src/lib.rs b/src/command/client/search/search_syntect/mod.rs similarity index 99% rename from atuin-syntect/src/lib.rs rename to src/command/client/search/search_syntect/mod.rs index d9bf090e..451e5d7f 100644 --- a/atuin-syntect/src/lib.rs +++ b/src/command/client/search/search_syntect/mod.rs @@ -7,8 +7,7 @@ use syntect::{ }, }; -mod style; -pub use style::*; +use crate::ratatui::style::{Color, Style}; impl Theme { // this is a manual/simpler implementation of