Hunter,

When you write

input.Scan()

you are discarding important information, the return value.

$ go doc bufio.scan
func (s *Scanner) Scan() bool

With the return value, you have an easy test for io.EOF. For example,

scan := input.Scan()
eof := !scan && input.Err() == nil
.
Peter

On Tuesday, September 4, 2018 at 11:28:12 AM UTC-4, Hunter Breathat wrote:
>
>
> I only had stated that bufio.Scan() doesn't return io.EOF as the doc stats 
> that it Err returns nil. Which is fine but hard to check for. But from what 
> I've seen the functionality that im looking for would need to check for the 
> SIG.KILL/EOF  on input. Now whether or not   i shoudlgo and alter the 
> bufio.Scanner to return io.EOF as an Err is a different thing. But that 
> would be a smidge excessive for just 1 minor functionality. 
> On Tuesday, 4 September 2018 09:53:43 UTC-4, peterGo wrote:
>>
>> Hunter,
>>
>> Your main.go file is 171 lines of dense code. If you reduced your issue 
>> to a small, working piece of code, people would be more likely help you.
>>
>> You say "bufio.Scan() doesn't return io.EOF." Why?
>>
>> $ go doc bufio.scanner
>> type Scanner struct {
>> }
>>
>>     Scanning stops unrecoverably at EOF, the first I/O error, or a token 
>> too
>>     large to fit in the buffer. 
>>
>> $ go doc bufio.scanner.scan
>> func (s *Scanner) Scan() bool
>>
>>     Scan advances the Scanner to the next token, which will then be 
>> available
>>     through the Bytes or Text method. It returns false when the scan 
>> stops,
>>     either by reaching the end of the input or an error. After Scan 
>> returns
>>     false, the Err method will return any error that occurred during 
>> scanning,
>>     except that if it was io.EOF, Err will return nil.
>>
>> For example,
>>
>> package main
>>
>> import (
>>     "bufio"
>>     "fmt"
>>     "io"
>>     "os"
>> )
>>
>> func main() {
>>     var input = bufio.NewScanner(os.Stdin)
>>     for input.Scan() {
>>         text := input.Text()
>>         fmt.Println(len(text), text)
>>     }
>>     if err := input.Err(); err != nil {
>>         fmt.Fprintln(os.Stderr, err)
>>         return
>>     }
>>     // input.Scan() == false && input.Err() == nil
>>     fmt.Println(io.EOF)
>> }
>>
>> Output:
>>
>> # On Linux, Ctrl-D for eof
>>
>> $ go run eof.go
>> asd
>> 3 asd
>> EOF
>> $
>>
>> Peter
>>
>> On Monday, September 3, 2018 at 12:49:12 PM UTC-4, Hunter Breathat wrote:
>>>
>>> Hey, so I'm currently trying to create a custom shell.
>>>
>>> I am currently trying to implement the EOF exit (^D). Currently, I am 
>>> able to use exit as input and a variety of other
>>> commands, platform-specific; anything, not windows related (WIP), but I 
>>> am having an issue with the EOF causing
>>> an infinite loop. If you could help that would be splendid.
>>>
>>> bufio.Scan() doesn't return io.EOF (So that's a bust even though that's 
>>> the current implementation) 
>>>
>>> GoShell Repo <https://github.com/NexisHunter/GoShell> 
>>>
>>> The section you are looking for is in the file: main.go.
>>>
>>> Thanks in advanced
>>> Hunter
>>>
>>> PS.
>>> If you are able to even possible walk me through it would help a bit.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to