Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support independent terminals per project #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions terminus/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging

from .clipboard import g_clipboard_history
from .const import DEFAULT_PANEL, DEFAULT_TITLE, EXEC_PANEL, CONTINUATION
from .const import DEFAULT_TITLE, EXEC_PANEL, CONTINUATION
from .key import get_key_code
from .recency import RecencyManager
from .terminal import Terminal
Expand Down Expand Up @@ -193,7 +193,8 @@ def run_async(

if not view:
if not panel_name:
panel_name = available_panel_name(window, DEFAULT_PANEL)
default_panel = RecencyManager.from_window(self.window).get_default_panel()
panel_name = available_panel_name(window, default_panel)

if show_in_panel:
view = window.get_output_panel(panel_name)
Expand Down Expand Up @@ -281,7 +282,8 @@ def on_selection_method(index, config_name):
if index == 0:
self.run(config_name=config_name)
elif index == 1:
self.run(config_name=config_name, panel_name=DEFAULT_PANEL)
default_panel = RecencyManager.from_window(self.window).get_default_panel()
self.run(config_name=config_name, panel_name=default_panel)

def get_config_by_name(self, name):
default_config = self.default_config()
Expand Down Expand Up @@ -717,7 +719,8 @@ def run_sync():
else:
panel_name = terminal.panel_name
if not panel_name:
panel_name = available_panel_name(window, DEFAULT_PANEL)
default_panel = RecencyManager.from_window(window).get_default_panel()
panel_name = available_panel_name(window, default_panel)

new_view = window.get_output_panel(panel_name)

Expand Down Expand Up @@ -895,7 +898,7 @@ def run(self, panel_name=None, cycle=False, **kwargs):
self.cycled_panels[:] = []

if not panel_name:
panel_name = recency_manager.recent_panel() or DEFAULT_PANEL
panel_name = recency_manager.recent_panel() or recency_manager.get_default_panel()

terminus_view = window.find_output_panel(panel_name)
if terminus_view:
Expand Down
1 change: 0 additions & 1 deletion terminus/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DEFAULT_PANEL = "Terminus"
DEFAULT_TITLE = "Terminus"
EXEC_PANEL = "Terminus Build Results"
CONTINUATION = "\u200b\u200c\u200b"
3 changes: 3 additions & 0 deletions terminus/event_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,6 @@ def on_window_command(self, window, command_name, args):
if terminal and terminal.show_in_panel:
recency_manager = RecencyManager.from_view(view)
recency_manager.set_recent_terminal(view)

def on_load_project_async(self, window):
window.run_command("hide_panel")
23 changes: 20 additions & 3 deletions terminus/recency.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@

logger = logging.getLogger('Terminus')

def get_instance_name(window):
""" returns a unique name per window and per project
effectively a human readable hash(window.id() + window.project_file_name())
"""

# make the the project filename as (1) unique (2) short as possible
file_name = window.project_file_name()
last_slash_index = file_name.rfind('/')
path_hash = hash(file_name[:last_slash_index]) % 32
project_name = file_name[last_slash_index+1:][:-len('.sublime-project')]

return "{}.{}/{}".format(window.id(), path_hash, project_name)

class RecencyManager:
_instances = {}

@classmethod
def from_window(cls, window):
if window.id() in cls._instances:
return cls._instances[window.id()]
name = get_instance_name(window)
if name in cls._instances:
return cls._instances[name]
instance = cls(window)
cls._instances[window.id()] = instance
cls._instances[name] = instance
return instance

@classmethod
Expand Down Expand Up @@ -64,3 +77,7 @@ def recent_view(self):
terminal = Terminal.from_id(view.id())
if terminal:
return view


def get_default_panel(self):
return get_instance_name(self.window) + ":Terminus"