ralph_workflow/json_parser/gemini/
io.rs1use std::cell::RefCell;
2use std::collections::HashMap;
3
4use crate::json_parser::streaming_state::StreamingSession;
5use crate::json_parser::terminal::TerminalMode;
6
7pub struct GeminiParserState {
8 pub streaming_session: std::rc::Rc<RefCell<StreamingSession>>,
9 pub terminal_mode: RefCell<TerminalMode>,
10 pub last_rendered_content: RefCell<HashMap<String, String>>,
11}
12
13impl GeminiParserState {
14 pub fn new(verbose_warnings: bool) -> Self {
15 let streaming_session = StreamingSession::new().with_verbose_warnings(verbose_warnings);
16 Self {
17 streaming_session: std::rc::Rc::new(RefCell::new(streaming_session)),
18 terminal_mode: RefCell::new(TerminalMode::detect()),
19 last_rendered_content: RefCell::new(HashMap::new()),
20 }
21 }
22
23 pub fn with_session_mut<R>(&self, f: impl FnOnce(&mut StreamingSession) -> R) -> R {
24 f(&mut self.streaming_session.borrow_mut())
25 }
26
27 pub fn with_last_rendered_content_mut<R>(
28 &self,
29 f: impl FnOnce(&mut HashMap<String, String>) -> R,
30 ) -> R {
31 f(&mut self.last_rendered_content.borrow_mut())
32 }
33}