All Projects → creack → Pty

creack / Pty

Licence: mit
PTY interface for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Pty

Saldl
A lightweight well-featured CLI downloader optimized for speed and early preview.
Stars: ✭ 203 (-77.49%)
Mutual labels:  tty, cross-platform
Tty Which
Cross-platform implementation of Unix `which` command
Stars: ✭ 11 (-98.78%)
Mutual labels:  tty, cross-platform
Everest
A beautiful, cross-platform REST client.
Stars: ✭ 785 (-12.97%)
Mutual labels:  cross-platform
Parcel
Cross-platform PowerShell package manager and provisioner
Stars: ✭ 17 (-98.12%)
Mutual labels:  cross-platform
Nodegui
A library for building cross-platform native desktop applications with Node.js and CSS 🚀. React NodeGui : https://react.nodegui.org and Vue NodeGui: https://vue.nodegui.org
Stars: ✭ 7,324 (+711.97%)
Mutual labels:  cross-platform
Flyingcarpet
Encrypted file transfer over ad hoc WiFi. No network infrastructure required, just two laptops in close range. Linux, Mac, and Windows.
Stars: ✭ 788 (-12.64%)
Mutual labels:  cross-platform
Node Cross Spawn
A cross platform solution to node's spawn and spawnSync
Stars: ✭ 831 (-7.87%)
Mutual labels:  cross-platform
Fkill Cli
Fabulously kill processes. Cross-platform.
Stars: ✭ 6,418 (+611.53%)
Mutual labels:  cross-platform
Slicergitsvnarchive
Multi-platform, free open source software for visualization and image computing.
Stars: ✭ 896 (-0.67%)
Mutual labels:  cross-platform
Fluidsynth
Software synthesizer based on the SoundFont 2 specifications
Stars: ✭ 811 (-10.09%)
Mutual labels:  cross-platform
Leaf3d
A lightweight 3D rendering engine based on modern OpenGL
Stars: ✭ 16 (-98.23%)
Mutual labels:  cross-platform
Azurite
A lightweight server clone of Azure Storage that simulates most of the commands supported by it with minimal dependencies
Stars: ✭ 810 (-10.2%)
Mutual labels:  cross-platform
Fluttercinematic
Flutter clone of my "Cinematic" App
Stars: ✭ 787 (-12.75%)
Mutual labels:  cross-platform
Notlitecode
Remote Encrypted Procedure Calling for .Net & .Net Core
Stars: ✭ 16 (-98.23%)
Mutual labels:  cross-platform
Git Interactive Rebase Tool
Native cross-platform full feature terminal-based sequence editor for git interactive rebase.
Stars: ✭ 786 (-12.86%)
Mutual labels:  cross-platform
Brainpowerapp
A visual memory training game, a mobile game made with Xamarin for both Android and IOS .
Stars: ✭ 17 (-98.12%)
Mutual labels:  cross-platform
Essential Ui Kit For Xamarin.forms
Free and beautiful XAML template pages for Xamarin.Forms apps.
Stars: ✭ 780 (-13.53%)
Mutual labels:  cross-platform
Mojoc
A cross-platform, open-source, pure C game engine for mobile game.
Stars: ✭ 799 (-11.42%)
Mutual labels:  cross-platform
Sfml
Simple and Fast Multimedia Library
Stars: ✭ 7,316 (+711.09%)
Mutual labels:  cross-platform
Gors
go实现的终端录屏程序
Stars: ✭ 19 (-97.89%)
Mutual labels:  tty

pty

Pty is a Go package for using unix pseudo-terminals.

Install

go get github.com/creack/pty

Example

Command

package main

import (
	"io"
	"os"
	"os/exec"

	"github.com/creack/pty"
)

func main() {
	c := exec.Command("grep", "--color=auto", "bar")
	f, err := pty.Start(c)
	if err != nil {
		panic(err)
	}

	go func() {
		f.Write([]byte("foo\n"))
		f.Write([]byte("bar\n"))
		f.Write([]byte("baz\n"))
		f.Write([]byte{4}) // EOT
	}()
	io.Copy(os.Stdout, f)
}

Shell

package main

import (
        "io"
        "log"
        "os"
        "os/exec"
        "os/signal"
        "syscall"

        "github.com/creack/pty"
        "golang.org/x/term"
)

func test() error {
        // Create arbitrary command.
        c := exec.Command("bash")

        // Start the command with a pty.
        ptmx, err := pty.Start(c)
        if err != nil {
                return err
        }
        // Make sure to close the pty at the end.
        defer func() { _ = ptmx.Close() }() // Best effort.

        // Handle pty size.
        ch := make(chan os.Signal, 1)
        signal.Notify(ch, syscall.SIGWINCH)
        go func() {
                for range ch {
                        if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
                                log.Printf("error resizing pty: %s", err)
                        }
                }
        }()
        ch <- syscall.SIGWINCH // Initial resize.

        // Set stdin in raw mode.
        oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
        if err != nil {
                panic(err)
        }
        defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.

        // Copy stdin to the pty and the pty to stdout.
        go func() { _, _ = io.Copy(ptmx, os.Stdin) }()
        _, _ = io.Copy(os.Stdout, ptmx)

        return nil
}

func main() {
        if err := test(); err != nil {
                log.Fatal(err)
        }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].