Skip to content

Commit 2f46263

Browse files
committed
Only set buffer type to stdout when no file args are passed
Fixes #2600
1 parent 9183fbe commit 2f46263

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

cmd/micro/micro.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ func LoadInput(args []string) []*buffer.Buffer {
163163
var err error
164164
buffers := make([]*buffer.Buffer, 0, len(args))
165165

166-
btype := buffer.BTDefault
167-
if !isatty.IsTerminal(os.Stdout.Fd()) {
168-
btype = buffer.BTStdout
169-
}
170-
171166
files := make([]string, 0, len(args))
172167

173168
flagStartPos := buffer.Loc{-1, -1}
@@ -218,6 +213,8 @@ func LoadInput(args []string) []*buffer.Buffer {
218213
SearchAfterStart: searchIndex > posIndex,
219214
}
220215

216+
btype := buffer.BTDefault
217+
221218
if len(files) > 0 {
222219
// Option 1
223220
// We go through each file and load it
@@ -230,19 +227,24 @@ func LoadInput(args []string) []*buffer.Buffer {
230227
// If the file didn't exist, input will be empty, and we'll open an empty buffer
231228
buffers = append(buffers, buf)
232229
}
233-
} else if !isatty.IsTerminal(os.Stdin.Fd()) {
234-
// Option 2
235-
// The input is not a terminal, so something is being piped in
236-
// and we should read from stdin
237-
input, err = io.ReadAll(os.Stdin)
238-
if err != nil {
239-
screen.TermMessage("Error reading from stdin: ", err)
240-
input = []byte{}
241-
}
242-
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
243230
} else {
244-
// Option 3, just open an empty buffer
245-
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
231+
if !isatty.IsTerminal(os.Stdout.Fd()) {
232+
btype = buffer.BTStdout
233+
}
234+
if !isatty.IsTerminal(os.Stdin.Fd()) {
235+
// Option 2
236+
// The input is not a terminal, so something is being piped in
237+
// and we should read from stdin
238+
input, err = io.ReadAll(os.Stdin)
239+
if err != nil {
240+
screen.TermMessage("Error reading from stdin: ", err)
241+
input = []byte{}
242+
}
243+
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
244+
} else {
245+
// Option 3, just open an empty buffer
246+
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
247+
}
246248
}
247249

248250
return buffers

0 commit comments

Comments
 (0)