Skip to content

Commit

Permalink
feat: Clear terminal menu item (nightly)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Aug 7, 2023
1 parent 6ecb4fb commit 7ceda3d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion biscuit/core/components/views/panel/terminal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, master, *args, **kwargs):
self.grid_propagate(False)

self.menu = TerminalMenu(self, "terminal")
self.menu.add_item("Clear Terminal")
self.menu.add_item("Clear Terminal", self.clear_terminal)
self.add_button('ellipsis', self.menu.show)

self.tabs = Tabs(self)
Expand Down Expand Up @@ -64,6 +64,10 @@ def set_active_terminal(self, terminal):
if tab.terminal == terminal:
self.tabs.set_active_tab(tab)

def clear_terminal(self, *_):
if active := self.active_terminal:
active.clear()

@property
def pwsh(self):
return self.default_terminals[0]
Expand Down
3 changes: 3 additions & 0 deletions biscuit/core/components/views/panel/terminal/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ def write(self, output, tag=None):
#self.terminal.tag_add("prompt", "insert linestart", "insert")
self.terminal.see(tk.END)
self.terminal.mark_set('input', 'insert')

def clear(self):
self.terminal.clear()
14 changes: 13 additions & 1 deletion biscuit/core/components/views/panel/terminal/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@ def __init__(self, master=None, **kw):
self.mark_set('input', 'insert')
self.mark_gravity('input', 'left')

self.proxy_enabled = True
self.config(**self.base.theme.views.panel.terminal.content)

self._orig = self._w + "_orig"
self.tk.call("rename", self._w, self._orig)
self.tk.createcommand(self._w, self._proxy)

def clear(self, *_):
self.proxy_enabled = False

lastline = self.get('input linestart', 'input')
self.delete('1.0', 'end')
self.insert('end', lastline)

self.proxy_enabled = True

def _proxy(self, *args):
largs = list(args)
if not self.proxy_enabled:
return self.tk.call((self._orig,) + args)

largs = list(args)
if args[0] == 'insert':
if self.compare('insert', '<', 'input'):
self.mark_set('insert', 'end')
Expand Down

0 comments on commit 7ceda3d

Please sign in to comment.