aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/sloth_std/term.rs
blob: 41e6708afb1a9f50198b145acb8825934f9976f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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: None,
};

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: None,
};