1*333d2b36SAndroid Build Coastguard Worker// Copyright 2018 Google Inc. All rights reserved. 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Worker// Package terminal provides a set of interfaces that can be used to interact 16*333d2b36SAndroid Build Coastguard Worker// with the terminal (including falling back when the terminal is detected to 17*333d2b36SAndroid Build Coastguard Worker// be a redirect or other dumb terminal) 18*333d2b36SAndroid Build Coastguard Workerpackage terminal 19*333d2b36SAndroid Build Coastguard Worker 20*333d2b36SAndroid Build Coastguard Workerimport ( 21*333d2b36SAndroid Build Coastguard Worker "io" 22*333d2b36SAndroid Build Coastguard Worker "os" 23*333d2b36SAndroid Build Coastguard Worker) 24*333d2b36SAndroid Build Coastguard Worker 25*333d2b36SAndroid Build Coastguard Worker// StdioInterface represents a set of stdin/stdout/stderr Reader/Writers 26*333d2b36SAndroid Build Coastguard Workertype StdioInterface interface { 27*333d2b36SAndroid Build Coastguard Worker Stdin() io.Reader 28*333d2b36SAndroid Build Coastguard Worker Stdout() io.Writer 29*333d2b36SAndroid Build Coastguard Worker Stderr() io.Writer 30*333d2b36SAndroid Build Coastguard Worker} 31*333d2b36SAndroid Build Coastguard Worker 32*333d2b36SAndroid Build Coastguard Worker// StdioImpl uses the OS stdin/stdout/stderr to implement StdioInterface 33*333d2b36SAndroid Build Coastguard Workertype StdioImpl struct{} 34*333d2b36SAndroid Build Coastguard Worker 35*333d2b36SAndroid Build Coastguard Workerfunc (StdioImpl) Stdin() io.Reader { return os.Stdin } 36*333d2b36SAndroid Build Coastguard Workerfunc (StdioImpl) Stdout() io.Writer { return os.Stdout } 37*333d2b36SAndroid Build Coastguard Workerfunc (StdioImpl) Stderr() io.Writer { return os.Stderr } 38*333d2b36SAndroid Build Coastguard Worker 39*333d2b36SAndroid Build Coastguard Workervar _ StdioInterface = StdioImpl{} 40*333d2b36SAndroid Build Coastguard Worker 41*333d2b36SAndroid Build Coastguard Workertype customStdio struct { 42*333d2b36SAndroid Build Coastguard Worker stdin io.Reader 43*333d2b36SAndroid Build Coastguard Worker stdout io.Writer 44*333d2b36SAndroid Build Coastguard Worker stderr io.Writer 45*333d2b36SAndroid Build Coastguard Worker} 46*333d2b36SAndroid Build Coastguard Worker 47*333d2b36SAndroid Build Coastguard Workerfunc NewCustomStdio(stdin io.Reader, stdout, stderr io.Writer) StdioInterface { 48*333d2b36SAndroid Build Coastguard Worker return customStdio{stdin, stdout, stderr} 49*333d2b36SAndroid Build Coastguard Worker} 50*333d2b36SAndroid Build Coastguard Worker 51*333d2b36SAndroid Build Coastguard Workerfunc (c customStdio) Stdin() io.Reader { return c.stdin } 52*333d2b36SAndroid Build Coastguard Workerfunc (c customStdio) Stdout() io.Writer { return c.stdout } 53*333d2b36SAndroid Build Coastguard Workerfunc (c customStdio) Stderr() io.Writer { return c.stderr } 54*333d2b36SAndroid Build Coastguard Worker 55*333d2b36SAndroid Build Coastguard Workervar _ StdioInterface = customStdio{} 56