Skip to content

Commit 87ec704

Browse files
Merge pull request #28 from misha-ssh/add-call-command
Add call command
2 parents b7ceb5a + e4918ac commit 87ec704

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ require (
1515
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
1616
github.com/stretchr/testify v1.10.0 // indirect
1717
golang.org/x/sys v0.35.0 // indirect
18+
golang.org/x/term v0.34.0 // indirect
1819
)

pkg/connect/ssh.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ import (
99
"github.com/misha-ssh/kernel/internal/logger"
1010
"github.com/misha-ssh/kernel/internal/storage"
1111
"golang.org/x/crypto/ssh"
12+
"golang.org/x/term"
1213
)
1314

1415
const (
1516
TypeConnect = "tcp"
1617

1718
Timeout = 20 * time.Second
1819

19-
DisableEcho = 0
20-
IgnoreCR = 1
20+
EnableMod = 1
21+
ICRNLMod = 1
22+
INLCRMod = 1
23+
ISIGMod = 1
2124

22-
TypeTerm = "vt100"
25+
ISPEED = 115200
26+
OSPEED = 115200
27+
28+
TypeTerm = "xterm-256color"
2329
HeightTerminal = 80
2430
WidthTerminal = 40
2531
)
@@ -90,7 +96,20 @@ func (s *Ssh) Connect(session *ssh.Session) error {
9096
}
9197
}()
9298

93-
err := session.Shell()
99+
fd := int(os.Stdin.Fd())
100+
101+
oldState, err := term.MakeRaw(fd)
102+
if err != nil {
103+
logger.Error(err.Error())
104+
return err
105+
}
106+
defer func() {
107+
if err = term.Restore(fd, oldState); err != nil {
108+
logger.Error(err.Error())
109+
}
110+
}()
111+
112+
err = session.Shell()
94113
if err != nil {
95114
logger.Error(err.Error())
96115
return err
@@ -147,13 +166,23 @@ func getClientConfig(connection *Connect) (*ssh.ClientConfig, error) {
147166
}
148167

149168
func createTerminalSession(session *ssh.Session) error {
169+
fd := int(os.Stdin.Fd())
170+
width, height, err := term.GetSize(fd)
171+
if err != nil {
172+
width = WidthTerminal
173+
height = HeightTerminal
174+
}
175+
150176
modes := ssh.TerminalModes{
151-
ssh.ECHO: DisableEcho,
152-
ssh.IGNCR: IgnoreCR,
177+
ssh.ECHO: EnableMod,
178+
ssh.ICRNL: ICRNLMod,
179+
ssh.INLCR: INLCRMod,
180+
ssh.ISIG: ISIGMod,
181+
ssh.TTY_OP_ISPEED: ISPEED,
182+
ssh.TTY_OP_OSPEED: OSPEED,
153183
}
154184

155-
err := session.RequestPty(TypeTerm, HeightTerminal, WidthTerminal, modes)
156-
if err != nil {
185+
if err = session.RequestPty(TypeTerm, height, width, modes); err != nil {
157186
logger.Error(err.Error())
158187
return err
159188
}

0 commit comments

Comments
 (0)