Skip to content

Commit

Permalink
add wrapper for Vte.get_text_range* based on version, handle ctrl+c
Browse files Browse the repository at this point in the history
  • Loading branch information
asifamin13 committed Jun 23, 2024
1 parent 6c1bb4a commit d67806e
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions terminatorlib/plugins/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@

from typing import Optional, List

import gi
from gi.repository import Gtk, GLib
gi.require_version('Vte', '2.91')
from gi.repository import Vte

from terminatorlib.plugin import MenuItem
from terminatorlib.config import Config
Expand All @@ -78,6 +81,28 @@

AVAILABLE = ['Remote']

def vte_get_text(vte_term, start_row, start_col, end_row, end_col):
""" wrapper for get_text_range* based on Vte version """
version = "{}.{}".format(
Vte.get_major_version(),
Vte.get_minor_version()
)
if version < "0.72":
return vte_term.get_text_range(
start_row=start_row,
start_col=start_col,
end_row=end_row,
end_col=end_col,
is_selected=None,
)[0]
return vte_term.get_text_range_format(
format=Vte.Format.TEXT,
start_row=start_row,
start_col=start_col,
end_row=end_row,
end_col=end_col
)[0]

class RemoteSession(object):
"""
API representing a 'Remote Session'
Expand Down Expand Up @@ -320,7 +345,7 @@ def __init__(self, session_types, poll_rate=1.0) -> None:

self.quit = False
self.loop = asyncio.new_event_loop()
self.thread = threading.Thread(target=self._external_thread)
self.thread = threading.Thread(target=self._external_thread, daemon=True)

def _has_remote_session(self, pid):
""" check if this PID has a direct child with remote session """
Expand Down Expand Up @@ -490,17 +515,19 @@ def _get_cwd_from_lines(self, terminal, N=3):
"""
vte = terminal.get_vte()
currCol, currRow = vte.get_cursor_position()
lines = vte.get_text_range(
lines = vte_get_text(
vte_term=vte,
start_row=max(0, currRow - N),
start_col=0,
end_row=currRow,
end_col=currCol
)[0]
matches = list(self.cwd_regex.finditer(lines))
if matches:
lastMatch = matches[-1]
dbg(f"Inferred remote cwd: {lastMatch.group()}")
return lastMatch.group()
)
if lines:
matches = list(self.cwd_regex.finditer(lines))
if matches:
lastMatch = matches[-1]
dbg(f"Inferred remote cwd: {lastMatch.group()}")
return lastMatch.group()
dbg(f"cant find remote cwd in '{lines}'")
return None

Expand Down

0 comments on commit d67806e

Please sign in to comment.