Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sogaiu/janet-termsize
https://github.com/sogaiu/janet-termsize
janet terminal
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sogaiu/janet-termsize
- Owner: sogaiu
- Created: 2023-07-29T16:00:55.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-08T13:09:19.000Z (4 months ago)
- Last Synced: 2024-09-08T14:32:38.001Z (4 months ago)
- Topics: janet, terminal
- Language: Janet
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# janet-termsize
A Janet implementation of determining a terminal's size (rows and
columns). No C compilation necessary.## Usage
```janet
(import termsize :as ts)(ts/rows-and-cols)
# =>
[24 80](ts/rows)
# =>
24(ts/cols)
# =>
80
```## Notes
Possibly of interest:
* The `:web` "operating system" (emscripten) isn't supported, but
various attempts have been made to try to support others including:* `:bsd` - BSD that isn't the other specific ones?
* `:cygwin`
* `:dragonfly`
* `:freebsd`
* `:linux` - includes Termux on Android
* `:macos`
* `:mingw`
* `:netbsd`
* `:posix` - some UNIXy machine not more specifically recognized?
* `:windows`Not all have been tested though. Please report if something isn't
working :)* Tries to use FFI where practical (ATM, only x86_64 + some operating
systems)* Falls back to external process methods (`stty` for Unixy systems and
powershell for Windows)* The function `rows-and-cols` hands things off to various helper
functions such as `via-ioctl`, `via-winapi`, or `via-shell`. These
are exposed but no particular effort may be made to keep them the
same (or around) over time [1].* When implementing FFI-related bits for Windows, it was helpful to
examine [this
page](https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types)
to figure out what things like `DWORD`, `HANDLE`, etc. are under the
covers. Once the underlying types were understood, [this
table](https://janet-lang.org/docs/ffi.html#Primitive-Types) was
used to determine a target keyword. As an example, consider
`DWORD`. According to the page at MS, it is:> A 32-bit unsigned integer. The range is 0 through 4294967295
> decimal.So taking that to mean `uint32_t`, according to the "primitive
types" table, that could be either `:uint32` or `:u32` (both
probably work).---
[1] The author doesn't find making things private to be worth all of
the extra work that often seems to lead to (e.g. testing and
investigation typically become more cumbersome).