Skip to content

Commit d1ceaca

Browse files
authored
Merge pull request #3910 from AndydeCleyre/bugfix/2600
Only set buffer type to stdout when no file args are passed
2 parents 118f5a3 + 331c43e commit d1ceaca

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

cmd/micro/micro.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,8 @@ func LoadInput(args []string) []*buffer.Buffer {
158158
// 3. If there is no input file and the input is a terminal, an empty buffer
159159
// should be opened
160160

161-
var filename string
162-
var input []byte
163-
var err error
164161
buffers := make([]*buffer.Buffer, 0, len(args))
165162

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

173165
flagStartPos := buffer.Loc{-1, -1}
@@ -222,27 +214,34 @@ func LoadInput(args []string) []*buffer.Buffer {
222214
// Option 1
223215
// We go through each file and load it
224216
for i := 0; i < len(files); i++ {
225-
buf, err := buffer.NewBufferFromFileWithCommand(files[i], btype, command)
217+
buf, err := buffer.NewBufferFromFileWithCommand(files[i], buffer.BTDefault, command)
226218
if err != nil {
227219
screen.TermMessage(err)
228220
continue
229221
}
230222
// If the file didn't exist, input will be empty, and we'll open an empty buffer
231223
buffers = append(buffers, buf)
232224
}
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))
243225
} else {
244-
// Option 3, just open an empty buffer
245-
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
226+
btype := buffer.BTDefault
227+
if !isatty.IsTerminal(os.Stdout.Fd()) {
228+
btype = buffer.BTStdout
229+
}
230+
231+
if !isatty.IsTerminal(os.Stdin.Fd()) {
232+
// Option 2
233+
// The input is not a terminal, so something is being piped in
234+
// and we should read from stdin
235+
input, err := io.ReadAll(os.Stdin)
236+
if err != nil {
237+
screen.TermMessage("Error reading from stdin: ", err)
238+
input = []byte{}
239+
}
240+
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), "", btype, command))
241+
} else {
242+
// Option 3, just open an empty buffer
243+
buffers = append(buffers, buffer.NewBufferFromStringWithCommand("", "", btype, command))
244+
}
246245
}
247246

248247
return buffers

0 commit comments

Comments
 (0)