package charInfo_width

  1. Overview
  2. Docs
Determine column width of a character

Install

Dune Dependency

Authors

Maintainers

Sources

charInfo_width-0.1.0.tar.gz
md5=b1856eb22cafcaf564d2d11be5d522c0

Description

This module is implemented purely in OCaml and the width function follows the prototype of POSIX's wcwidth.

Published: 16 Nov 2018

README

CharInfo_width

Determine column width of a character.

Description

CharInfo_width.width c returns the column width of c where c is of type Camomile.UChar.t and the value returned is of type int.

This module is implemented purely in OCaml and the width function follows the prototype of POSIX's wcwidth. i.e. If c is a printable character, the value is at least 0. If c is null character (L'\0'), the value is 0. Otherwise, -1 is returned. The width_exn function, when encounter an unprintable character, it raises Failure "unprintable character" instead of returning -1.

By default, the width and width_exn function is compatible with ncursesw, ncursesw based CLIs, terminals. The way they consider the width of a character is the same.

An optional parameter, cfg, can extend extra width info. The current width info table of ncursesw, xterm, xterm-compatible terminal is inadequate and limited, so is the default cfg of this module. When implement raw mode command-line interface, e.g. readline, a text editor, better extend extra width info by cfg. An on going sample repository of width table is here: charInfo_width_extra

This module also provides a function, CharInfo_width.width_utext to calculate the width of a unicode string. The returned value is either Ok width or Error pos-of-unprintable-character.

Dependencies (4)

  1. dune >= "1.4"
  2. camomile >= "1.0.0" & < "2.0~"
  3. result
  4. ocaml >= "4.02.3"

Dev Dependencies (1)

  1. ppx_expect with-test

Used by

None

Conflicts

None