Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Terminal handling library.


Writing a text editor that I acutally like is something that's been on my
queue of things to write for ages. When I saw Kilo, I started poking through
it for inspiration. The editor itself is a toy, but the terminal handling
convinced me that it wouldn't be hard to bang out something quickly. More
quickly than my X11/XCB experiemnts (although they're also getting there...)

So, here it is:

	http://git.eigenstate.org/ori/libtermios.git

And mirrored:

	https://github.com/oridb/libtermios

The API is fairly simple, and somewhat resembles the termbox api (although
I didn't realize this until after I put the library together). Here it is:

	
	pkg termios = 
		type color
		type event = union
			`Winsz (int, int)
			`Gone	/* lost the terminal fd */
			`Kesc
			`Kup
			`Kdown
			`Kleft
			`Kright
			`Khome
			`Kend
			`Kdel
			`Kpgup
			`Kpgdn
			`Kc char
		;;

		const Black	: color
		const Red  	: color
		const Green	: color
		const Yellow	: color
		const Blue 	: color
		const Magenta	: color
		const Cyan 	: color
		const White	: color
		const Default	: color

		const Normal	: attr
		const Bold	: attr
		const Italic	: attr
		const Underline	: attr
		const Blink	: attr	/* eww, blink tags */

		const mk	: (fd : std.fd -> term#)
		const free	: (t : term# -> void)
		const raw	: (t : term# -> void)

		const size	: (t : term# -> (int, int))
		const move	: (t : term#, r : int, c : int -> void)

		const cls	: (t : term# -> void)
		const flush	: (t : term# -> void)
		const putc	: (t : term#, c : char -> void)
		const put	: (t : term#, fmt : byte[:], args : ... -> void)
		const setfg	: (t : term#, c : color -> void)
		const setbg	: (t : term#, c : color -> void)
		const setattr	: (t : term#, c : attr -> void)

		const event : (t : term# -> event)
	;;

It also provides raw access to the termios api, although this is slightly
system specific:


	const tcgetattr	: (fd : std.fd, t : termios# -> sys.errno)
	const tcsetattr	: (fd : std.fd, opt : tioopt, t : termios# -> sys.errno)
	const tcwinsize	: (fd : std.fd, winsz : winsize# -> sys.errno)


Currently it's pretty rudimentary. It restricts itself to a common ANSI escape
code subset that it seems all terminals I have tested respect.

TODO:
	- Event peeking
	- Better color support
	- Reading termcap/terminfo and respecting that
	- Bugfixes?

-- 
    Ori Bernstein

Follow-Ups:
Re: Terminal handling library.Ori Bernstein <ori@xxxxxxxxxxxxxx>