当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.GetStdHandle函数代码示例

本文整理汇总了Golang中syscall.GetStdHandle函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStdHandle函数的具体用法?Golang GetStdHandle怎么用?Golang GetStdHandle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetStdHandle函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getNativeConsole

// getNativeConsole returns the console modes ('state') for the native Windows console
func getNativeConsole() (State, error) {
	var (
		err   error
		state State
	)

	// Get the handle to stdout
	if state.outHandle, err = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE); err != nil {
		return state, err
	}

	// Get the console mode from the consoles stdout handle
	if err = syscall.GetConsoleMode(state.outHandle, &state.outMode); err != nil {
		return state, err
	}

	// Get the handle to stdin
	if state.inHandle, err = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE); err != nil {
		return state, err
	}

	// Get the console mode from the consoles stdin handle
	if err = syscall.GetConsoleMode(state.inHandle, &state.inMode); err != nil {
		return state, err
	}

	return state, nil
}
开发者ID:Altiscale,项目名称:containerd,代码行数:29,代码来源:term_windows.go

示例2: wAllRedirects

func (d *SubprocessData) wAllRedirects(s *Subprocess, si *syscall.StartupInfo) error {
	var err error

	if si.StdInput, err = d.wInputRedirect(s.StdIn); err != nil {
		return err
	}
	if si.StdOutput, err = d.wOutputRedirect(s.StdOut, &d.stdOut); err != nil {
		return err
	}
	if s.JoinStdOutErr {
		si.StdErr = si.StdOutput
	} else {
		if si.StdErr, err = d.wOutputRedirect(s.StdErr, &d.stdErr); err != nil {
			return err
		}
	}
	if si.StdInput != syscall.InvalidHandle ||
		si.StdOutput != syscall.InvalidHandle ||
		si.StdErr != syscall.InvalidHandle {
		si.Flags |= syscall.STARTF_USESTDHANDLES

		if si.StdInput == syscall.InvalidHandle {
			si.StdInput, _ = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE)
		}
		if si.StdOutput == syscall.InvalidHandle {
			si.StdOutput, _ = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
		}
		if si.StdErr == syscall.InvalidHandle {
			si.StdErr, _ = syscall.GetStdHandle(syscall.STD_ERROR_HANDLE)
		}
	}
	return nil
}
开发者ID:petemoore,项目名称:runlib,代码行数:33,代码来源:subprocess_windows.go

示例3: Init

// Initializes termbox library. This function should be called before any other functions.
// After successful initialization, the library must be finalized using 'Close' function.
//
// Example usage:
//      err := termbox.Init()
//      if err != nil {
//              panic(err)
//      }
//      defer termbox.Close()
func Init() error {
	var err error

	in, err = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE)
	if err != nil {
		return err
	}
	out, err = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
	if err != nil {
		return err
	}

	err = get_console_mode(in, &orig_mode)
	if err != nil {
		return err
	}

	err = set_console_mode(in, enable_window_input)
	if err != nil {
		return err
	}

	go input_event_producer()

	return nil
}
开发者ID:swdunlop,项目名称:rawtty-go,代码行数:35,代码来源:api_windows.go

示例4: Init

// Initializes termbox library. This function should be called before any other functions.
// After successful initialization, the library must be finalized using 'Close' function.
//
// Example usage:
//      err := termbox.Init()
//      if err != nil {
//              panic(err)
//      }
//      defer termbox.Close()
func Init() error {
	var err error

	in, err = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE)
	if err != nil {
		return err
	}
	out, err = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
	if err != nil {
		return err
	}

	err = get_console_mode(in, &orig_mode)
	if err != nil {
		return err
	}

	err = set_console_mode(in, enable_window_input)
	if err != nil {
		return err
	}

	w, h := get_win_size(out)
	orig_screen = out
	out, err = create_console_screen_buffer()
	if err != nil {
		return err
	}

	err = set_console_screen_buffer_size(out, coord{short(w), short(h)})
	if err != nil {
		return err
	}

	err = set_console_active_screen_buffer(out)
	if err != nil {
		return err
	}

	show_cursor(false)
	termw, termh = get_term_size(out)
	back_buffer.init(termw, termh)
	front_buffer.init(termw, termh)
	back_buffer.clear()
	front_buffer.clear()
	clear()

	attrsbuf = make([]word, 0, termw*termh)
	charsbuf = make([]wchar, 0, termw*termh)
	diffbuf = make([]diff_msg, 0, 32)

	go input_event_producer()

	return nil
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:64,代码来源:api_windows.go

