ralph_workflow/json_parser/boundary/
streaming_state.rs1use crate::json_parser::streaming_state::StreamingSession;
2use std::cell::RefCell;
3use std::rc::Rc;
4
5#[derive(Debug, Clone)]
6pub struct StreamingState {
7 session: Rc<RefCell<StreamingSession>>,
8 terminal_mode: Rc<RefCell<crate::json_parser::terminal::TerminalMode>>,
9 thinking_active_index: Rc<RefCell<Option<u64>>>,
10 thinking_non_tty_indices: Rc<RefCell<std::collections::BTreeSet<u64>>>,
11 suppress_thinking_for_message: Rc<RefCell<bool>>,
12 text_line_active: Rc<RefCell<bool>>,
13 cursor_up_active: Rc<RefCell<bool>>,
14 last_rendered_content: Rc<RefCell<std::collections::HashMap<String, String>>>,
15}
16
17impl StreamingState {
18 #[must_use]
19 pub fn new() -> Self {
20 Self {
21 session: Rc::new(RefCell::new(StreamingSession::new())),
22 terminal_mode: Rc::new(RefCell::new(
23 crate::json_parser::terminal::TerminalMode::detect(),
24 )),
25 thinking_active_index: Rc::new(RefCell::new(None)),
26 thinking_non_tty_indices: Rc::new(RefCell::new(std::collections::BTreeSet::new())),
27 suppress_thinking_for_message: Rc::new(RefCell::new(false)),
28 text_line_active: Rc::new(RefCell::new(false)),
29 cursor_up_active: Rc::new(RefCell::new(false)),
30 last_rendered_content: Rc::new(RefCell::new(std::collections::HashMap::new())),
31 }
32 }
33
34 pub fn borrow_session(&self) -> std::cell::Ref<'_, StreamingSession> {
35 self.session.borrow()
36 }
37
38 pub fn borrow_session_mut(&self) -> std::cell::RefMut<'_, StreamingSession> {
39 self.session.borrow_mut()
40 }
41
42 pub fn terminal_mode(&self) -> std::cell::Ref<'_, crate::json_parser::terminal::TerminalMode> {
43 self.terminal_mode.borrow()
44 }
45
46 pub fn terminal_mode_mut(
47 &self,
48 ) -> std::cell::RefMut<'_, crate::json_parser::terminal::TerminalMode> {
49 self.terminal_mode.borrow_mut()
50 }
51
52 pub fn thinking_active_index(&self) -> std::cell::Ref<'_, Option<u64>> {
53 self.thinking_active_index.borrow()
54 }
55
56 pub fn thinking_active_index_mut(&self) -> std::cell::RefMut<'_, Option<u64>> {
57 self.thinking_active_index.borrow_mut()
58 }
59
60 pub fn thinking_non_tty_indices(&self) -> std::cell::Ref<'_, std::collections::BTreeSet<u64>> {
61 self.thinking_non_tty_indices.borrow()
62 }
63
64 pub fn thinking_non_tty_indices_mut(
65 &self,
66 ) -> std::cell::RefMut<'_, std::collections::BTreeSet<u64>> {
67 self.thinking_non_tty_indices.borrow_mut()
68 }
69
70 pub fn suppress_thinking_for_message(&self) -> std::cell::Ref<'_, bool> {
71 self.suppress_thinking_for_message.borrow()
72 }
73
74 pub fn suppress_thinking_for_message_mut(&self) -> std::cell::RefMut<'_, bool> {
75 self.suppress_thinking_for_message.borrow_mut()
76 }
77
78 pub fn text_line_active(&self) -> std::cell::Ref<'_, bool> {
79 self.text_line_active.borrow()
80 }
81
82 pub fn text_line_active_mut(&self) -> std::cell::RefMut<'_, bool> {
83 self.text_line_active.borrow_mut()
84 }
85
86 pub fn cursor_up_active(&self) -> std::cell::Ref<'_, bool> {
87 self.cursor_up_active.borrow()
88 }
89
90 pub fn cursor_up_active_mut(&self) -> std::cell::RefMut<'_, bool> {
91 self.cursor_up_active.borrow_mut()
92 }
93
94 pub fn last_rendered_content(
95 &self,
96 ) -> std::cell::Ref<'_, std::collections::HashMap<String, String>> {
97 self.last_rendered_content.borrow()
98 }
99
100 pub fn last_rendered_content_mut(
101 &self,
102 ) -> std::cell::RefMut<'_, std::collections::HashMap<String, String>> {
103 self.last_rendered_content.borrow_mut()
104 }
105}
106
107impl Default for StreamingState {
108 fn default() -> Self {
109 Self::new()
110 }
111}