Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vsnthdev/read-file-input
Opens a ๐ text editor, waits until closed & captures ๐ฌ file content.
https://github.com/vsnthdev/read-file-input
cli command-line editor input prompt prompts readline stdin terminal
Last synced: about 20 hours ago
JSON representation
Opens a ๐ text editor, waits until closed & captures ๐ฌ file content.
- Host: GitHub
- URL: https://github.com/vsnthdev/read-file-input
- Owner: vsnthdev
- License: mit
- Created: 2021-12-03T19:20:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-03T14:25:15.000Z (9 months ago)
- Last Synced: 2024-03-03T15:31:46.656Z (9 months ago)
- Topics: cli, command-line, editor, input, prompt, prompts, readline, stdin, terminal
- Language: TypeScript
- Homepage:
- Size: 183 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
read-file-input
Opens a ๐ text editor, waits until closed & captures ๐ฌ file content.
Allows you to capture user input by opening a text editor instead of `stdin`. Manually passing large amounts of data through `stdin` is cumbersome and not widely supported as it depends on the terminal emulator.
This module creates a temporary file and opens it with the configured text editor. When the user saves the file and quits the editor, we read back the file while optionally deleting it.
Since most text editors support UTF-8, any emojis and special characters will be handled safely instead of replying on the terminal.
> Tweet @vsnthdev, I would love to know your opinion & experience on this project ๐
## โจ Features
1. Cross platform
2. Supports graphical & terminal editors
3. Prefills the file with content## ๐ฟ Installation
## ๐ Quick Start
After `read-file-input` as a dependency using the above command, you can use it in the following way:
```javascript
// import readFileInput from 'read-file-input'
import readFi from '../dist/read-file-input.js'// read from the user with zero configuration
const read = await readFi()// print the input we have read
console.log('Read input as:')
console.log(read)```
## ๐งช Configuration
```typescript
export interface ConfigImpl {
// the name of the file created, defaults to "[id].txt"
// where [id] is replaced with a random 5 character string
// to prevent conflicts
name?: string// a custom editor command which defaults to notepad.exe on Windows
// and uses the $VISUAL & $EDITOR environment variables on Linux & macOS
editor?: string// whether to delete the file after the input has been read
// defaults to true and recommended to keep it that way
cleanup?: boolean// do not wait for the editor to be closed, just return
// as soon as the editor has opened, useful to just show
// some content rather than taking inputs
noWait?: boolean// the content that the temporary file should be pre-filled with
// undefined by default
content?: {
// the string of data which will be pre-filled onto the
// temporary file, will override the file setting
data?: string// path to a file from which the content will be read
// for generating the temporary file
// useful for passing large amount of data for the temporary file
file?: string
}
}```
## ๐ป Building & Dev Setup
You need to be at least on **Node.js v17 or above** and follow the below instructions to build the project ๐
- **STEP 1๏ธโฃ** Clone this project
- **STEP 2๏ธโฃ** Run **`npm install`** to get all dependencies
- **STEP 3๏ธโฃ** To build the TypeScript project run **`npm run build`**Now you should have a `dist` folder in the project directory.
### โก Running Examples
Once you have successfully built the project, to run a basic example ๐
```
node examples/basic.js
```Checkout [other examples](https://github.com/vsnthdev/read-file-input/tree/main/examples) to know more on different use cases and configuration of options of **read-file-input**.
### ๐ ๏ธ Writing Code
This project follows [Vasanth's Commit Style](https://vas.cx/commits) for commit messages.
## ๐ฐ License
> The **read-file-input** project is released under the [MIT license](https://github.com/vsnthdev/read-file-input/blob/main/LICENSE.md).
Developed & maintained By Vasanth Srivatsa. Copyright 2023 ยฉ Vasanth Developer.
> vsnth.dev ย ยทย
> YouTube @vasanthdeveloper ย ยทย
> Twitter @vsnthdev ย ยทย
> Discord Vasanth Developer