Skip to content

Commit

Permalink
Refactor tmux pane output function names
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoop57 committed Dec 7, 2024
1 parent 77ca92e commit 88a0d1c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 20 deletions.
104 changes: 97 additions & 7 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,58 @@
"outputs": [],
"source": [
"#| exports\n",
"def get_pane_output(n, pid=None):\n",
"def get_pane(n, pid=None):\n",
" \"Get output from a tmux pane\"\n",
" cmd = ['tmux', 'capture-pane', '-p', '-S', f'-{n}']\n",
" if pid: cmd += ['-t', pid]\n",
" return co(cmd, text=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e799e039",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Writing objects: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">100</span>% <span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span>/<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span><span style=\"font-weight: bold\">)</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">702</span> bytes | <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">702.00</span> KiB/s, done.\n",
"Total <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span> <span style=\"font-weight: bold\">(</span>delta <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span><span style=\"font-weight: bold\">)</span>, reused <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> <span style=\"font-weight: bold\">(</span>delta <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">)</span>, pack-reused <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>\n",
"remote: Resolving deltas: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">100</span>% <span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>/<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span><span style=\"font-weight: bold\">)</span>, completed with <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span> local objects.\n",
"To github.com:AnswerDotAI/shell_sage.git\n",
" 90bd427..77ca92e main -&gt; main\n",
"<span style=\"font-weight: bold\">(</span>py311<span style=\"font-weight: bold\">)</span>\n",
"shell_sage on  main via  v3.<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">11.10</span> via  py311 on  <span style=\"font-weight: bold\">(</span>us-east-<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span><span style=\"font-weight: bold\">)</span> on ☁️ nc@<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">answer.ai</span><span style=\"font-weight: bold\">(</span>us-west1<span style=\"font-weight: bold\">)</span>\n",
"❯ ssage --s Tell me about XDG Base Directory Specification\n",
"powers up documentation circuits with a slight whir\n",
"\n",
"Ah, the XDG Base Directory Specificat\n",
"</pre>\n"
],
"text/plain": [
"Writing objects: \u001b[1;36m100\u001b[0m% \u001b[1m(\u001b[0m\u001b[1;36m7\u001b[0m/\u001b[1;36m7\u001b[0m\u001b[1m)\u001b[0m, \u001b[1;36m702\u001b[0m bytes | \u001b[1;36m702.00\u001b[0m KiB/s, done.\n",
"Total \u001b[1;36m7\u001b[0m \u001b[1m(\u001b[0mdelta \u001b[1;36m4\u001b[0m\u001b[1m)\u001b[0m, reused \u001b[1;36m0\u001b[0m \u001b[1m(\u001b[0mdelta \u001b[1;36m0\u001b[0m\u001b[1m)\u001b[0m, pack-reused \u001b[1;36m0\u001b[0m\n",
"remote: Resolving deltas: \u001b[1;36m100\u001b[0m% \u001b[1m(\u001b[0m\u001b[1;36m4\u001b[0m/\u001b[1;36m4\u001b[0m\u001b[1m)\u001b[0m, completed with \u001b[1;36m4\u001b[0m local objects.\n",
"To github.com:AnswerDotAI/shell_sage.git\n",
" 90bd427..77ca92e main -> main\n",
"\u001b[1m(\u001b[0mpy311\u001b[1m)\u001b[0m\n",
"shell_sage on  main via  v3.\u001b[1;36m11.10\u001b[0m via  py311 on  \u001b[1m(\u001b[0mus-east-\u001b[1;36m1\u001b[0m\u001b[1m)\u001b[0m on ☁️ nc@\u001b[1;35manswer.ai\u001b[0m\u001b[1m(\u001b[0mus-west1\u001b[1m)\u001b[0m\n",
"❯ ssage --s Tell me about XDG Base Directory Specification\n",
"powers up documentation circuits with a slight whir\n",
"\n",
"Ah, the XDG Base Directory Specificat\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p = get_pane(20)\n",
"print(p[:512])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -204,10 +249,55 @@
"outputs": [],
"source": [
"#| exports\n",
"def get_pane_outputs(n):\n",
" current_id = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip()\n",
"def get_panes(n):\n",
" cid = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip()\n",
" pids = [p for p in co(['tmux', 'list-panes', '-F', '#{pane_id}'], text=True).splitlines()] \n",
" return '\\n'.join(f\"<pane id={p} {'active' if p==current_id else ''}>{get_pane_output(n, p)}</pane>\" for p in pids) "
" return '\\n'.join(f\"<pane id={p} {'active' if p==cid else ''}>{get_pane(n, p)}</pane>\" for p in pids) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a537f788",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">pane</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span><span style=\"color: #000000; text-decoration-color: #000000\">=%</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"color: #000000; text-decoration-color: #000000\"> active&gt;Writing objects: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">100</span><span style=\"color: #000000; text-decoration-color: #000000\">% </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span><span style=\"color: #000000; text-decoration-color: #000000\">/</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">, </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">702</span><span style=\"color: #000000; text-decoration-color: #000000\"> bytes | </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">702.00</span><span style=\"color: #000000; text-decoration-color: #000000\"> KiB/s, done.</span>\n",
"<span style=\"color: #000000; text-decoration-color: #000000\">Total </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">(</span><span style=\"color: #000000; text-decoration-color: #000000\">delta </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">, reused </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">(</span><span style=\"color: #000000; text-decoration-color: #000000\">delta </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">, pack-reused </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>\n",
"<span style=\"color: #000000; text-decoration-color: #000000\">remote: Resolving deltas: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">100</span><span style=\"color: #000000; text-decoration-color: #000000\">% </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span><span style=\"color: #000000; text-decoration-color: #000000\">/</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">, completed with </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span><span style=\"color: #000000; text-decoration-color: #000000\"> local objects.</span>\n",
"<span style=\"color: #000000; text-decoration-color: #000000\">To github.com:AnswerDotAI/shell_sage.git</span>\n",
"<span style=\"color: #000000; text-decoration-color: #000000\"> 90bd427..77ca92e main -</span><span style=\"font-weight: bold\">&gt;</span> main\n",
"<span style=\"font-weight: bold\">(</span>py311<span style=\"font-weight: bold\">)</span>\n",
"shell_sage on  main via  v3.<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">11.10</span> via  py311 on  <span style=\"font-weight: bold\">(</span>us-east-<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span><span style=\"font-weight: bold\">)</span> on ☁️ nc@<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">answer.ai</span><span style=\"font-weight: bold\">(</span>us-west1<span style=\"font-weight: bold\">)</span>\n",
"❯ ssage --s Tell me about XDG Base Directory Specification\n",
"powers up documentation circuits with a slight whir\n",
"\n",
"Ah, the XDG Base D\n",
"</pre>\n"
],
"text/plain": [
"\u001b[1m<\u001b[0m\u001b[1;95mpane\u001b[0m\u001b[39m \u001b[0m\u001b[33mid\u001b[0m\u001b[39m=%\u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m active>Writing objects: \u001b[0m\u001b[1;36m100\u001b[0m\u001b[39m% \u001b[0m\u001b[1;39m(\u001b[0m\u001b[1;36m7\u001b[0m\u001b[39m/\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, \u001b[0m\u001b[1;36m702\u001b[0m\u001b[39m bytes | \u001b[0m\u001b[1;36m702.00\u001b[0m\u001b[39m KiB/s, done.\u001b[0m\n",
"\u001b[39mTotal \u001b[0m\u001b[1;36m7\u001b[0m\u001b[39m \u001b[0m\u001b[1;39m(\u001b[0m\u001b[39mdelta \u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, reused \u001b[0m\u001b[1;36m0\u001b[0m\u001b[39m \u001b[0m\u001b[1;39m(\u001b[0m\u001b[39mdelta \u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, pack-reused \u001b[0m\u001b[1;36m0\u001b[0m\n",
"\u001b[39mremote: Resolving deltas: \u001b[0m\u001b[1;36m100\u001b[0m\u001b[39m% \u001b[0m\u001b[1;39m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[39m/\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m, completed with \u001b[0m\u001b[1;36m4\u001b[0m\u001b[39m local objects.\u001b[0m\n",
"\u001b[39mTo github.com:AnswerDotAI/shell_sage.git\u001b[0m\n",
"\u001b[39m 90bd427..77ca92e main -\u001b[0m\u001b[1m>\u001b[0m main\n",
"\u001b[1m(\u001b[0mpy311\u001b[1m)\u001b[0m\n",
"shell_sage on  main via  v3.\u001b[1;36m11.10\u001b[0m via  py311 on  \u001b[1m(\u001b[0mus-east-\u001b[1;36m1\u001b[0m\u001b[1m)\u001b[0m on ☁️ nc@\u001b[1;35manswer.ai\u001b[0m\u001b[1m(\u001b[0mus-west1\u001b[1m)\u001b[0m\n",
"❯ ssage --s Tell me about XDG Base Directory Specification\n",
"powers up documentation circuits with a slight whir\n",
"\n",
"Ah, the XDG Base D\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ps = get_panes(20)\n",
"print(ps[:512])"
]
},
{
Expand All @@ -220,9 +310,9 @@
"#| exports\n",
"def get_history(n, pid='current'):\n",
" try:\n",
" if pid=='current': return get_pane_output(n)\n",
" if pid=='all': return get_pane_outputs(n)\n",
" return get_pane_output(n, pid)\n",
" if pid=='current': return get_pane(n)\n",
" if pid=='all': return get_panes(n)\n",
" return get_pane(n, pid)\n",
" except subprocess.CalledProcessError: return None"
]
},
Expand Down
4 changes: 2 additions & 2 deletions shell_sage/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
'git_url': 'https://github.com/AnswerDotAI/shell_sage',
'lib_path': 'shell_sage'},
'syms': { 'shell_sage.core': { 'shell_sage.core.get_history': ('core.html#get_history', 'shell_sage/core.py'),
'shell_sage.core.get_pane_output': ('core.html#get_pane_output', 'shell_sage/core.py'),
'shell_sage.core.get_pane_outputs': ('core.html#get_pane_outputs', 'shell_sage/core.py'),
'shell_sage.core.get_pane': ('core.html#get_pane', 'shell_sage/core.py'),
'shell_sage.core.get_panes': ('core.html#get_panes', 'shell_sage/core.py'),
'shell_sage.core.main': ('core.html#main', 'shell_sage/core.py')}}}
22 changes: 11 additions & 11 deletions shell_sage/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.