示例5: getStdHandle

func getStdHandle(stdhandle int) uintptr {
	handle, err := syscall.GetStdHandle(stdhandle)
	if err != nil {
		panic(fmt.Errorf("could not get standard io handle %d", stdhandle))
	}
	return uintptr(handle)
}
开发者ID:nicholaskh,项目名称:docker,代码行数:7,代码来源:console_windows.go

示例6: raw

// enable raw mode and gather metrics, like number of columns
func (l *LineReader) raw() {
	// STD_OUTPUT_HANDLE
	h, errno := syscall.GetStdHandle(-11)
	t.h = uintptr(h)
	if int32(t.h) == -1 {
		err := os.Errno(errno)
		panic(err)
	}
	ok, _, e := syscall.Syscall(procGetConsoleMode, 2,
		t.h, uintptr(unsafe.Pointer(&t.origTerm)), 0)
	if ok == 0 {
		err := os.NewSyscallError("GetConsoleMode", int(e))
		panic(err)
	}

	raw := t.origTerm
	raw &^= _ENABLE_LINE_INPUT | _ENABLE_ECHO_INPUT | _ENABLE_PROCESSED_INPUT | _ENABLE_WINDOW_INPUT
	ok, _, e = syscall.Syscall(procSetConsoleMode, 2, t.h, uintptr(raw), 0)
	if ok == 0 {
		err := os.NewSyscallError("SetConsoleMode", int(e))
		panic(err)
	}

	win := t.getConsoleInfo()
	t.cols = int(win.dwSize.x)
	t.rows = int(win.dwSize.y)

	t.buf = new(buffer)
}
开发者ID:sbinet,项目名称:fineline,代码行数:30,代码来源:windows.go

示例7: useNativeConsole

// useNativeConsole determines if the docker client should use the built-in
// console which supports ANSI emulation, or fall-back to the golang emulator
// (github.com/azure/go-ansiterm).
func useNativeConsole() bool {
	osv, err := system.GetOSVersion()
	if err != nil {
		return false
	}

	// Native console is not available major version 10
	if osv.MajorVersion < 10 {
		return false
	}

	// Must have a late pre-release TP4 build of Windows Server 2016/Windows 10 TH2 or later
	if osv.Build < 10578 {
		return false
	}

	// Environment variable override
	if e := os.Getenv("USE_NATIVE_CONSOLE"); e != "" {
		if e == "1" {
			return true
		}
		return false
	}

	// Get the handle to stdout
	stdOutHandle, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
	if err != nil {
		return false
	}

	// Get the console mode from the consoles stdout handle
	var mode uint32
	if err := syscall.GetConsoleMode(stdOutHandle, &mode); err != nil {
		return false
	}

	// Legacy mode does not have native ANSI emulation.
	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
	const enableVirtualTerminalProcessing = 0x0004
	if mode&enableVirtualTerminalProcessing == 0 {
		return false
	}

	// TODO Windows (Post TP4). The native emulator still has issues which
	// mean it shouldn't be enabled for everyone. Change this next line to true
	// to change the default to "enable if available". In the meantime, users
	// can still try it out by using USE_NATIVE_CONSOLE env variable.
	return false
}
开发者ID:Test-Betta-Inc,项目名称:psychic-barnacle,代码行数:52,代码来源:term_windows.go

示例8: Width

