def create_session(opts, args=None, special_window=None, cwd_from=None, respect_cwd=False, default_session=None): if args and args.session: with open(args.session) as f: return parse_session(f.read(), opts) if default_session and default_session != 'none': try: with open(default_session) as f: session_data = f.read() except EnvironmentError: log_error('Failed to read from session file, ignoring: {}'.format( default_session)) else: return parse_session(session_data, opts) ans = Session() current_layout = opts.enabled_layouts[0] if opts.enabled_layouts else 'tall' ans.add_tab(opts) ans.tabs[-1].layout = current_layout if special_window is None: cmd = args.args if args and args.args else resolved_shell(opts) if args and args.hold: cmd = [kitty_exe(), '+hold'] + cmd from kitty.tabs import SpecialWindow k = {'cwd_from': cwd_from} if respect_cwd: k['cwd'] = args.directory if getattr(args, 'title', None): k['override_title'] = args.title special_window = SpecialWindow(cmd, **k) ans.add_special_window(special_window) return ans
def create_session(opts, args=None, special_window=None, cwd_from=None, respect_cwd=False): if args and args.session: with open(args.session) as f: return parse_session(f.read(), opts) ans = Session() if args and args.window_layout: if args.window_layout not in opts.enabled_layouts: opts.enabled_layouts.insert(0, args.window_layout) current_layout = args.window_layout else: current_layout = opts.enabled_layouts[ 0] if opts.enabled_layouts else 'tall' ans.add_tab(opts) ans.tabs[-1].layout = current_layout if special_window is None: cmd = args.args if args and args.args else resolved_shell(opts) from kitty.tabs import SpecialWindow k = {'cwd_from': cwd_from} if respect_cwd: k['cwd'] = args.directory if getattr(args, 'title', None): k['override_title'] = args.title special_window = SpecialWindow(cmd, **k) ans.add_special_window(special_window) return ans
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: w = SpecialWindow(cmd=payload_get('args') or None, override_title=payload_get('title'), cwd=payload_get('cwd')) old_window = boss.active_window if payload_get('new_tab'): boss._new_tab(w) tab = boss.active_tab if payload_get('tab_title') and tab: tab.set_title(payload_get('tab_title')) aw = boss.active_window if payload_get('keep_focus') and old_window: boss.set_active_window(old_window) return None if not aw or payload_get('no_response') else str(aw.id) if payload_get('window_type') == 'os': boss._new_os_window(w) aw = boss.active_window if payload_get('keep_focus') and old_window: os_window_id = boss.set_active_window(old_window) if os_window_id: focus_os_window(os_window_id) return None if not aw or payload_get('no_response') else str(aw.id) tab = self.tabs_for_match_payload(boss, window, payload_get)[0] ans = tab.new_special_window(w) if payload_get('keep_focus') and old_window: boss.set_active_window(old_window) return None if payload_get('no_response') else str(ans.id)
def finalize_session(ans: Session) -> Session: from .tabs import SpecialWindow for t in ans.tabs: if not t.windows: t.windows.append( SpecialWindow(cmd=resolved_shell(opts), override_title=default_title)) return ans
def add_window(self, cmd): if cmd: cmd = shlex.split(cmd) if isinstance(cmd, str) else cmd else: cmd = None from .tabs import SpecialWindow t = self.tabs[-1] t.windows.append(SpecialWindow(cmd, cwd=t.cwd, override_title=t.next_title or self.default_title)) t.next_title = None
def finalize_session(ans: Session) -> Session: from .tabs import SpecialWindow for t in ans.tabs: if not t.windows: w: Optional[Watchers] = None if t.watchers.has_watchers: w = t.watchers.copy() t.windows.append(SpecialWindow(cmd=resolved_shell(opts), watchers=w, override_title=default_title)) return ans
def add_window(self, cmd: Union[None, str, List[str]]) -> None: if cmd: cmd = shlex.split(cmd) if isinstance(cmd, str) else cmd else: cmd = None from .tabs import SpecialWindow t = self.tabs[-1] watchers: Optional[Watchers] = None if self.watchers.has_watchers: watchers = self.watchers.copy() sw = SpecialWindow(cmd, cwd=t.cwd, override_title=t.next_title or self.default_title, watchers=watchers) t.windows.append(sw) t.next_title = None
def create_sessions( opts: Options, args: Optional[CLIOptions] = None, special_window: Optional['SpecialWindowInstance'] = None, cwd_from: Optional[int] = None, respect_cwd: bool = False, default_session: Optional[str] = None ) -> Generator[Session, None, None]: if args and args.session: if isinstance(args.session, PreReadSession): session_data = '' + str(args.session) else: if args.session == '-': f = sys.stdin else: f = open(args.session) with f: session_data = f.read() yield from parse_session(session_data, opts, getattr(args, 'title', None)) return if default_session and default_session != 'none': try: with open(default_session) as f: session_data = f.read() except OSError: log_error('Failed to read from session file, ignoring: {}'.format( default_session)) else: yield from parse_session(session_data, opts, getattr(args, 'title', None)) return default_watchers = args.watcher if args else () ans = Session(default_watchers=default_watchers) current_layout = opts.enabled_layouts[0] if opts.enabled_layouts else 'tall' ans.add_tab(opts) ans.tabs[-1].layout = current_layout if special_window is None: cmd = args.args if args and args.args else resolved_shell(opts) if args and args.hold: cmd = [kitty_exe(), '+hold'] + cmd from kitty.tabs import SpecialWindow cwd: Optional[str] = args.directory if respect_cwd and args else None title = getattr(args, 'title', None) special_window = SpecialWindow(cmd, override_title=title, cwd_from=cwd_from, cwd=cwd) ans.add_special_window(special_window) yield ans
def create_session(opts, args=None, special_window=None): if args and args.session: with open(args.session) as f: return parse_session(f.read(), opts) ans = Session() if args and args.window_layout: if args.window_layout not in opts.enabled_layouts: opts.enabled_layouts.insert(0, args.window_layout) current_layout = args.window_layout else: current_layout = opts.enabled_layouts[ 0] if opts.enabled_layouts else 'tall' ans.add_tab(opts) ans.tabs[-1].layout = current_layout if special_window is None: cmd = args.args if args and args.args else [shell_path] if args.title: from kitty.tabs import SpecialWindow ans.add_window(SpecialWindow(cmd, override_title=args.title)) else: ans.add_window(cmd) else: ans.add_special_window(special_window) return ans
def finalize_session(ans: Session) -> Session: from .tabs import SpecialWindow for t in ans.tabs: if not t.windows: t.windows.append(WindowSpec(SpecialWindow(cmd=resolved_shell(opts)))) return ans