Skip to content

TermCL 0.8

Latest

Choose a tag to compare

@RaphGL RaphGL released this 05 Oct 18:52
· 1 commit to main since this release

Breaking changes

Redefining Inputs

Manually parsing keyboard and mouse input is annoying, it also makes adding custom backends harder due to it being tied to how terminals process the inputs rather than just the inputs being given. So I've changed the signature for both read and read_blocking. They still return an Input but it's been redefined to:

Input :: union {
    Keyboard_Input,
    Mouse_Input,
}

This makes it easier to use but it also makes it easier to extend to other backends as well.

If for some reason you still need to access the raw bytes returned from the terminal, use the raw variants: read_raw and read_raw_blocking acessible through the termcl/term package. This package also contains the parse_mouse_input and parse_keyboard_input functions so that you can still convert raw input into Input.

Custom backends

As was hinted before, the addition of cell buffers allowed for the potential use of custom backends to render to other targets, such as other escape code standards or GUIs. For now I'm adding an SDL3 backend so that TUIs can be ported to GUIs. There's still some ironing out to do so there might be some different behavior between the terminal and the backend, but as long as you test your code on both TUI and GUI, it shouldn't be too big of a problem.

How it works

The library uses a VTable with implementations for backend specific stuff. This VTable looks like this:

Backend_VTable :: struct {
	init_screen:    proc(allocator: runtime.Allocator) -> Screen,
	destroy_screen: proc(screen: ^Screen),
	get_term_size:  proc() -> Window_Size,
	set_term_mode:  proc(screen: ^Screen, mode: Term_Mode),
	blit:           proc(win: ^Window),
	read:           proc(screen: ^Screen) -> Input,
	read_blocking:  proc(screen: ^Screen) -> Input,
}

You set it by calling the set_backend function:

set_backend :: proc(backend: Backend_VTable) {

Or by just passing the backend's vtable when calling init_screen.

All you have to do is import the backend you want to use and call it's own set_backend function. For current users, the only modification they need to do is to import termcl/term and call term.set_backend() and everything should keep working as it was before.

For people attempting to use the SDL3 backend, if you're were previously doing "frame capping" by using a timer, be aware that that will screw up the event handling on SDL3, so you should do everything besides the rendering on another thread if that is the case (like you would normally do for any SDL3 program). Other than that, most programs can easily be rendered as a GUI by just swapping the backend.

Additions

  • Added SDL3 backend

Fixes

  • Removed generics to rely on subtyping instead so that the binary size of the library is smaller
  • Fixed enable_alt_buffer dispatching wrong escape code for disabling the alternate buffer