|
|
|
@ -21,6 +21,7 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
|
|
"git.rawtext.club/sloum/slope/termios"
|
|
|
|
|
)
|
|
|
|
@ -1099,33 +1100,57 @@ var stdLibrary = vars{
|
|
|
|
|
// error is encountered while reading return the
|
|
|
|
|
// output if the len(buffer) > 0, otherwise an
|
|
|
|
|
// exception
|
|
|
|
|
|
|
|
|
|
byteBuf := make([]byte, 0, 3)
|
|
|
|
|
b := make([]byte, 1)
|
|
|
|
|
|
|
|
|
|
switch f := obj.Obj.(type) {
|
|
|
|
|
case *os.File:
|
|
|
|
|
reader := bufio.NewReader(f)
|
|
|
|
|
char, _, err := reader.ReadRune()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return exception("'read-char' could not read from the given IOHandle")
|
|
|
|
|
for {
|
|
|
|
|
n, err := f.Read(b)
|
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
|
return exception("'read-char' could not read from the given IOHandle")
|
|
|
|
|
} else if err != nil || n == 0 {
|
|
|
|
|
return symbol("EOF")
|
|
|
|
|
}
|
|
|
|
|
byteBuf = append(byteBuf, b[0])
|
|
|
|
|
if utf8.FullRune(byteBuf) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%c", char)
|
|
|
|
|
return string(byteBuf)
|
|
|
|
|
case *net.Conn:
|
|
|
|
|
reader := bufio.NewReader(*f)
|
|
|
|
|
char, _, err := reader.ReadRune()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return exception("'read-char' could not read from the given IOHandle")
|
|
|
|
|
for {
|
|
|
|
|
n, err := (*f).Read(b)
|
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
|
return exception("'read-char' could not read from the given IOHandle")
|
|
|
|
|
} else if err != nil || n == 0 {
|
|
|
|
|
return symbol("EOF")
|
|
|
|
|
}
|
|
|
|
|
byteBuf = append(byteBuf, b[0])
|
|
|
|
|
if utf8.FullRune(byteBuf) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%c", char)
|
|
|
|
|
return string(byteBuf)
|
|
|
|
|
case *tls.Conn:
|
|
|
|
|
reader := bufio.NewReader(f)
|
|
|
|
|
char, _, err := reader.ReadRune()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return exception("'read-char' could not read from the given IOHandle")
|
|
|
|
|
for {
|
|
|
|
|
n, err := f.Read(b)
|
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
|
return exception("'read-char' could not read from the given IOHandle")
|
|
|
|
|
} else if err != nil || n == 0 {
|
|
|
|
|
return symbol("EOF")
|
|
|
|
|
}
|
|
|
|
|
byteBuf = append(byteBuf, b[0])
|
|
|
|
|
if utf8.FullRune(byteBuf) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%c", char)
|
|
|
|
|
return string(byteBuf)
|
|
|
|
|
default:
|
|
|
|
|
return exception("'read-char' has not been implemented for this object type")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
"read-line": func(a ...expression) expression {
|
|
|
|
|
if len(a) == 0 {
|
|
|
|
|