-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_windows.go
More file actions
101 lines (86 loc) · 2.82 KB
/
session_windows.go
File metadata and controls
101 lines (86 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//go:build windows
// +build windows
package sip
import (
"io"
"os"
)
// platformPty holds platform-specific PTY resources.
// On Windows, we use io.Pipe() since ConPty is designed for spawning
// child processes, not for in-process terminal emulation.
type platformPty struct {
// Pipes for terminal I/O
inputReader *io.PipeReader // Bubble Tea reads input from here
inputWriter *io.PipeWriter // Handler writes input here
outputReader *io.PipeReader // Handler reads output from here
outputWriter *io.PipeWriter // Bubble Tea writes output here
// Fake slave file for Bubble Tea compatibility
// On Windows, we create a pipe-based solution
slaveReadFile *os.File
slaveWriteFile *os.File
}
// newPlatformPty creates pipe-based I/O for Windows.
// We use io.Pipe() which provides proper synchronization.
// Note: cols/rows are unused on Windows since we don't have a real PTY;
// resize is handled via tea.WindowSizeMsg instead.
func newPlatformPty(_, _ int) (*platformPty, error) {
// Create pipes for input (handler -> Bubble Tea)
inputReader, inputWriter := io.Pipe()
// Create pipes for output (Bubble Tea -> handler)
outputReader, outputWriter := io.Pipe()
return &platformPty{
inputReader: inputReader,
inputWriter: inputWriter,
outputReader: outputReader,
outputWriter: outputWriter,
}, nil
}
// Close closes all pipe resources.
func (p *platformPty) Close() error {
if p.inputReader != nil {
_ = p.inputReader.Close()
}
if p.inputWriter != nil {
_ = p.inputWriter.Close()
}
if p.outputReader != nil {
_ = p.outputReader.Close()
}
if p.outputWriter != nil {
_ = p.outputWriter.Close()
}
return nil
}
// Resize is a no-op on Windows since we use pipes.
// Resize is handled via tea.WindowSizeMsg instead.
func (p *platformPty) Resize(cols, rows int) error {
// No-op: resize is handled by sending tea.WindowSizeMsg directly
return nil
}
// OutputReader returns an io.Reader for reading terminal output.
// On Windows, this reads from the output pipe.
func (p *platformPty) OutputReader() io.Reader {
return p.outputReader
}
// InputWriter returns an io.Writer for writing terminal input.
// On Windows, this writes to the input pipe.
func (p *platformPty) InputWriter() io.Writer {
return p.inputWriter
}
// SlaveFile returns nil on Windows since we don't have a real PTY.
// Bubble Tea will use the pipe reader/writer directly via SlaveReader/SlaveWriter.
func (p *platformPty) SlaveFile() *os.File {
return nil
}
// SlaveFd returns 0 on Windows since we don't have a real PTY slave.
func (p *platformPty) SlaveFd() uintptr {
return 0
}
// SlaveReader returns the reader for Bubble Tea input on Windows.
func (p *platformPty) SlaveReader() io.Reader {
return p.inputReader
}
// SlaveWriter returns the writer for Bubble Tea output on Windows.
func (p *platformPty) SlaveWriter() io.Writer {
return p.outputWriter
}