Thanks!
I've changed the code to this:
var console *bufio.ReadWriter
var cmd string
func (g *Game) Parse() {
// reader should be wrapped inside an _input() function.
for {
console = bufio.NewReadWriter(
bufio.NewReader(os.Stdin),
bufio.NewWriter(os.Stdout))
fmt.Print(">>> ")
cmd, _ = console.ReadString('\n')
switch cmd {
...
...
Now my thinking is that I should be able to simply assign "cmd" from
anywhere outside the loop
followed by a newline character (i e "cmd = "Test \n") and the reader
should pick it up as if it was a manual input.
Unfortunately, that doesn't quite seem to work yet.
On Wednesday, 29 May 2019 19:26:58 UTC+2, Mark Bauermeister wrote:
>
> I'm in the process of writing a text adventure parser.
> By default, the parser simply uses Stdin.
>
> i e
>
> for {
> fmt.Print(">>> ")
>
> reader := bufio.NewScanner(os.Stdin)
> for reader.Scan() {
> switch reader.Text() {
> ...
> ...
>
> This is quite convenient. However, I now want to be able to pass in text
> from outside this for-loop. Say I have a function "Invoke(arg string)"
> which I should be able to call to pass
> arguments straight to the Scanner interface.
>
> What would be the most straightforward way to achieve this?
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/1ad89796-0624-47ad-9fdf-ad6c4786c025%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.