Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit a21ab33

Browse files
authored
Merge pull request #35 from lilafian/main
Add run_command plugin API function
2 parents 186d5af + 4f43dc7 commit a21ab33

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

poly.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ def define_command(name, function, arguments):
8383

8484

8585

86+
def api_run_command(cmd_line): # Returns output of command (different from run_commands)
87+
temp_tabs = [Tab()]
88+
89+
commands = [c.strip() for c in cmd_line.split('&&') if c.strip()]
90+
for cmd_line in commands:
91+
current, should_exit = handle_command(cmd_line, temp_tabs, 0)
92+
if should_exit:
93+
sys.exit()
94+
95+
output = "\n".join(temp_tabs[0].buffer)
96+
return output
97+
98+
8699
def load_icon(icon_name):
87100
icon_path = os.path.join(os.path.dirname(__file__), icon_name)
88101
if getattr(sys, 'frozen', False):
@@ -134,7 +147,8 @@ def __init__(self, name="New Tab"):
134147
app_context = {
135148
"tab": self,
136149
"define_command": define_command,
137-
"define_alias": define_alias
150+
"define_alias": define_alias,
151+
"run_command": api_run_command
138152
}
139153
self.plugins = load_plugins(app_context)
140154

@@ -1127,7 +1141,7 @@ def run_commands(cmds):
11271141
print(f"> {line}")
11281142
commands = [c.strip() for c in line.split('&&') if c.strip()]
11291143
for cmd_line in commands:
1130-
current, should_exit = handle_single_command(cmd_line, tabs, current)
1144+
current, should_exit = handle_command(cmd_line, tabs, current)
11311145
if should_exit:
11321146
return
11331147

0 commit comments

Comments
 (0)