feat: split into code for buffer and vm

This commit is contained in:
2026-07-20 00:32:34 +05:30
parent 5550c92c23
commit 208820217c
4 changed files with 149 additions and 126 deletions
+30
View File
@@ -0,0 +1,30 @@
package buffer
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
type InputBuffer struct {
Buffer string
Reader *bufio.Reader
}
func NewInputBuffer() *InputBuffer {
return &InputBuffer{
Buffer: "",
Reader: bufio.NewReader(os.Stdin),
}
}
func (inputBuffer *InputBuffer) ReadConsole() {
line, err := inputBuffer.Reader.ReadString('\n')
if err != nil && err != io.EOF {
fmt.Println("Error reading input", err)
os.Exit(1)
}
inputBuffer.Buffer = strings.TrimSpace(line)
}