@brandon_9527/tcode 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,21 +9,21 @@ from prompt_toolkit.layout.controls import FormattedTextControl
9
9
  from prompt_toolkit.application.current import get_app
10
10
  from prompt_toolkit.formatted_text.ansi import ANSI
11
11
  class ScrollableFormattedLogControl(FormattedTextControl):
12
- def __init__(A):A.lines=[];A.scroll_offset=0;A._height=0;A.last_count=0;A._selecting=_A;A._selection_start=_B;A._selection_end=_B;super().__init__(A.bq,focusable=_C,show_cursor=_A)
12
+ def __init__(A):A.lines=[];A.scroll_offset=0;A._height=0;A.last_count=0;A._selecting=_A;A._selection_start=_B;A._selection_end=_B;super().__init__(A.br,focusable=_C,show_cursor=_A)
13
13
  def clear(A):A.lines=[];A.scroll_offset=0;A.last_count=0;A._height=0
14
- def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.bt()
14
+ def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.bs()
15
15
  def update_last(A,ansi_text):
16
16
  B=ansi_text.splitlines()
17
17
  if A.lines:A.lines=A.lines[:-A.last_count]+B
18
18
  else:A.lines=B
19
- A.last_count=len(B);A.bt()
19
+ A.last_count=len(B);A.bs()
20
20
  def refresh_scroll(A):
21
21
  if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
22
- def bt(A):
22
+ def bs(A):
23
23
  if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
24
- def br(A,amount):
24
+ def bq(A,amount):
25
25
  if A._height:B=max(0,len(A.lines)-A._height);A.scroll_offset=max(0,min(A.scroll_offset+amount,B))
26
- def bq(A):
26
+ def br(A):
27
27
  R=A._height or 100;S=A.lines[A.scroll_offset:A.scroll_offset+R];C=[]
28
28
  for(T,U)in enumerate(S):
29
29
  L=A.scroll_offset+T;M=ANSI(U).__pt_formatted_text__()
@@ -48,8 +48,8 @@ class ScrollableFormattedLogControl(FormattedTextControl):
48
48
  def create_content(B,width,height):A=height;B._height=A or 100;return super().create_content(width,A)
49
49
  def mouse_handler(A,mouse_event):
50
50
  B=mouse_event;E=B.position;C,D=E.y,E.x
51
- if B.event_type==MouseEventType.SCROLL_UP:A.br(-1);return
52
- elif B.event_type==MouseEventType.SCROLL_DOWN:A.br(1);return
51
+ if B.event_type==MouseEventType.SCROLL_UP:A.bq(-1);return
52
+ elif B.event_type==MouseEventType.SCROLL_DOWN:A.bq(1);return
53
53
  elif B.event_type==MouseEventType.MOUSE_DOWN and B.button==MouseButton.LEFT:A._selecting=_C;A._selection_start=A.scroll_offset+C,D;A._selection_end=A._selection_start;get_app().invalidate();return
54
54
  elif B.event_type==MouseEventType.MOUSE_MOVE and A._selecting:A._selection_end=A.scroll_offset+C,D;get_app().invalidate();return
55
55
  elif B.event_type==MouseEventType.MOUSE_UP and A._selecting:A._selection_end=A.scroll_offset+C,D;A._selecting=_A;get_app().invalidate();return
@@ -76,9 +76,9 @@ log_window=Window(content=log_control,wrap_lines=_A)
76
76
  frame=log_window
77
77
  kb=KeyBindings()
78
78
  @kb.add('c-c')
79
- def bs(event):log_control.copy_selection_to_clipboard()
79
+ def bt(event):log_control.copy_selection_to_clipboard()
80
80
  @kb.add('q')
81
- def bs(event):event.app.exit()
81
+ def bt(event):event.app.exit()
82
82
  style=Style.from_dict({'frame.border':'#888888','frame.title':'bold','log':'#ffffff','selection':'reverse'})
83
83
  layout=Layout(HSplit([frame]))
84
84
  app=Application(layout=layout,key_bindings=kb,mouse_support=_C,full_screen=_C,style=style)
@@ -6,7 +6,7 @@ from prompt_toolkit.layout.controls import UIControl,UIContent
6
6
  from prompt_toolkit.data_structures import Point
7
7
  from prompt_toolkit.formatted_text import ANSI
8
8
  class ScrollableFormattedLogControl(FormattedTextControl):
9
- def __init__(A):A.lines=[];A.scroll_offset=0;A._height=0;A.last_count=0;super().__init__(A.bf,focusable=True,show_cursor=False)
9
+ def __init__(A):A.lines=[];A.scroll_offset=0;A._height=0;A.last_count=0;super().__init__(A.bg,focusable=True,show_cursor=False)
10
10
  def clear(A):A.lines=[];A.scroll_offset=0;A.last_count=0;A._height=0
11
11
  def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.bh()
12
12
  def update_last(A,ansi_text):
@@ -18,18 +18,18 @@ class ScrollableFormattedLogControl(FormattedTextControl):
18
18
  if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
19
19
  def bh(A):
20
20
  if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
