diff options
| author | nic-gaffney <gaffney_nic@protonmail.com> | 2023-04-14 03:20:23 -0500 |
|---|---|---|
| committer | nic-gaffney <gaffney_nic@protonmail.com> | 2023-04-14 03:20:23 -0500 |
| commit | f6e14f4b2b15b0ace8ed312252ae107f139bd33d (patch) | |
| tree | 34d844e1c4f1be2c95ef87e6363a76b3502bb40f /crates/sloth_vm/src/sloth_std/term.rs | |
| parent | 97b7cd10d2bec408cc237e13c61562c810d8fd29 (diff) | |
| download | sloth-f6e14f4b2b15b0ace8ed312252ae107f139bd33d.tar.gz | |
Terminal and file stuff
Diffstat (limited to 'crates/sloth_vm/src/sloth_std/term.rs')
| -rw-r--r-- | crates/sloth_vm/src/sloth_std/term.rs | 32 |
1 files changed, 32 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..cffa1e8 --- /dev/null +++ b/crates/sloth_vm/src/sloth_std/term.rs @@ -0,0 +1,32 @@ +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, +}; + +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, +}; |
