Skip to content

Just a minimal library to do some terminal stuff.

Notifications You must be signed in to change notification settings

biraj21/termctl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Termctl

A simple library to do some basic terminal stuff.

Screenshot

Usage

const termctl = require("termctl");

Note: We have tested this on Linux Mint and Windows 10 but we don't know if changing colors will work on Mac.

Methods

Input/Output

  • You need to call init() method once before using gets() because termctl uses Node.js's readline module, so init() will be used to create an instance of readline.Interface.

    termctl.init();
  • gets() is used to take user input from the terminal (stdin). First argument is the prompt message to be displayed. Second argument specifies whether to print what user is typing (echo). It's default value is true.

    // termctl.gets(query?: string, echo?: boolean) => Promise<any>
    
    const uname = await termctl.gets("Enter your name: ");
    const pswd = await termctl.gets("Enter password: ", false);
  • Call close() to close the readline.Interface instance.

    termctl.close();

Styling

  • Set background color

    // termctl.color.set_bg(r: number, g: number, b: number): void
    
    termctl.color.set_bg(255, 255, 100);
    
    // (or) css style hex colors
    termctl.color.set_bg(0xFFFF64); // 0xRRGGBB format
  • Reset background color to default

    // termctl.color.reset_bg(): void
    
    termctl.color.reset_bg();
  • Set foreground color

    // termctl.color.set_bg(r: number, g: number, b: number): void
    
    termctl.color.set_fg(0, 0, 0);
    
    // (or) css style hex colors
    termctl.color.set_fg(0x000000); // 0xRRGGBB format
  • Reset foreground color to default

    // termctl.color.reset_bg(): void
    
    termctl.color.reset_fg();
  • Bold

    // termctl.set_bold(bold?: boolean): void
    
    termctl.color.set_bold();
  • Italic

    // termctl.set_italic(italic?: boolean): void
    
    termctl.color.set_italic();
  • Underline

    // termctl.set_underline(underline?: boolean): void
    
    termctl.color.set_underline();
  • Resets all styles to default

    // termctl.color.reset_styles(): void
    
    termctl.color.reset_styles();

Note: We are just using escape sequences inside these methods for changing styles. So resetting styles before exiting is always a good idea.

About

Just a minimal library to do some terminal stuff.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published