21
- def bg(A,amount):
21
+ def bf(A,amount):
22
22
  if A._height:B=max(0,len(A.lines)-A._height);A.scroll_offset=max(0,min(A.scroll_offset+amount,B))
23
23
  def is_focusable(A):return True
24
- def bf(A):
24
+ def bg(A):
25
25
  C=A._height or 100;D=A.lines[A.scroll_offset:A.scroll_offset+C];B=[]
26
26
  for E in D:F=sanitize_ansi_text(E);B.extend(ANSI(F).__pt_formatted_text__());B.append(('','\n'))
27
27
  return B
28
28
  def create_content(B,width,height):A=height;B._height=A or 100;return super().create_content(width,A)
29
29
  def mouse_handler(A,mouse_event):
30
30
  B=mouse_event;C=5
31
- if B.event_type==MouseEventType.SCROLL_UP:A.bg(-C);return
32
- elif B.event_type==MouseEventType.SCROLL_DOWN:A.bg(C);return
31
+ if B.event_type==MouseEventType.SCROLL_UP:A.bf(-C);return
32
+ elif B.event_type==MouseEventType.SCROLL_DOWN:A.bf(C);return
33
33
  return NotImplemented
34
34
  class ScrollableLogControl(UIControl):
35
35
  def __init__(A):A.lines=[];A.scroll_offset=0;A.visible_lines=[];A._height=0;A.last_count=0
@@ -43,7 +43,7 @@ class ScrollableLogControl(UIControl):
43
43
  def refresh_scroll(A):
44
44
  if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
45
45
  def bh(A):A.scroll_offset=max(0,len(A.lines)-A._height)
46
- def bg(A,amount):A.scroll_offset=max(0,min(A.scroll_offset+amount,max(0,len(A.lines)-A._height)))
46
+ def bf(A,amount):A.scroll_offset=max(0,min(A.scroll_offset+amount,max(0,len(A.lines)-A._height)))
47
47
  def is_focusable(A):return True
48
48
  def create_content(A,width,height):B=height;A._height=B;A.visible_lines=A.lines[A.scroll_offset:A.scroll_offset+B];return UIContent(get_line=A.get_line,line_count=len(A.visible_lines),cursor_position=Point(0,len(A.visible_lines)-1))
49
49
  def get_line(B,lineno):
@@ -52,7 +52,7 @@ class ScrollableLogControl(UIControl):
52
52
  C=sanitize_ansi_text(B.visible_lines[A]);return ANSI(C).__pt_formatted_text__()
53
53
  def mouse_handler(A,mouse_event):
54
54
  B=mouse_event
55
- if B.event_type==MouseEventType.SCROLL_UP:A.bg(-1);return
56
- elif B.event_type==MouseEventType.SCROLL_DOWN:A.bg(1);return
55
+ if B.event_type==MouseEventType.SCROLL_UP:A.bf(-1);return
56
+ elif B.event_type==MouseEventType.SCROLL_DOWN:A.bf(1);return
57
57
  return NotImplemented
58
58
  def sanitize_ansi_text(text):return re.sub('[¹²³⁰⁴⁵⁶⁷⁸⁹₀₁₂₃₄₅₆₇₈₉]',' ',text)
@@ -28,7 +28,7 @@ from src.tui.components.tdiff import render_diff_as_markdown
28
28
  from src.tui.components.tdisplay import render_content_with_line_limit
29
29
  from src.tui.utils.render import markdown_to_wrapped_text
30
30
  def display_tool_call(tool_name,args,events=[]):
31
- C=tool_name;A=events;E=format_tool_compact(C,args);D=w(C,args);B=Tree(Text(_I,style=_J)+Text(f"{E}",style=_C),guide_style=_D)
31
+ C=tool_name;A=events;E=format_tool_compact(C,args);D=bc(C,args);B=Tree(Text(_I,style=_J)+Text(f"{E}",style=_C),guide_style=_D)
32
32
  if A and len(A)>0:F=display_sub_panel(D,sub_events=A);B.add(F)
33
33
  else:B.add(D)
34
34
  return B
@@ -37,14 +37,14 @@ def display_tool_result(tool_name,args=_E,result=_E,events=[]):
37
37
  if A is _E:A={}
38
38
  H=format_tool_compact(G,A);C=G.lower()
39
39
  try:
40
- if C==_K and isinstance(A,dict):B=y(A)
41
- elif C==_L and isinstance(A,dict):B=y(A)
42
- elif C in[_M]and isinstance(A,dict):B=y(A)
43
- elif C==_H and isinstance(A,dict):B=x(A,D)
44
- elif C==_N and isinstance(A,dict):B=bd(A,D)
45
- elif C==_O and isinstance(A,dict):B=v(A,D)
46
- elif C==_P and isinstance(A,dict):B=bb(A,D)
47
- else:B=z(A,D)
40
+ if C==_K and isinstance(A,dict):B=ba(A)
41
+ elif C==_L and isinstance(A,dict):B=ba(A)
42
+ elif C in[_M]and isinstance(A,dict):B=ba(A)
43
+ elif C==_H and isinstance(A,dict):B=v(A,D)
44
+ elif C==_N and isinstance(A,dict):B=w(A,D)
45
+ elif C==_O and isinstance(A,dict):B=z(A,D)
46
+ elif C==_P and isinstance(A,dict):B=x(A,D)
47
+ else:B=bd(A,D)
48
48
  except Exception as I:import traceback as J;B=Text(f"Error: {str(I)}\n{J.format_exc()}",style='red')
