forked from charmbracelet/bubbletea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports GOOS=js GOARCH=wasm go build containerd-console now has a shim for js as well: containerd/console#60 Update that dependency. Signed-off-by: Christian Stewart <christian@paral.in>
- Loading branch information
Showing
7 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -20,3 +20,5 @@ tutorials/basics/basics | |
tutorials/commands/commands | ||
.idea | ||
coverage.txt | ||
README.md.* | ||
vendor/ |
This file contains 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 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 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 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 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,12 @@ | ||
//go:build js | ||
// +build js | ||
|
||
package tea | ||
|
||
// listenForResize sends messages (or errors) when the terminal resizes. | ||
// Argument output should be the file descriptor for the terminal; usually | ||
// os.Stdout. | ||
func (p *Program) listenForResize(done chan struct{}) { | ||
// Do nothing on JS. | ||
close(done) | ||
} |
This file contains 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,47 @@ | ||
//go:build js | ||
// +build js | ||
|
||
package tea | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/containerd/console" | ||
) | ||
|
||
func (p *Program) initInput() error { | ||
// If input's a file, use console to manage it | ||
if f, ok := p.input.(*os.File); ok { | ||
// Save a reference to the current stdin then replace stdin with our | ||
// input. We do this so we can hand input off to containerd/console to | ||
// set raw mode, and do it in this fashion because the method | ||
// console.ConsoleFromFile isn't supported on JS. | ||
p.windowsStdin = os.Stdin | ||
os.Stdin = f | ||
|
||
// Note: this will panic if it fails. | ||
c := console.Current() | ||
p.console = c | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// restoreInput restores stdout in the event that we placed it aside to handle | ||
// input with CONIN$, above. | ||
func (p *Program) restoreInput() error { | ||
if p.windowsStdin != nil { | ||
os.Stdin = p.windowsStdin | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Open the JS equivalent of a TTY. | ||
func openInputTTY() (*os.File, error) { | ||
f, err := os.OpenFile("CONIN$", os.O_RDWR, 0644) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return f, nil | ||
} |