Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit e031b9c

Browse files
authored
chore: remove dead xterminal code (#298)
1 parent 11c28a2 commit e031b9c

File tree

2 files changed

+0
-153
lines changed

2 files changed

+0
-153
lines changed

internal/x/xterminal/terminal.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,14 @@
33
package xterminal
44

55
import (
6-
"context"
7-
"os"
8-
"os/signal"
9-
106
"golang.org/x/crypto/ssh/terminal"
11-
"golang.org/x/sys/unix"
127
)
138

149
// State differs per-platform.
1510
type State struct {
1611
s *terminal.State
1712
}
1813

19-
// MakeRaw sets the terminal to raw.
20-
func MakeRaw(fd uintptr) (*State, error) {
21-
previousState, err := terminal.MakeRaw(int(fd))
22-
if err != nil {
23-
return nil, err
24-
}
25-
return &State{s: previousState}, nil
26-
}
27-
2814
// MakeOutputRaw does nothing on non-Windows platforms.
2915
func MakeOutputRaw(fd uintptr) (*State, error) { return nil, nil }
3016

@@ -36,60 +22,3 @@ func Restore(fd uintptr, state *State) error {
3622

3723
return terminal.Restore(int(fd), state.s)
3824
}
39-
40-
// ColorEnabled returns true on Linux if handle is a terminal.
41-
func ColorEnabled(fd uintptr) (bool, error) {
42-
return terminal.IsTerminal(int(fd)), nil
43-
}
44-
45-
// ResizeEvent describes the new terminal dimensions following a resize.
46-
type ResizeEvent struct {
47-
Height uint16
48-
Width uint16
49-
}
50-
51-
// ResizeEvents sends terminal resize events.
52-
func ResizeEvents(ctx context.Context, termFD uintptr) chan ResizeEvent {
53-
// Use a buffered chan to avoid blocking when we emit the initial resize event.
54-
// We send the event right away while the main routine might not be ready just yet.
55-
events := make(chan ResizeEvent, 1)
56-
57-
go func() {
58-
sigChan := make(chan os.Signal, 16) // Arbitrary large buffer size to allow for "continuous" resizing without blocking.
59-
defer close(sigChan)
60-
61-
// Terminal resize event are notified using the SIGWINCH signal, start watching for it.
62-
signal.Notify(sigChan, unix.SIGWINCH)
63-
defer signal.Stop(sigChan)
64-
65-
// Emit an initial signal event to make sure the server receives our current window size.
66-
select {
67-
case <-ctx.Done():
68-
return
69-
case sigChan <- unix.SIGWINCH:
70-
}
71-
72-
for {
73-
select {
74-
case <-ctx.Done():
75-
return
76-
case <-sigChan:
77-
width, height, err := terminal.GetSize(int(termFD))
78-
if err != nil {
79-
return
80-
}
81-
event := ResizeEvent{
82-
Height: uint16(height),
83-
Width: uint16(width),
84-
}
85-
select {
86-
case <-ctx.Done():
87-
return
88-
case events <- event:
89-
}
90-
}
91-
}
92-
}()
93-
94-
return events
95-
}

internal/x/xterminal/terminal_windows.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
package xterminal
44

55
import (
6-
"context"
7-
"time"
8-
9-
"golang.org/x/crypto/ssh/terminal"
106
"golang.org/x/sys/windows"
117
)
128

@@ -36,16 +32,6 @@ func makeRaw(handle windows.Handle, input bool) (uint32, error) {
3632
return prevState, nil
3733
}
3834

39-
// MakeRaw sets an input terminal to raw and enables VT100 processing.
40-
func MakeRaw(handle uintptr) (*State, error) {
41-
prevState, err := makeRaw(windows.Handle(handle), true)
42-
if err != nil {
43-
return nil, err
44-
}
45-
46-
return &State{mode: prevState}, nil
47-
}
48-
4935
// MakeOutputRaw sets an output terminal to raw and enables VT100 processing.
5036
func MakeOutputRaw(handle uintptr) (*State, error) {
5137
prevState, err := makeRaw(windows.Handle(handle), false)
@@ -60,71 +46,3 @@ func MakeOutputRaw(handle uintptr) (*State, error) {
6046
func Restore(handle uintptr, state *State) error {
6147
return windows.SetConsoleMode(windows.Handle(handle), state.mode)
6248
}
63-
64-
// ColorEnabled returns true if VT100 processing is enabled on the output
65-
// console.
66-
func ColorEnabled(handle uintptr) (bool, error) {
67-
var state uint32
68-
if err := windows.GetConsoleMode(windows.Handle(handle), &state); err != nil {
69-
return false, err
70-
}
71-
72-
return state&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0, nil
73-
}
74-
75-
// ResizeEvent represent the new size of the terminal.
76-
type ResizeEvent struct {
77-
Height uint16
78-
Width uint16
79-
}
80-
81-
func (s ResizeEvent) equal(s2 *ResizeEvent) bool {
82-
if s2 == nil {
83-
return false
84-
}
85-
return s.Height == s2.Height && s.Width == s2.Width
86-
}
87-
88-
// ResizeEvents sends terminal resize events when the dimensions change.
89-
// Windows does not have a unix.SIGWINCH equivalent, so we poll the terminal size
90-
// at a fixed interval
91-
func ResizeEvents(ctx context.Context, termFD uintptr) chan ResizeEvent {
92-
// Use a buffered chan to avoid blocking if the main is not ready yet when we send the initial resize event.
93-
events := make(chan ResizeEvent, 1)
94-
95-
go func() {
96-
defer close(events)
97-
98-
// On windows, as we don't have a signal to know the size changed, we
99-
// use a ticker and emit then event if the current size differs from last time we checked.
100-
ticker := time.NewTicker(100 * time.Millisecond)
101-
defer ticker.Stop()
102-
103-
var lastEvent *ResizeEvent
104-
for {
105-
select {
106-
case <-ctx.Done():
107-
return
108-
case <-ticker.C:
109-
width, height, err := terminal.GetSize(int(windows.Handle(termFD)))
110-
if err != nil {
111-
return
112-
}
113-
event := ResizeEvent{
114-
Height: uint16(height),
115-
Width: uint16(width),
116-
}
117-
if !event.equal(lastEvent) {
118-
select {
119-
case <-ctx.Done():
120-
return
121-
case events <- event:
122-
}
123-
}
124-
lastEvent = &event
125-
}
126-
}
127-
}()
128-
129-
return events
130-
}

0 commit comments

Comments
 (0)