This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Adds support for windows #79
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Adds support for windows
Change-Id: I2797929cfa72752932e334fc44614095eb1cdea6
- Loading branch information
commit 6a5fbc59b5de413cc1d560080458ecb3635dbb7f
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
"golang.org/x/sys/unix" | ||
|
||
"go.coder.com/flog" | ||
) | ||
|
||
func resizeEvents(ctx context.Context, termfd int) chan resizeEvent { | ||
sigs := make(chan os.Signal, 16) | ||
signal.Notify(sigs, unix.SIGWINCH) | ||
|
||
events := make(chan resizeEvent) | ||
|
||
go func() { | ||
for ctx.Err() == nil { | ||
width, height, err := terminal.GetSize(termfd) | ||
if err != nil { | ||
flog.Error("get term size: %v", err) | ||
break | ||
} | ||
events <- resizeEvent{ | ||
height: uint16(height), | ||
width: uint16(width), | ||
} | ||
|
||
<-sigs | ||
} | ||
}() | ||
|
||
return events | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build windows | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
|
||
"go.coder.com/flog" | ||
) | ||
|
||
// windows does have a unix.SIGWINCH equivalent, so we poll the terminal size | ||
// and send resize events when needed | ||
func resizeEvents(ctx context.Context, termfd int) chan resizeEvent { | ||
events := make(chan resizeEvent) | ||
t := time.Tick(time.Millisecond * 100) | ||
|
||
go func() { | ||
var lastEvent *resizeEvent | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
break | ||
case <-t: | ||
width, height, err := terminal.GetSize(termfd) | ||
if err != nil { | ||
flog.Error("get term size: %v", err) | ||
break | ||
} | ||
event := resizeEvent{ | ||
height: uint16(height), | ||
width: uint16(width), | ||
} | ||
if !event.equal(lastEvent) { | ||
events <- event | ||
} | ||
lastEvent = &event | ||
} | ||
} | ||
}() | ||
|
||
return events | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.