Giter Club home page Giter Club logo

tty's People

Contributors

leostera avatar metame avatar neshtea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

neshtea metame rchog

tty's Issues

Finish profile detection for non-TrueColor terminals

As it stands now, there's a few flags that are always false in profile.ml

  (* TODO(@leostera): String.contains "256color" "color" "ansi" *)
  let is_256color = false in
  let is_color = false in
  let is_ansi = false in

The checks for these are essentially String.contains checks, and need to be done based on the env variables available.

Terminal dimensions

I've been trying to figure out a way to get the dimensions of the current terminal in a sensible (somewhat) cross-platform way. I thought it'd be a fairly easy thing to do and I could try submitting a PR once I have something working, but it's proving to be beyond my skill/knowledge level with OCaml and terminals in general.

However, it seems like a very common thing that people would expect to see in a library like this, so I figured it could merit some discussion at the very least?

AFAIK there's a bunch of ways it could be done, but they all have downsides:

  • CSI DSR (\x1b[6n) should cause a status message ESC[n;mR to be 'printed' to STDIN. I got this kind of working1, but this only seems to work for certain terminals. Foot, Alacritty, URXVT and the linux console worked for me while Kitty, Wezterm, xfce-terminal and, surprisingly, xterm didnt.
  • ioctl() through Ctypes works, kind of2, but I could not figure out a way to access libc constants in OCaml, so I had to hardcode the value of TIOCGWINSZ, so it's the furthest thing from cross platform.
  • A separate mini-library that just exposes a couple functions to get the terminal size. Probably the most cross-platform and easiest method, but I didn't try it because submitting a PR with a bunch of C seemed like it might not be welcome. If I'd gone with this method, I'd be tempted to do some of the terminal setup/cleanup through C as well, just because IIRC dealing with things like SIGWINCH, SIGINT etc. in OCaml is much harder(?)
  • tputs and/or stty - shelling out to these seems like an easy 'cheat' but I doubt these are available on all platforms.

Footnotes

  1. with this hacky monstrosity. I had Base and Stdio opened in these experiments, in case some functions look odd.

  2. https://gist.github.com/rchog/ac9303c0d6b4d0deb74b006534749722

Should be able to use /dev/tty instead of stdin

I think the Stdin module should read from /dev/tty instead of stdin (or else the user should be able to choose). Otherwise writing interactive programs that read input from stdin (e.g. fzf in cat ... | fzf) will have problems.

Specifically, when I tried doing that with minttea, I got an ENOTTY error message (although the program still seemed to function as expected). Changing the stdin module to start with let stdin_fd = Unix.descr_of_in_channel (In_channel.open_bin "/dev/tty") got rid of it.

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.