Skip to content

Commit e803817

Browse files
committed
upgrade runtimelib to 0.11.0
1 parent a9cf2fd commit e803817

File tree

3 files changed

+33
-56
lines changed

3 files changed

+33
-56
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/runtimes/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ language.workspace = true
2727
log.workspace = true
2828
project.workspace = true
2929
resvg = { version = "0.41.0", default-features = false }
30-
# runtimelib = "0.10.0"
31-
runtimelib = { path = "../../../../runtimed/runtimed/runtimelib" }
30+
runtimelib = "0.11.0"
3231
serde.workspace = true
3332
serde_json.workspace = true
3433
settings.workspace = true

crates/runtimes/src/outputs.rs

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use anyhow::Result;
66
use gpui::{img, AnyElement, FontWeight, ImageData, Render, View};
77
use runtimelib::datatable::TableSchema;
88
use runtimelib::media::datatable::TabularDataResource;
9-
use runtimelib::{ExecutionState, JupyterMessageContent, MimeType};
9+
use runtimelib::{ExecutionState, JupyterMessageContent, MimeBundle, MimeType};
1010
use serde_json::Value;
1111
use ui::{div, prelude::*, v_flex, IntoElement, Styled, ViewContext};
1212

@@ -70,8 +70,8 @@ pub trait LineHeight: Sized {
7070

7171
fn rank_mime_type(mimetype: &MimeType) -> usize {
7272
match mimetype {
73-
// SVG Rendering is incomplete so we don't show it
7473
MimeType::DataTable(_) => 6,
74+
// SVG Rendering is incomplete so we don't show it
7575
// MimeType::Svg(_) => 5,
7676
MimeType::Png(_) => 4,
7777
MimeType::Jpeg(_) => 3,
@@ -319,6 +319,30 @@ pub fn extract_image_output(base64_encoded_data: &str) -> Result<OutputType> {
319319
}));
320320
}
321321

322+
impl From<&MimeBundle> for OutputType {
323+
fn from(data: &MimeBundle) -> Self {
324+
match data.richest(rank_mime_type) {
325+
Some(MimeType::Plain(text)) => OutputType::Plain(TerminalOutput::from(text)),
326+
Some(MimeType::Markdown(text)) => OutputType::Plain(TerminalOutput::from(text)),
327+
Some(MimeType::Svg(text)) => match svg_to_vec(text, 1.0) {
328+
Ok(output) => output,
329+
Err(error) => OutputType::Message(format!("Failed to load image: {}", error)),
330+
},
331+
Some(MimeType::Png(data)) | Some(MimeType::Jpeg(data)) => {
332+
match extract_image_output(&data) {
333+
Ok(output) => output,
334+
Err(error) => OutputType::Message(format!("Failed to load image: {}", error)),
335+
}
336+
}
337+
Some(MimeType::DataTable(data)) => OutputType::Table(TableView {
338+
table: data.clone(),
339+
}),
340+
// Any other media types are not supported
341+
_ => OutputType::Message("Unsupported media type".to_string()),
342+
}
343+
}
344+
}
345+
322346
impl ExecutionView {
323347
pub fn new(execution_id: ExecutionId, _cx: &mut ViewContext<Self>) -> Self {
324348
Self {
@@ -330,57 +354,9 @@ impl ExecutionView {
330354

331355
/// Accept a Jupyter message belonging to this execution
332356
pub fn push_message(&mut self, message: &JupyterMessageContent, cx: &mut ViewContext<Self>) {
333-
let output = match message {
334-
JupyterMessageContent::ExecuteResult(result) => {
335-
match result.data.richest(rank_mime_type) {
336-
Some(MimeType::Plain(text)) => OutputType::Plain(TerminalOutput::from(text)),
337-
Some(MimeType::Markdown(text)) => OutputType::Plain(TerminalOutput::from(text)),
338-
Some(MimeType::Svg(text)) => match svg_to_vec(text, 1.0) {
339-
Ok(output) => output,
340-
Err(error) => {
341-
OutputType::Message(format!("Failed to load image: {}", error))
342-
}
343-
},
344-
Some(MimeType::Png(data)) | Some(MimeType::Jpeg(data)) => {
345-
match extract_image_output(&data) {
346-
Ok(output) => output,
347-
Err(error) => {
348-
OutputType::Message(format!("Failed to load image: {}", error))
349-
}
350-
}
351-
}
352-
Some(MimeType::DataTable(data)) => OutputType::Table(TableView {
353-
table: data.clone(),
354-
}),
355-
// Any other media types are not supported
356-
_ => return,
357-
}
358-
}
359-
JupyterMessageContent::DisplayData(result) => {
360-
match result.data.richest(rank_mime_type) {
361-
Some(MimeType::Plain(text)) => OutputType::Plain(TerminalOutput::from(text)),
362-
Some(MimeType::Markdown(text)) => OutputType::Plain(TerminalOutput::from(text)),
363-
Some(MimeType::Svg(text)) => match svg_to_vec(text, 1.0) {
364-
Ok(output) => output,
365-
Err(error) => {
366-
OutputType::Message(format!("Failed to load image: {}", error))
367-
}
368-
},
369-
Some(MimeType::Png(data)) | Some(MimeType::Jpeg(data)) => {
370-
match extract_image_output(&data) {
371-
Ok(output) => output,
372-
Err(error) => {
373-
OutputType::Message(format!("Failed to load image: {}", error))
374-
}
375-
}
376-
}
377-
Some(MimeType::DataTable(data)) => OutputType::Table(TableView {
378-
table: data.clone(),
379-
}),
380-
// Any other media types are not supported
381-
_ => return,
382-
}
383-
}
357+
let output: OutputType = match message {
358+
JupyterMessageContent::ExecuteResult(result) => (&result.data).into(),
359+
JupyterMessageContent::DisplayData(result) => (&result.data).into(),
384360
JupyterMessageContent::StreamContent(result) => {
385361
// Previous stream data will combine together, handling colors, carriage returns, etc
386362
if let Some(new_terminal) = self.apply_terminal_text(&result.text) {

0 commit comments

Comments
 (0)