feat: split code for repl

This commit is contained in:
2026-07-19 23:33:02 +05:30
parent d97308b4f1
commit 5550c92c23
3 changed files with 50 additions and 39 deletions
+34
View File
@@ -0,0 +1,34 @@
package repl
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 PrintConsole() {
fmt.Print("godb > ")
}
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)
}