Coder Social home page Coder Social logo

charinfo_width's Introduction

CharInfo_width

Determine column width for a character.

How to use

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 functor, CharInfo_width.String. This functor accepts a Camomile.UnicodeString compatible module to calculate the width of a unicode string. The returned value is either Ok width or Error pos-of-unprintable-character.

Document

The document is available here.

charinfo_width's People

Contributors

dmbaturin avatar kandu avatar

Watchers

 avatar  avatar

Forkers

dmbaturin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.