22
33# %% auto 0
44__all__ = ['dh_settings' ,'Placements' ,'empty' ,'find_var' ,'set_var' ,'call_endp' ,'find_dname' ,'find_msg_id' ,'curr_dialog' ,
5- 'find_msgs ' ,'msg_idx ' ,'add_html' ,'add_msg' ,'del_msg' ,'update_msg' ,'url2note ' ,'ast_py ' ,'ast_grep ' ,
6- 'read_msg ' ,'run_msg ' ,'msg_insert_line' ,'msg_str_replace' ,'msg_strs_replace' ,'msg_replace_lines' ,
5+ 'msg_idx ' ,'find_msgs ' ,'add_html' ,'add_msg' ,'del_msg' ,'update_msg' ,'read_msg ' ,'run_msg ' ,'url2note ' ,
6+ 'ast_py ' ,'ast_grep ' ,'msg_insert_line' ,'msg_str_replace' ,'msg_strs_replace' ,'msg_replace_lines' ,
77'load_gist' ,'gist_file' ,'import_string' ,'is_usable_tool' ,'mk_toollist' ,'import_gist' ,'tool_info' ,
88'fc_tool_info' ]
99
@@ -71,6 +71,15 @@ def curr_dialog(
7171res = call_endp ('curr_dialog_' ,dname ,json = True ,with_messages = with_messages )
7272if res :return {'name' :res ['name' ],'mode' :res ['mode' ]}
7373
74+ # %% ../nbs/00_core.ipynb
75+ def msg_idx (
76+ msgid = None ,# Message id to find (defaults to current message)
77+ dname :str = '' # Running dialog to get info for; defaults to current dialog
78+ ):
79+ "Get absolute index of message in dialog."
80+ if not msgid :msgid = find_msg_id ()
81+ return call_endp ('msg_idx_' ,dname ,json = True ,msgid = msgid )['msgid' ]
82+
7483# %% ../nbs/00_core.ipynb
7584def find_msgs (
7685re_pattern :str = '' ,# Optional regex to search for (re.DOTALL+re.MULTILINE is used)
@@ -85,15 +94,6 @@ def find_msgs(
8594for o in res :o .pop ('output' ,None )
8695return res
8796
88- # %% ../nbs/00_core.ipynb
89- def msg_idx (
90- msgid = None ,# Message id to find (defaults to current message)
91- dname :str = '' # Running dialog to get info for; defaults to current dialog
92- ):
93- "Get absolute index of message in dialog."
94- if not msgid :msgid = find_msg_id ()
95- return call_endp ('msg_idx_' ,dname ,json = True ,msgid = msgid )['msgid' ]
96-
9797# %% ../nbs/00_core.ipynb
9898def add_html (
9999content :str ,# The HTML to send to the client (generally should include hx-swap-oob)
@@ -185,6 +185,30 @@ def update_msg(
185185set_var ('__msg_id' ,res )
186186return res
187187
188+ # %% ../nbs/00_core.ipynb
189+ def read_msg (
190+ n :int = - 1 ,# Message index (if relative, +ve is downwards)
191+ relative :bool = True ,# Is `n` relative to current message (True) or absolute (False)?
192+ msgid :str = None ,# Message id to find (defaults to current message)
193+ view_range :list [int ,int ]= None ,# Optional 1-indexed (start, end) line range for files, end=-1 for EOF
194+ nums :bool = False ,# Whether to show line numbers
195+ dname :str = '' # Running dialog to get info for; defaults to current dialog
196+ ):
197+ "Get the `Message` object indexed in the current dialog."
198+ if not msgid :msgid = find_msg_id ()
199+ data = dict (n = n ,relative = relative ,msgid = msgid )
200+ if view_range :data ['view_range' ]= view_range # None gets converted to '' so we avoid passing it to use the p.default
201+ if nums :data ['nums' ]= nums
202+ return call_endp ('read_msg_' ,dname ,json = True ,** data )
203+
204+ # %% ../nbs/00_core.ipynb
205+ def run_msg (
206+ msgid :str = None ,# id of message to execute
207+ dname :str = '' # Running dialog to get info for; defaults to current dialog
208+ ):
209+ "Adds a message to the run queue. Use read_msg to see the output once it runs."
210+ return call_endp ('add_runq_' ,dname ,msgid = msgid ,api = True )
211+
188212# %% ../nbs/00_core.ipynb
189213def url2note (
190214url :str ,# URL to read
@@ -214,30 +238,6 @@ def ast_grep(
214238res = subprocess .run (cmd ,shell = True ,capture_output = True ,text = True )
215239return json .loads (res .stdout )if res .stdout else res .stderr
216240
217- # %% ../nbs/00_core.ipynb
218- def read_msg (
219- n :int = - 1 ,# Message index (if relative, +ve is downwards)
220- relative :bool = True ,# Is `n` relative to current message (True) or absolute (False)?
221- msgid :str = None ,# Message id to find (defaults to current message)
222- view_range :list [int ,int ]= None ,# Optional 1-indexed (start, end) line range for files, end=-1 for EOF
223- nums :bool = False ,# Whether to show line numbers
224- dname :str = '' # Running dialog to get info for; defaults to current dialog
225- ):
226- "Get the `Message` object indexed in the current dialog."
227- if not msgid :msgid = find_msg_id ()
228- data = dict (n = n ,relative = relative ,msgid = msgid )
229- if view_range :data ['view_range' ]= view_range # None gets converted to '' so we avoid passing it to use the p.default
230- if nums :data ['nums' ]= nums
231- return call_endp ('read_msg_' ,dname ,json = True ,** data )
232-
233- # %% ../nbs/00_core.ipynb
234- def run_msg (
235- msgid :str = None ,# id of message to execute
236- dname :str = '' # Running dialog to get info for; defaults to current dialog
237- ):
238- "Adds a message to the run queue. Use read_msg to see the output once it runs."
239- return call_endp ('add_runq_' ,dname ,msgid = msgid ,api = True )
240-
241241# %% ../nbs/00_core.ipynb
242242def msg_insert_line (
243243msgid :str ,# Message id to edit