func Width() int {
	outHandle, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
	if err != nil {
		return 0
	}

	info := &consoleScreenBufferInfo{}
	success, _, _ := syscall.Syscall(getConsoleScreenBufferInfo.Addr(), 2, uintptr(outHandle), uintptr(unsafe.Pointer(info)), 0)
	if int(success) == 0 {
		return 0
	}

	cols := int(info.size.x)
	if cols > 0 {
		cols--
	}

	return cols
}
开发者ID:peer23peer,项目名称:TMSU,代码行数:19,代码来源:terminal_windows.go

示例9: GetStdFile

func GetStdFile(nFile int) (*os.File, uintptr) {
	var file *os.File
	switch nFile {
	case syscall.STD_INPUT_HANDLE:
		file = os.Stdin
	case syscall.STD_OUTPUT_HANDLE:
		file = os.Stdout
	case syscall.STD_ERROR_HANDLE:
		file = os.Stderr
	default:
		panic(fmt.Errorf("Invalid standard handle identifier: %v", nFile))
	}

	fd, err := syscall.GetStdHandle(nFile)
	if err != nil {
		panic(fmt.Errorf("Invalid standard handle indentifier: %v -- %v", nFile, err))
	}

	return file, uintptr(fd)
}
开发者ID:eldarion-gondor,项目名称:cli,代码行数:20,代码来源:ansi.go

示例10: initPanicFile

func initPanicFile(path string) error {
	var err error
	panicFile, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0)
	if err != nil {
		return err
	}

	st, err := panicFile.Stat()
	if err != nil {
		return err
	}

	// If there are contents in the file already, move the file out of the way
	// and replace it.
	if st.Size() > 0 {
		panicFile.Close()
		os.Rename(path, path+".old")
		panicFile, err = os.Create(path)
		if err != nil {
			return err
		}
	}

	// Update STD_ERROR_HANDLE to point to the panic file so that Go writes to
	// it when it panics. Remember the old stderr to restore it before removing
	// the panic file.
	sh := syscall.STD_ERROR_HANDLE
	h, err := syscall.GetStdHandle(sh)
	if err != nil {
		return err
	}

	oldStderr = h

	r, _, err := setStdHandle.Call(uintptr(sh), uintptr(panicFile.Fd()))
	if r == 0 && err != nil {
		return err
	}

	return nil
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:41,代码来源:service_windows.go

示例11: getColorableWriter

// getColorableWriter will return a writer that is capable
// of interpreting ANSI escape codes for terminal colors.
func getColorableWriter() io.Writer {
	if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
		// The ConEmu terminal is installed. Use it.
		return os.Stdout
	}

	const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004

	h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
	if err != nil {
		return os.Stdout
	}
	var m uint32
	err = syscall.GetConsoleMode(h, &m)
	if err != nil {
		return os.Stdout
	}
	if m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
		return os.Stdout
	}
	return colorable.NewColorableStdout()
}
开发者ID:alexbrainman,项目名称:delve,代码行数:24,代码来源:terminal_windows.go

示例12: getStdHandle

func getStdHandle(h int) (fd syscall.Handle) {
	r, _ := syscall.GetStdHandle(h)
	syscall.CloseOnExec(r)
	return r
}
开发者ID:heavenshell,项目名称:peco,代码行数:5,代码来源:tty_windows.go

示例13: GetLocate

package conio

import (
	"syscall"
)

var hConout, _ = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)

func GetLocate() (int, int) {
	csbi := GetScreenBufferInfo()
	return int(csbi.CursorPosition.X), int(csbi.CursorPosition.Y)
}

func Locate(x, y int) {
	csbi := coord_t{X: int16(x), Y: int16(y)}
	setConsoleCursorPosition.Call(uintptr(hConout), csbi.Pack())
}
开发者ID:tyochiai,项目名称:nyagos,代码行数:17,代码来源:locate.go


注:本文中的syscall.GetStdHandle函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。