Skip to content
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
8 changes: 7 additions & 1 deletion src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
use os_pipe::PipeReader;
use std::{
collections::{BTreeMap, HashMap},
fmt::{self, Debug},
fs::File,
io::{self, BufRead, BufReader, Write},
path::{Path, PathBuf},
Expand All @@ -21,7 +22,6 @@ static EXECUTORS: Lazy<BTreeMap<SnippetLanguage, LanguageSnippetExecutionConfig>
Lazy::new(|| serde_yaml::from_slice(include_bytes!("../executors.yaml")).expect("executors.yaml is broken"));

/// Allows executing code.
#[derive(Debug)]
pub struct SnippetExecutor {
executors: BTreeMap<SnippetLanguage, LanguageSnippetExecutionConfig>,
cwd: PathBuf,
Expand Down Expand Up @@ -126,6 +126,12 @@ impl Default for SnippetExecutor {
}
}

impl Debug for SnippetExecutor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SnippetExecutor {{ .. }}")
}
}

/// An invalid executor was found.
#[derive(thiserror::Error, Debug)]
#[error("invalid snippet execution for '{0:?}': {1}")]
Expand Down
8 changes: 7 additions & 1 deletion src/processing/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,16 @@ impl<'a> PresentationBuilder<'a> {
ExecutionMode::ReplaceSnippet => DisplaySeparator::Off,
};
let alignment = self.code_style(&code).alignment.unwrap_or_default();
let default_colors = self.theme.default_style.colors;
let mut execution_output_style = self.theme.execution_output.clone();
if code.attributes.no_background {
execution_output_style.colors.background = None;
}
let operation = RunSnippetOperation::new(
code,
self.code_executor.clone(),
&self.theme,
default_colors,
execution_output_style,
block_length as u16,
separator,
alignment,
Expand Down
26 changes: 14 additions & 12 deletions src/processing/execution.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use crossterm::{
ExecutableCommand, cursor,
terminal::{self, disable_raw_mode, enable_raw_mode},
};

use super::separator::{RenderSeparator, SeparatorWidth};
use crate::{
PresentationTheme,
ansi::AnsiSplitter,
execute::{ExecutionHandle, ExecutionState, ProcessStatus, SnippetExecutor},
markdown::{
Expand All @@ -16,7 +10,11 @@ use crate::{
processing::code::Snippet,
render::{properties::WindowSize, terminal::should_hide_cursor},
style::{Colors, TextStyle},
theme::{Alignment, ExecutionStatusBlockStyle, Margin},
theme::{Alignment, ExecutionOutputBlockStyle, ExecutionStatusBlockStyle, Margin},
};
use crossterm::{
ExecutableCommand, cursor,
terminal::{self, disable_raw_mode, enable_raw_mode},
};
use std::{
cell::RefCell,
Expand Down Expand Up @@ -55,14 +53,14 @@ impl RunSnippetOperation {
pub(crate) fn new(
code: Snippet,
executor: Rc<SnippetExecutor>,
theme: &PresentationTheme,
default_colors: Colors,
execution_output_style: ExecutionOutputBlockStyle,
block_length: u16,
separator: DisplaySeparator,
alignment: Alignment,
) -> Self {
let default_colors = theme.default_style.colors;
let block_colors = theme.execution_output.colors;
let status_colors = theme.execution_output.status.clone();
let block_colors = execution_output_style.colors;
let status_colors = execution_output_style.status.clone();
let not_started_colors = status_colors.not_started;
let block_length = match &alignment {
Alignment::Left { .. } | Alignment::Right { .. } => block_length,
Expand Down Expand Up @@ -121,7 +119,11 @@ impl AsRenderOperations for RunSnippetOperation {
if matches!(inner.state, RenderAsyncState::NotStarted) {
return operations;
}
operations.extend([RenderOperation::RenderLineBreak, RenderOperation::SetColors(self.block_colors)]);
operations.push(RenderOperation::RenderLineBreak);

if self.block_colors.background.is_some() {
operations.push(RenderOperation::SetColors(self.block_colors));
}

let has_margin = match &self.alignment {
Alignment::Left { margin } => !margin.is_empty(),
Expand Down