aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/sloth_std/term.rs
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-05-24 00:23:13 -0500
committerCody <cody@codyq.dev>2023-05-24 00:23:13 -0500
commit9c41dd96cd3652ce9c46307184e8055704655338 (patch)
tree07071d74da7398593fc5b9cfe5c4df0229ee4eb0 /crates/sloth_vm/src/sloth_std/term.rs
parent2418d68631f6e338251f2d988de2d3fde206982b (diff)
parentdf00e9ff2c2b563c79beb71ba8c510233b04f3bf (diff)
downloadsloth-9c41dd96cd3652ce9c46307184e8055704655338.tar.gz
Merge branch 'master' into compiler
Diffstat (limited to 'crates/sloth_vm/src/sloth_std/term.rs')
-rw-r--r--crates/sloth_vm/src/sloth_std/term.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/sloth_vm/src/sloth_std/term.rs b/crates/sloth_vm/src/sloth_std/term.rs
new file mode 100644
index 0000000..f61321c
--- /dev/null
+++ b/crates/sloth_vm/src/sloth_std/term.rs
@@ -0,0 +1,41 @@
+use crate::native::{self, NativeFunction, NativeFunctionResult};
+use crate::value::Primitive;
+use crate::value::Primitive::Integer;
+use crate::VM;
+
+pub const TERM_CLEAR: NativeFunction = NativeFunction {
+ name: "term$clear",
+ function: |_vm, _args| {
+ print!("\x1b[2J\x1b[H");
+ Ok(Primitive::Empty)
+ },
+ arity: 0,
+ returns_value: false,
+ doc: Some(
+ "NativeFunction term$clear: \n\tdesc: Clears the terminal\n\tExample: `term$clear(); # \
+ Clears the terminal`",
+ ),
+};
+
+fn term_setpos(_vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
+ let x = args.get(0).cloned();
+ let y = args.get(1).cloned();
+
+ let (Some(Integer(x)), Some(Integer(y))) = (x, y) else {
+ return Err(native::Error::InvalidArgument);
+ };
+ print!("\x1b[{x};{y}H");
+ Ok(Primitive::Empty)
+}
+
+pub const TERM_SETPOS: NativeFunction = NativeFunction {
+ name: "term$setpos",
+ function: term_setpos,
+ arity: 2,
+ returns_value: false,
+ doc: Some(
+ "NativeFunction term$setpos: \n\targs: x (int), y (int)\n\tdesc: Sets the cursors \
+ position to (<x>, <y>)\n\tExample: `term$setpos(5, 17); # Sets the position of the \
+ cursor to (5, 17)`",
+ ),
+};