Skip to content

Commit 39e82e6

Browse files
committed
cli/streams: move constructors to the start
It's more idiomatic to define the constructor before methods. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 34805dd commit 39e82e6

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

cli/streams/in.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ type In struct {
1515
in io.ReadCloser
1616
}
1717

18+
// NewIn returns a new [In] from an [io.ReadCloser].
19+
func NewIn(in io.ReadCloser) *In {
20+
i := &In{in: in}
21+
i.fd, i.isTerminal = term.GetFdInfo(in)
22+
return i
23+
}
24+
1825
// Read implements the [io.Reader] interface.
1926
func (i *In) Read(p []byte) (int, error) {
2027
return i.in.Read(p)
@@ -47,10 +54,3 @@ func (i *In) CheckTty(attachStdin, ttyMode bool) error {
4754
}
4855
return nil
4956
}
50-
51-
// NewIn returns a new [In] from an [io.ReadCloser].
52-
func NewIn(in io.ReadCloser) *In {
53-
i := &In{in: in}
54-
i.fd, i.isTerminal = term.GetFdInfo(in)
55-
return i
56-
}

cli/streams/out.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ type Out struct {
1515
out io.Writer
1616
}
1717

18+
// NewOut returns a new [Out] from an [io.Writer].
19+
func NewOut(out io.Writer) *Out {
20+
o := &Out{out: out}
21+
o.fd, o.isTerminal = term.GetFdInfo(out)
22+
return o
23+
}
24+
1825
func (o *Out) Write(p []byte) (int, error) {
1926
return o.out.Write(p)
2027
}
@@ -44,10 +51,3 @@ func (o *Out) GetTtySize() (height uint, width uint) {
4451
}
4552
return uint(ws.Height), uint(ws.Width)
4653
}
47-
48-
// NewOut returns a new [Out] from an [io.Writer].
49-
func NewOut(out io.Writer) *Out {
50-
o := &Out{out: out}
51-
o.fd, o.isTerminal = term.GetFdInfo(out)
52-
return o
53-
}

0 commit comments

Comments
 (0)