Skip to content

Commit c2e2603

Browse files
committed
fix(cli-rs): apply a session.markdown change to shown text in place
TS's transcript Markdown takes conceal from markdownMode() reactively, so switching session.markdown in the settings shows the source of text already on screen. The Rust rows read the setting only when they were built. Text, reasoning, thoughts and compaction summaries now set it on every update. Since OpenTUI #2105 a conceal change keeps the built-in code views and their highlight.
1 parent 6aab9f8 commit c2e2603

6 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎packages/cli-rs/crates/tui/src/routes/session/grouping.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ impl Inner {
10211021
(Child::Row(row), Node::Entry(spec)) => row.update(cx, spec),
10221022
(Child::Thought(view), Node::Entry(spec)) => {
10231023
if let Some((message, part)) = thought(cx, spec) {
1024-
view.update(message, part);
1024+
view.update(message, part, cx.conceal);
10251025
}
10261026
}
10271027
(Child::Group(view), Node::Group(group)) => {
@@ -1089,9 +1089,11 @@ impl Thought {
10891089
opencode_ui::markdown::restyle(&self.markdown, thought_colors(cx.theme), cx.thinking_syntax);
10901090
}
10911091

1092-
fn update(&self, message: &SessionMessageAssistant, part: &SessionMessageAssistantReasoning) {
1092+
fn update(&self, message: &SessionMessageAssistant, part: &SessionMessageAssistantReasoning, conceal: bool) {
10931093
let content = reasoning::content(part);
10941094
self.root.visible(!content.is_empty());
1095+
// `session.markdown` changes in place; the code views stay.
1096+
self.markdown.conceal(conceal);
10951097
if *self.content.borrow() != content {
10961098
self.markdown.set_markdown(content.as_str());
10971099
*self.content.borrow_mut() = content;

‎packages/cli-rs/crates/tui/src/routes/session/messages/assistant.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ impl TextPart {
3535
opencode_ui::markdown::restyle(&self.markdown, colors, cx.syntax);
3636
}
3737

38-
pub fn update(&self, message: &SessionMessageAssistant, part: &SessionMessageAssistantText) {
38+
pub fn update(&self, message: &SessionMessageAssistant, part: &SessionMessageAssistantText, conceal: bool) {
3939
let text = part.text.trim();
4040
self.root.visible(!text.is_empty());
41+
// `session.markdown` changes in place, as TS's `conceal` prop follows it; the code views stay.
42+
self.markdown.conceal(conceal);
4143
// Content goes in before streaming ends, so completion keeps the final tokens. The widget's source is the
4244
// text shown so far. Read it in place for the bytes `text` keeps (0 replaces them all), and change it only
4345
// after the read ends.

‎packages/cli-rs/crates/tui/src/routes/session/messages/compaction.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ impl Compaction {
9696
usage: (status != Status::Running).then(|| tokens.and_then(usage)).flatten(),
9797
content: text.trim().to_owned(),
9898
};
99+
// `session.markdown` changes in place; the code views stay.
100+
self.markdown.conceal(cx.conceal);
99101
if !self.stale.replace(false) && self.rendered.borrow().as_ref() == Some(&rendered) {
100102
return;
101103
}

‎packages/cli-rs/crates/tui/src/routes/session/messages/list.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ impl Row {
14221422
if let Some(assistant) = cx.assistant(message)
14231423
&& let Some(SessionMessageAssistantContentItem::Text(text)) = part.resolve(assistant)
14241424
{
1425-
view.update(assistant, text);
1425+
view.update(assistant, text, cx.conceal);
14261426
}
14271427
}
14281428
(Body::Reasoning(view), Spec::Part { message, part }) => {

‎packages/cli-rs/crates/tui/src/routes/session/messages/reasoning.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ impl Reasoning {
114114
let done = time.and_then(|time| time.completed).is_some() || message.time.completed.is_some();
115115
let end = time.and_then(|time| time.completed).or(message.time.completed);
116116
let start = time.map_or(message.time.created, |time| time.created);
117+
// `session.markdown` changes in place; the code views stay.
118+
self.0.markdown.conceal(cx.conceal);
117119
let mut state = self.0.state.borrow_mut();
118120
if state.content != content {
119121
self.0.markdown.set_markdown(content.as_str());

‎packages/cli-rs/crates/tui/tests/all/transcript.rs‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::time::Duration;
1111

1212
use opencode_api::generated::V2Event;
1313
use opencode_api::transport::{BoxFuture, Request, Response, Transport};
14-
use opencode_local::cli_config::{Bounded, Debug, Info, Scroll, Session, TurnTokens, Verbosity, Visibility};
14+
use opencode_local::cli_config::{Bounded, Debug, Info, Markdown, Scroll, Session, TurnTokens, Verbosity, Visibility};
1515
use opencode_tui::Deps;
1616
use serde_json::{Value, json};
1717
use tokio::sync::Semaphore;
@@ -507,6 +507,36 @@ fn a_theme_switch_restyles_the_transcript_in_place() {
507507
assert_eq!(diff.map(|(x, y)| (x, y, switched.cell(x, y), expected.cell(x, y))), None, "{}", switched.text());
508508
}
509509

510+
/// `session.markdown` reaches the text already shown, as TS's `conceal` prop follows `markdownMode()`
511+
/// (`message-parts.tsx:195`), and the fence keeps its widget.
512+
#[test]
513+
fn a_markdown_mode_change_shows_the_source_in_place() {
514+
let text = "Some **bold** text.\n\n```rust\nlet x = 1;\n```";
515+
let messages = || {
516+
vec![
517+
user("msg_1", 1000, "Show"),
518+
assistant("msg_2", 1500, json!([{ "type": "text", "text": text }]), Some(4000)),
519+
]
520+
};
521+
let h = open(60, 20, "ses_c", messages(), support::still());
522+
let screen = h.wait_for("let x = 1;");
523+
assert!(screen.contains("Some bold text."), "{screen}");
524+
let fence = Rc::new(());
525+
support::mark_at(&h.app, "let x = 1;", 1, &fence);
526+
opencode_tui::dialogs::settings::update(&h.tui, |draft| {
527+
opencode_tui::dialogs::settings::set_path(draft, &["session", "markdown"], json!("source"))
528+
});
529+
let switched = h.app.render();
530+
assert!(switched.text().contains("Some **bold** text."), "{}", switched.text());
531+
assert_eq!(Rc::strong_count(&fence), 2, "the fence was built again");
532+
533+
let source =
534+
Info { session: Some(Session { markdown: Some(Markdown::Source), ..Session::default() }), ..support::still() };
535+
let fresh = open(60, 20, "ses_c", messages(), source);
536+
fresh.wait_for("let x = 1;");
537+
assert_eq!(switched.cells, fresh.app.render().cells, "{}", switched.text());
538+
}
539+
510540
/// Groups and the turn's usage restyle in place: an open group and the open usage table stay open, and each cell
511541
/// equals the rows mounted in the new theme.
512542
#[test]

0 commit comments

Comments
 (0)