Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add syntax highlighting for Nushell #84

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/v0.15.10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- it's now possible to directly copy images into Stacks, using the macOS
content menu
45 changes: 23 additions & 22 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::state::SharedState;
use crate::store::{
InProgressStream, MimeType, Movement, Settings, StackLockStatus, StackSortOrder,
};
use crate::ui::{generate_preview, with_meta, Item as UIItem, Nav, UI};
use crate::ui::{with_meta, Item as UIItem, Nav, UI};
use crate::view::View;

#[derive(Debug, Clone, serde::Serialize)]
Expand Down Expand Up @@ -170,13 +170,15 @@ pub async fn store_pipe_stack_to_shell(
streamer.append(&buffer[..size]);

if mime_type == MimeType::TextPlain {
let preview = generate_preview(
"dark",
&Some(streamer.content.clone()),
&streamer.content_meta.mime_type,
&streamer.content_meta.content_type,
true,
);
let preview = state.with_lock(|state| {
state.ui.generate_preview(
&Some(streamer.content.clone()),
&streamer.content_meta.mime_type,
&streamer.content_meta.content_type,
true,
)
});

let content = String::from_utf8_lossy(&streamer.content);
let content = Content {
mime_type: streamer.content_meta.mime_type.clone(),
Expand Down Expand Up @@ -403,13 +405,15 @@ pub async fn store_pipe_to_command(
streamer.append(&buffer[..size]);

if mime_type == MimeType::TextPlain {
let preview = generate_preview(
"dark",
&Some(streamer.content.clone()),
&streamer.content_meta.mime_type,
&streamer.content_meta.content_type,
true,
);
let preview = state.with_lock(|state| {
state.ui.generate_preview(
&Some(streamer.content.clone()),
&streamer.content_meta.mime_type,
&streamer.content_meta.content_type,
true,
)
});

let content = String::from_utf8_lossy(&streamer.content);
let content = Content {
mime_type: streamer.content_meta.mime_type.clone(),
Expand Down Expand Up @@ -574,13 +578,10 @@ pub fn store_get_content(state: tauri::State<SharedState>, hash: ssri::Integrity
_ => (0, 0),
};

let preview = generate_preview(
&state.ui.theme_mode,
&content,
&meta.mime_type,
&meta.content_type,
false,
);
let preview =
state
.ui
.generate_preview(&content, &meta.mime_type, &meta.content_type, false);

Content {
mime_type: meta.mime_type,
Expand Down
27 changes: 11 additions & 16 deletions src-tauri/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use hyper_util::rt::TokioIo;

use crate::state::SharedState;
use crate::store::{infer_mime_type, InProgressStream, MimeType};
use crate::ui::generate_preview;

type BoxError = Box<dyn std::error::Error + Send + Sync>;
type HTTPResult = Result<Response<BoxBody<Bytes, BoxError>>, BoxError>;
Expand Down Expand Up @@ -59,14 +58,9 @@ fn get_as_html(state: SharedState, hash: ssri::Integrity) -> HTTPResult {
let preview = state.with_lock(|state| {
let content = state.store.get_content(&hash);
let meta = state.store.get_content_meta(&hash).unwrap();

generate_preview(
&state.ui.theme_mode,
&content,
&meta.mime_type,
&meta.content_type,
false,
)
state
.ui
.generate_preview(&content, &meta.mime_type, &meta.content_type, false)
});

Ok(Response::builder()
Expand Down Expand Up @@ -158,13 +152,14 @@ async fn post(
while let Some(frame) = body.frame().await {
let data = frame?.into_data().unwrap();
streamer.append(&data);
let preview = generate_preview(
"dark",
&Some(streamer.content.clone()),
&MimeType::TextPlain,
&"Text".to_string(),
true,
);
let preview = state.with_lock(|state| {
state.ui.generate_preview(
&Some(streamer.content.clone()),
&MimeType::TextPlain,
&"Text".to_string(),
true,
)
});

let content = String::from_utf8_lossy(&streamer.content);
let content = Content {
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod commands;
mod content_bus;
mod content_type;
mod http;
mod publish;
mod serve;
mod spotlight;
mod state;
Expand Down
151 changes: 0 additions & 151 deletions src-tauri/src/publish.rs

This file was deleted.

5 changes: 1 addition & 4 deletions src-tauri/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::clipboard;
use crate::commands;
use crate::content_bus;
use crate::http;
use crate::publish;
use crate::spotlight;
use crate::state::{SharedState, State};

Expand Down Expand Up @@ -101,14 +100,12 @@ pub async fn serve<A: tauri::Assets>(context: tauri::Context<A>, db_path: String
let _ = window.move_window(Position::Center);
}

let (packet_sender, packet_receiver) = std::sync::mpsc::channel();

let (packet_sender, _) = std::sync::mpsc::channel();
let state = State::new(&db_path, packet_sender);
let mutex = tracing_mutex_span::TracingMutexSpan::new("SharedState", state);
let state: SharedState = Arc::new(mutex);
app.manage(state.clone());

publish::spawn(state.clone(), packet_receiver);
content_bus::spawn_tiktokens(app.handle(), state.clone());

http::start(app.handle().clone(), state.clone(), &db_path);
Expand Down
Loading