localterm_svc

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package localterm_svc 管理本地 shell(PTY)终端会话。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectConfig

type ConnectConfig struct {
	AssetID int64
	Shell   string
	Args    []string
	Cwd     string
	Cols    int
	Rows    int
}

ConnectConfig 本地终端连接配置。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 管理所有本地终端会话。

func NewManager

func NewManager() *Manager

NewManager 创建本地终端会话管理器。

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll 关闭所有会话。

func (*Manager) Connect

func (m *Manager) Connect(cfg ConnectConfig) (string, error)

Connect 启动一个本地 shell,返回 sessionID。调用方随后用 SetCallbacks 挂回调。

func (*Manager) Disconnect

func (m *Manager) Disconnect(sessionID string)

Disconnect 断开会话。

func (*Manager) GetSession

func (m *Manager) GetSession(sessionID string) (*Session, bool)

GetSession 获取活跃会话。

func (*Manager) SetCallbacks

func (m *Manager) SetCallbacks(sessionID string, onData func([]byte), onClosed func(string))

SetCallbacks 挂数据/关闭回调,回调就绪后才启动 reader,避免首屏输出丢失。

func (*Manager) SplitFrom

func (m *Manager) SplitFrom(existingSessionID string, cols, rows int) (string, error)

SplitFrom 以现有会话的 shell 配置(shell/args/cwd/assetID)新开一个 PTY,返回新 sessionID。本地"分屏"不复用 PTY(没有连接可复用),而是再起一个同配置的 shell —— 与 iTerm/tmux 的分屏语义一致。调用方随后用 SetCallbacks 挂回调,与 Connect 一致。

type Session

type Session struct {
	ID      string
	AssetID int64
	// contains filtered or unexported fields
}

Session 表示一个活跃的本地终端会话。

func (*Session) Close

func (s *Session) Close()

Close 关闭会话(关 PTY + 回调)。

func (*Session) IsClosed

func (s *Session) IsClosed() bool

IsClosed 是否已关闭。

func (*Session) Resize

func (s *Session) Resize(cols, rows int) error

Resize 调整 PTY 窗口尺寸。

func (*Session) Write

func (s *Session) Write(data []byte) error

Write 向 PTY 写入用户输入。

type ShellInfo

type ShellInfo struct {
	Name string   `json:"name"`           // 展示名,如 "zsh" / "WSL: Ubuntu" / "Git Bash"
	Path string   `json:"path"`           // 可执行文件路径
	Args []string `json:"args,omitempty"` // 启动参数,如 ["-d","Ubuntu"]
}

ShellInfo 描述一个可供用户选择的本地 shell 预设。 Args 让 "shell+固定参数" 的预设(如 WSL 发行版、Git Bash 登录)可一键选中。

func DetectShells

func DetectShells() []ShellInfo

DetectShells 探测本机可用 shell:$SHELL(默认优先)+ /etc/shells(系统权威清单)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL