Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ func LoadInput(args []string) []*buffer.Buffer {
var err error
buffers := make([]*buffer.Buffer, 0, len(args))

btype := buffer.BTDefault
if !isatty.IsTerminal(os.Stdout.Fd()) {
btype = buffer.BTStdout
}

files := make([]string, 0, len(args))

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

btype := buffer.BTDefault

if len(files) > 0 {
// Option 1
// We go through each file and load it
Expand All @@ -230,18 +227,21 @@ func LoadInput(args []string) []*buffer.Buffer {
// If the file didn't exist, input will be empty, and we'll open an empty buffer
buffers = append(buffers, buf)
}
} else if !isatty.IsTerminal(os.Stdin.Fd()) {
// Option 2
// The input is not a terminal, so something is being piped in
// and we should read from stdin
input, err = io.ReadAll(os.Stdin)
if err != nil {
screen.TermMessage("Error reading from stdin: ", err)
input = []byte{}
}
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
} else {
// Option 3, just open an empty buffer
if !isatty.IsTerminal(os.Stdout.Fd()) {
btype = buffer.BTStdout
}
if !isatty.IsTerminal(os.Stdin.Fd()) {
// Option 2
// The input is not a terminal, so something is being piped in
// and we should read from stdin
input, err = io.ReadAll(os.Stdin)
if err != nil {
screen.TermMessage("Error reading from stdin: ", err)
input = []byte{}
}
}
// Open either stdin (Option 2) or an empty buffer (Option 3)
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
}

Expand Down