49
49
  F=Tree(Text(_I,style=_J)+Text(f"{H}",style=_C),guide_style=_D)
50
50
  if E and len(E)>0:K=display_sub_panel(B,sub_events=E);F.add(K)
@@ -102,11 +102,11 @@ def format_tool_compact(name,args):
102
102
  I=', '.join(M)
103
103
  if len(I)>50:I=I[:47]+_B
104
104
  return f"{J}({I})"
105
- def w(tool_name,arguments):
105
+ def bc(tool_name,arguments):
106
106
  D=' Will search for pattern';C=arguments;B='bold grey';A=tool_name.lower()
107
107
  if A==_H:return Text(f"running ...",style=B)
108
108
  if A==_M:return Text(f" Executing ...",style=B)
109
- elif A==_L:return bc(C)
109
+ elif A==_L:return y(C)
110
110
  elif A==_K:return be(C)
111
111
  elif A in[_N,_O]:return Text(D,style=B)
112
112
  elif A==_P:return Text(D,stype=B)
@@ -128,7 +128,7 @@ def be(arguments):
128
128
  if os.path.exists(B):
129
129
  with open(B,'r',encoding='utf-8')as F:G=F.read()
130
130
  H=D if C==''else G.replace(C,D,1);I=render_diff_as_markdown(E,H);return I
131
- def bc(arguments):
131
+ def y(arguments):
132
132
  D=arguments;A=D.get(_F,'');B=D.get(_R,'')
133
133
  if os.path.exists(A):C=open(A,'r').read()
134
134
  else:C=''
@@ -137,7 +137,7 @@ def bc(arguments):
137
137
  E=recognize_language(A)
138
138
  if E:G=f"```\n{E}\n{B}\n```";return render_content_with_line_limit(G,'',100)
139
139
  else:return render_content_with_line_limit(B,'',100)
140
- def y(arguments):
140
+ def ba(arguments):
141
141
  B=arguments.get(_F,'');C=''
142
142
  if os.path.exists(B):C=open(B,'r').read()
143
143
  E=C.split(_A);F=len(E);A=50
@@ -146,7 +146,7 @@ def y(arguments):
146
146
  H=recognize_language(B)
147
147
  if H:J=f"```{H}\n{D}\n```";return render_content_with_line_limit(J,'',-1)
148
148
  else:return render_content_with_line_limit(D,'',-1)
149
- def ba(arguments,result):
149
+ def bb(arguments,result):
150
150
  C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
151
151
  for(H,A)in enumerate(G):
152
152
  I=''if H==0 else''
@@ -155,7 +155,7 @@ def ba(arguments,result):
155
155
  E=F-D
156
156
  if E>0:B.append(f" ... and {E} more lines")
157
157
  return Text(_A.join(B),style=_G)
158
- def x(arguments,result):
158
+ def v(arguments,result):
159
159
  C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
160
160
  for(H,A)in enumerate(G):
161
161
  I=''if H==0 else''
@@ -164,7 +164,7 @@ def x(arguments,result):
164
164
  E=F-D
165
165
  if E>0:B.append(f" ... and {E} more lines")
166
166
  return Text(_A.join(B),style=_G)
167
- def bd(arguments,result):
167
+ def w(arguments,result):
168
168
  C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
169
169
  for(H,A)in enumerate(G):
170
170
  I=''if H==0 else''
@@ -173,7 +173,7 @@ def bd(arguments,result):
173
173
  E=F-D
174
174
  if E>0:B.append(f" ... and {E} more lines")
175
175
  return Text(_A.join(B),style=_G)
176
- def v(arguments,result):
176
+ def z(arguments,result):
177
177
  C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
178
178
  for(H,A)in enumerate(G):
179
179
  I=''if H==0 else''
@@ -182,7 +182,7 @@ def v(arguments,result):
182
182
  E=F-D
183
183
  if E>0:B.append(f" ... and {E} more lines")
184
184
  return Text(_A.join(B),style=_G)
185
- def bb(arguments,result):
185
+ def x(arguments,result):
186
186
  C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
187
187
  for(H,A)in enumerate(G):
188
188
  I=''if H==0 else''
@@ -191,7 +191,7 @@ def bb(arguments,result):
191
191
  E=F-D
192
192
  if E>0:B.append(f" ... and {E} more lines")
193
193
  return Text(_A.join(B),style=_G)
194
- def z(arguments,result):
194
+ def bd(arguments,result):
195
195
  B=result;A=str(B)if B else'tool completed successfully'
196
196
  if len(A)>500:C=A[:500]+'\n ... (truncated)'
197
197
  else:C=A
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandon_9527/tcode",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "TypeScript版 单仓库混合方案(Python源码随npm发布,本地Build)",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {