package console

import "core:fmt"

ESC :: "\x1b"
CSI :: ESC + "["

CLEAR :: CSI + "2J"

CURSOR_HIDE :: CSI + "?25l"
CURSOR_SHOW :: CSI + "?25h"

CURSOR_POSITION :: CSI + "%d;%dH"
FORMAT :: CSI + "%d;%dm"
RESET_FORMAT :: CSI + "0m"

BOLD :: 1
ITALIC :: 2
UNDERLINE :: 4
STRIKETHROUGH :: 9
BRIGHT_BLACK :: 90

LINE_DRAWING_MODE :: ESC + "(0"
ASCII_DRAWING_MODE :: ESC + "(B"

Keys :: enum {
	none,
	unk,
	quit,
	back,
	forward,
}

Console :: struct {
	using _: _Console,
	width:   int,
	height:  int,
}

create :: proc() -> Console {
	return _create()
}

destroy :: proc(con: ^Console) {
	_destroy(con)
}

should_quit :: proc() -> bool {
	return _should_quit()
}

clear :: proc(con: Console) {
	_clear(con)
}

write :: proc(con: Console, msg: string) {
	_write(con, msg)
}

write_at :: proc(con: Console, msg: string, x, y: int) {
	_write_at(con, msg, x + 1, y + 1)
}

putch :: proc(con: Console, c: rune, x, y: int) {
	_putch(con, c, x + 1, y + 1)
}

putch_s :: proc(con: Console, c: rune, x, y: int) -> string {
	return fmt.tprintf(CURSOR_POSITION + "%c", y + 1, x + 1, c)
}

wait_for_input :: proc(con: Console) -> Keys {
	return _wait_for_input(con)
}

get_size :: proc(con: Console) -> (int, int) {
	return _get_size(con)
}