# %% auto 0
__all__ = ['print', 'sp', 'ssp', 'model', 'cli', 'ss', 'sss', 'get_pane_output', 'get_pane_outputs', 'get_history', 'main']
__all__ = ['print', 'sp', 'ssp', 'model', 'cli', 'ss', 'sss', 'get_pane', 'get_panes', 'get_history', 'main']

# %% ../nbs/00_core.ipynb 3
from claudette import *
Expand Down Expand Up @@ -103,27 +103,27 @@
sss = partial(cli, sp=ssp)

# %% ../nbs/00_core.ipynb 10
def get_pane_output(n, pid=None):
def get_pane(n, pid=None):
"Get output from a tmux pane"
cmd = ['tmux', 'capture-pane', '-p', '-S', f'-{n}']
if pid: cmd += ['-t', pid]
return co(cmd, text=True)

# %% ../nbs/00_core.ipynb 11
def get_pane_outputs(n):
current_id = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip()
# %% ../nbs/00_core.ipynb 12
def get_panes(n):
cid = co(['tmux', 'display-message', '-p', '#{pane_id}'], text=True).strip()
pids = [p for p in co(['tmux', 'list-panes', '-F', '#{pane_id}'], text=True).splitlines()]
return '\n'.join(f"<pane id={p} {'active' if p==current_id else ''}>{get_pane_output(n, p)}</pane>" for p in pids)
return '\n'.join(f"<pane id={p} {'active' if p==cid else ''}>{get_pane(n, p)}</pane>" for p in pids)

# %% ../nbs/00_core.ipynb 12
# %% ../nbs/00_core.ipynb 14
def get_history(n, pid='current'):
try:
if pid=='current': return get_pane_output(n)
if pid=='all': return get_pane_outputs(n)
return get_pane_output(n, pid)
if pid=='current': return get_pane(n)
if pid=='all': return get_panes(n)
return get_pane(n, pid)
except subprocess.CalledProcessError: return None

# %% ../nbs/00_core.ipynb 13
# %% ../nbs/00_core.ipynb 15
@call_parse
def main(
query: Param('The query to send to the LLM', str, nargs='+'),
Expand Down

0 comments on commit 88a0d1c

Please sign in to comment.