mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Merge pull request #3910 from AndydeCleyre/bugfix/2600
Only set buffer type to stdout when no file args are passed
This commit is contained in:
@@ -158,16 +158,8 @@ func LoadInput(args []string) []*buffer.Buffer {
|
|||||||
// 3. If there is no input file and the input is a terminal, an empty buffer
|
// 3. If there is no input file and the input is a terminal, an empty buffer
|
||||||
// should be opened
|
// should be opened
|
||||||
|
|
||||||
var filename string
|
|
||||||
var input []byte
|
|
||||||
var err error
|
|
||||||
buffers := make([]*buffer.Buffer, 0, len(args))
|
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))
|
files := make([]string, 0, len(args))
|
||||||
|
|
||||||
flagStartPos := buffer.Loc{-1, -1}
|
flagStartPos := buffer.Loc{-1, -1}
|
||||||
@@ -222,7 +214,7 @@ func LoadInput(args []string) []*buffer.Buffer {
|
|||||||
// Option 1
|
// Option 1
|
||||||
// We go through each file and load it
|
// We go through each file and load it
|
||||||
for i := 0; i < len(files); i++ {
|
for i := 0; i < len(files); i++ {
|
||||||
buf, err := buffer.NewBufferFromFileWithCommand(files[i], btype, command)
|
buf, err := buffer.NewBufferFromFileWithCommand(files[i], buffer.BTDefault, command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
screen.TermMessage(err)
|
screen.TermMessage(err)
|
||||||
continue
|
continue
|
||||||
@@ -230,19 +222,26 @@ func LoadInput(args []string) []*buffer.Buffer {
|
|||||||
// If the file didn't exist, input will be empty, and we'll open an empty buffer
|
// If the file didn't exist, input will be empty, and we'll open an empty buffer
|
||||||
buffers = append(buffers, buf)
|
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 {
|
} else {
|
||||||
// Option 3, just open an empty buffer
|
btype := buffer.BTDefault
|
||||||
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), filename, btype, command))
|
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{}
|
||||||
|
}
|
||||||
|
buffers = append(buffers, buffer.NewBufferFromStringWithCommand(string(input), "", btype, command))
|
||||||
|
} else {
|
||||||
|
// Option 3, just open an empty buffer
|
||||||
|
buffers = append(buffers, buffer.NewBufferFromStringWithCommand("", "", btype, command))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffers
|
return buffers
|
||||||
|
|||||||
Reference in New Issue
Block a user