okami.mom/ultraviolet

git clone https://git.nkp.pet/okami.mom/ultraviolet

Ayman Bagabasfeat: add cross-platform console I/O interface (#78)6ea2266

main
1007 B39 linesraw
1//go:build windows
2// +build windows
3
4package uv
5
6import (
7	"context"
8	"os"
9	"os/signal"
10)
11
12func openTTY() (inTty, outTty *os.File, err error) {
13	// On Windows, when the input/output is redirected or piped, we need to
14	// open the console explicitly.
15	// See https://learn.microsoft.com/en-us/windows/console/getstdhandle#remarks
16	inTty, err = os.OpenFile("CONIN$", os.O_RDWR, 0o644) //nolint:gosec
17	if err != nil {
18		return nil, nil, err //nolint:wrapcheck
19	}
20	outTty, err = os.OpenFile("CONOUT$", os.O_RDWR, 0o644) //nolint:gosec
21	if err != nil {
22		return nil, nil, err //nolint:wrapcheck
23	}
24	return inTty, outTty, nil
25}
26
27func suspend() (err error) {
28	// On Windows, suspending the process group is not supported in the same
29	// way as Unix-like systems.
30	return nil
31}
32
33func notifyWinch(c chan os.Signal, sigs ...os.Signal) {
34	signal.Notify(c, sigs...)
35}
36
37func notifyWinchContext(ctx context.Context, sigs ...os.Signal) (context.Context, context.CancelFunc) {
38	return signal.NotifyContext(ctx, sigs...)
39}