github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/minterm/minterm_nix.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  //go:build !windows
     5  // +build !windows
     6  
     7  package minterm
     8  
     9  import (
    10  	"io"
    11  	"os"
    12  
    13  	"github.com/keybase/go-crypto/ssh/terminal"
    14  )
    15  
    16  func (m *MinTerm) open() error {
    17  	f, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
    18  	if err != nil {
    19  		return err
    20  	}
    21  	m.termIn = f
    22  	m.termOut = f
    23  	m.closeTermOut = false // since it's repeated
    24  	fd := int(f.Fd())
    25  	w, h, err := terminal.GetSize(fd)
    26  	if err != nil {
    27  		return err
    28  	}
    29  	m.width, m.height = w, h
    30  	return nil
    31  }
    32  
    33  func (m *MinTerm) getReadWriter() io.ReadWriter {
    34  	return m.termIn
    35  }