Skip to content

RaphGL/TermCL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


TermCL

Terminal control and ANSI escape code library for Odin




· Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. How it works
  3. Usage

TermCL is an Odin library for writing TUIs and CLIs with. The library is compatible with any ANSI escape code compatible terminal, which is to say, almost every single modern terminal worth using :)

The library should also work on windows and any posix compatible operating system.

How it works

The library uses a Screen struct to represent the terminal. To start a CLI/TUI you need to call init_screen, this function calls the operating system to get information on the terminal state.

Note

you should call destroy_screen before you exit to restore the terminal state otherwise you might end up with a weird behaving terminal

After that you should just set the terminal to whatever mode you want with the set_term_mode function, there are 3 modes you can use:

  • Raw mode (.Raw) - prevents the terminal from processing the user input so that you can handle them yourself
  • Cooked mode (.Cbreak) - prevents user input but unlike raw, it still processed for signals like Ctrl + C and others
  • Restored mode (.Restored) - restores the terminal to the state it was in before the program started messing with it, this is also called when the screen is destroyed

After doing this, you should be good to go to do whatever you want.

Here's a few minor things to take into consideration:

  • To handle input you can use the read function or the read_blocking function, as the default read is nonblocking.
  • There's convenience functions that allow you to more easily process input, they're called parse_keyboard_input and parse_mouse_input
  • Whatever you do won't show up on screen until you blit, since everything is cached first, windows also have their own cached escapes, so make sure you blit them as well

Usage

package main

import "termcl"

main :: proc() {
    scr := termcl.init_screen()
    defer termcl.destroy_screen(&scr)

    termcl.set_text_style(&scr, {.Bold, .Italic})
    termcl.write(&scr, "Hello ")
    termcl.reset_styles(&scr)

    termcl.set_text_style(&scr, {.Dim})
    termcl.set_color_style_8(&scr, .Green, nil)
    termcl.write(&scr, "from ANSI escapes")
    termcl.reset_styles(&scr)

    termcl.move_cursor(&scr, 10, 10)
    termcl.write(&scr, "Alles Ordnung")

    termcl.blit(&scr)
}

Check the examples directory to see more on how to use it.

About

Terminal Control Library for Odin

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages