GithubHelp home page GithubHelp logo

elius94 / console-gui-tools Goto Github PK

View Code? Open in Web Editor NEW
88.0 4.0 14.0 1008 KB

A simple library to draw option menu or other popup inputs and layout on Node.js console.

License: MIT License

JavaScript 2.81% TypeScript 97.19%
console logs node node-js gui consoleapp ncurses terminal terminal-colors terminal-graphics

console-gui-tools's Introduction

Hi there I'm Elia ๐Ÿ‘‹

  • ๐Ÿ”ญ Currently working on JS, Node, React, Rust and C++
  • ๐Ÿ“ท Landscapes Photographer -> www.eliusoutdoor.com
  • ๐Ÿ”๏ธ Love Mountaineering and adventures
  • ๐Ÿชด Based in Bologna, IT
  • ๐ŸŽธ Guitar player, Music lover

My web spaces

Nerd Stats

Elius94 trophy

console-gui-tools's People

Contributors

compositr avatar dependabot[bot] avatar elius94 avatar ellisgl avatar fabianescarate avatar h-sifat 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

console-gui-tools's Issues

New widget: Filemanager

It could start from the option popup and spawn a child-process to ls the selected folder and return the selected file name and path.

[Feature]: addColumn (instead of double or quad)

What do you want?

Allow columns, too. Like used in Bootstrap's Grid-system (Columns, rows) to give the dev better options on how to setup a given layout. I'd also like to control, if the "Logs" should be be rendered in a specific column or row.

Why do you want it?

It would enable the dev to generate GUI-elements, instead of having to force the design in a "double" or "quad" layout.

How do you implement it?

Two rows, each with two columns:
billede
Yes, that's actually a QuadLayout, but done manually.

I'd also like it to support two "horizontal views", where the first one contains two rows, and no. 2 is a single big one:
billede

Another solution would be to just support a "triple` layout, maybe two (one for 100% left colum height, and one for 100 right column height - like the example).

Also, just to add it:
Personally I had a hard find spotting the "quad" option. Maybe I just missed the example, but after i noticed [https://github.com/Elius94/console-gui-tools/blob/main/docs/QuadLayout.md) in the docs, I though.... The quad-option must be part of the "type" on ConsoleGuiOptions, and luckily it was.

I understand that the addColumn doesnt really fit into the current solution, if I understand the code-base correctly, so the other alternative with two new Layouts would be a good alternative. Maybe even just one, and a "mirror" function (but that's not that logical, for most users).
Yet another take would be to just allow one to be stretched to 100% height, and tell the user to set the proper pageRatio (Like [[0.3, 0.7],[0.3, 0.7]] , where page 2 (1) is defined with 100% height). But right now, I even struggle to find the function to render a 100% height ConsoleManager.

I'm new to the console-gui-tools, but I've looked at terminal-kit (node), and solutions like urwid (python) and bash solutions like whiptail / dialog and a few others. But console-gui-tools looks very great! In urwid I find myself using way too much time creating simple GUI changes, instead of the functions behind it.

Are you interested in developing this feature?

  • Yes, I am interested in developing this feature
  • No, I am not interested in developing this feature

Code structure: make it better

It's necessary to add Tests with Mocha/chai and coverage checks.
Also we need to add more examples and a folder containing only components.

[Bug]: LayoutOptions.changeFocusKey marked as required

What happened?

The interface definition has the changeFocusKey property marked as required, so types show to be wrong in IDE.

What should have happened?

No type errors should appear in in IDE.

Code

const opt: ConsoleGuiOptions = {
    title: "Progress Bar Test",
    layoutOptions: {
        type: "single"
    },
    logLocation: "popup",
    enableMouse: true
};

Library Version

3.2.0

Node Version

20.7.0

What operating system are you using?

Ubuntu

Terminal

konsole

Interest to fix the bug

  • I would like to fix this bug!

[Feature]: Change all class constructors parameters with one single object with optional props

What do you want?

Convert all class constructors with a single parameter: An object with a type (Interface) defined, in order to better handle optional parameters, and to simplify coding.

Why do you want it?

To conform with current coding style standards and to facilitate the declaration of new classes.

@h-sifat mentioned this possibility in #54

// with a single object parameter
new Progress({
	x: 3,
	y: 23,
	length: 20,
	id: "prog1",
	thickness: 1,
	style: pStyle,
	theme: "htop",
	orientation: "horizontal",
});

// with multiple parameters
new Progress("prog1", 20, 1, 3, 23, pStyle, "htop", "horizontal")

How do you implement it?

To implement it you need to

  • Take some time to create the Typescript interfaces of each constructor
  • Update all constructors and all class instances already called internally
  • Test that EVERYTHING works exactly as before
  • Document the newly created types
  • Run npm run docs to update the code documentation
  • Update the README.md and explain how to migrate to the new version.

All of this will go into forming the new Major Release (v3), as it compromises backwards compatibility because of the syntax change.

Are you interested in developing this feature?

  • Yes, I am interested in developing this feature
  • No, I am not interested in developing this feature

[Bug]: InputPopup can handle strings

What happened?

Trying to use the InputPopup to get a string returns NaN.
Entering a number logs the correct output. I have tried converting that str variable to string but is looks like the function only returns numbers.

What should have happened?

A string as an output

Code

let input = new InputPopup({
id: "popupTypeStr",
title: "Pega el enlace",
value: "",
numeric:false,
})
.show()
.on("confirm",(str) => {
GUI.warn(str)
});

Library Version

3.2.2

Node Version

20.8.0

What operating system are you using?

Ubuntu

Terminal

gnome-terminal

Interest to fix the bug

  • I would like to fix this bug!

[Bug]: Error using Libary in ESM Project (TS 7016)

What happened?

cant use types in an ESM Project ("types": "esnext") with

ts 4.9.x

Error

Could not find a declaration file for module 'console-gui-tools'. 'c:/remoterep/rtptools/node_modules/console-gui-tools/dist/esm/ConsoleGui.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/console-gui-tools` if it exists or add a new declaration (.d.ts) file containing `declare module 'console-gui-tools';`ts(7016)

ts 5.3.x

Could not find a declaration file for module 'console-gui-tools'. 'c:/remoterep/rtptools/node_modules/console-gui-tools/dist/esm/ConsoleGui.mjs' implicitly has an 'any' type.
  There are types at 'c:/remoterep/rtptools/node_modules/console-gui-tools/dist/types/ConsoleGui.d.ts', but this result could not be resolved when respecting package.json "exports". The 'console-gui-tools' library may need to update its package.json or typings.ts(7016)

What should have happened?

Using Types in VSCode (current all is "any")

Code

import { ConsoleManager } from 'console-gui-tools'

(but no types available)

Library Version

3.4.0

Node Version

18.16.1

What operating system are you using?

Windows

Terminal

gitbash

Interest to fix the bug

  • I would like to fix this bug!

New type of widgets: In page widget

The goal is to make a new kind of widgets. A widget that is printed inside a PageBuilder class, it will use fiew characters or multiple lines but it will embedded inside the rows of the page.
To use the page widgets the user must select one of them (maybe with tab) and use the keyboard, so it's neccessary to add a sort of tabindex on PageBuilder class.
The following list represent some of the possible page widget to do:

  • Checkbox / Checkbox Group
  • Radio / Radio Group
  • Scrollbar
  • Ascii Charts
  • Table / Grid
  • Button

Extends color patterns from chalk

Currently we can set colors using chalk. If we need to set a color or style on the home page we still have to use it.
I wish to add color syntax to the homepage string like html tags or other escaped strings that will be changed to chalk function in the library.

[Feature]: Popups Offset

What do you want?

I want to offset the popups

Why do you want it?

I think it'll be more convenient to have the pop ups offset feature

How do you implement it?

IDK...

P/s: Sorry alot for my lack of knowledge and bad English

Are you interested in developing this feature?

  • Yes, I am interested in developing this feature
  • No, I am not interested in developing this feature

Add keyboard key to push button

Add "key" parameter to button to push it with keyboard key
example:

const button = new Button("btnClickMe", "Click Me!", 11, 3, 10, 10, style1)
button.setKey("x", ctrl=true, alt=false, shift=false)

[Bug]: Input popup doesn't handle special characters properly

What happened?

When I tried to type an & sign, it just inputted "undefined"
image

I typed the following: test&123

Uppercase does not work either (shift key doesn't work)

What should have happened?

I would expect the popup input to handle special characters (e.g. "&") properly

Code

  const input = await new Promise<string>((resolve, reject) => {
    new InputPopup({
      id: "popupInput",
      title: "Input",
      numeric: false,
      value: "",
    })
      .show()
      .on("confirm", (out) => {
        resolve(out);
        GUI.refresh();
      })
      .on("cancel", () => {
        reject();
      });
  }).catch(() => {
    // kill
    process.exit(1);
  });

Library Version

3.0.3

Node Version

18.12.1

What operating system are you using?

Other Linux

Terminal

KDE Konsole on Arch

Interest to fix the bug

  • I would like to fix this bug!

Improving performance on refresh

High Refresh rate, on big screen make the screen flashing very noisely. try to render tty only once and before only return a screen variable.

Animation

[Feature]: Added Support so the Process needs not be ended with process.exit()

What do you want?

currently the process.exit() is needed for node to end correctly, cause the StdIn Interface is not correctly closed.

Why do you want it?

Implement the GUI correctly even during close.

How do you implement it?

The changes needed can be seen here. I'm not sure if all components are working, but a small implementation does not need the on("exit") process.exit() structure anymore

main...haeferer:console-gui-tools:main

Now this code works

GUI.on("exit", () => {
    console.clear();
})

you can even remove these lines, if you dont want to clear the console on exit

Are you interested in developing this feature?

  • Yes, I am interested in developing this feature
  • No, I am not interested in developing this feature

[Bug]: Button click does not work

What happened?

Code runs but when I click the button it does not execute the wanted code.

What should have happened?

Should register the click

Code

const { InPageWidgetBuilder, Control } = require('console-gui-tools')

const widget1 = new InPageWidgetBuilder()
widget1.addRow({ text: "โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”", color: "yellow", style: "bold" })
widget1.addRow({ text: "โ”‚ START! โ”‚", color: "yellow", style: "bold" })
widget1.addRow({ text: "โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜", color: "yellow", style: "bold" })

const button1 = new Control({
  id: "btn1",
  visible: false,
  attributes: { x: 30, y: 18, width: 10, height: 3 },
  children: widget1
})
button1.on("relativeMouse", (event) => {
   if (event.name === "MOUSE_LEFT_BUTTON_RELEASED") {
        require('fs').writeFileSync('button.txt', 'Button clicked!')
   }
})```

### Library Version

3.3.0

### Node Version

18.5.0

### What operating system are you using?

Windows

### Terminal

Tried CMD & windows terminal. I also tried on my macbook and got the same results.

### Interest to fix the bug

- [ ] I would like to fix this bug!

[Bug]: OptionPopup - selected prop = "" is considered undefined

What happened?

If you define a OptionPopup with selected: "", it throw a error considering selected undefined.

What should have happened?

It should allow to set it to empty string

Code

new OptionPopup({
  id: "testBox",
  title: "title",
  options: opts,
  selected: ""
})

Library Version

3.0.4

Node Version

19.3

What operating system are you using?

Windows

Terminal

Windows Terminal

Interest to fix the bug

  • I would like to fix this bug!

Customizable layout: Tabview and more than two layouts

Currently the lib allows to use only Homepage (top of the screen) and Logs View (bottom of the screen).
It's interesting to give to the user the possibility of adding more than one pages and maybe with a custom layout.

Another thing is to make the layout acts like a tabview, so with a keybord key or combination make it changing the selected tab.

[Support]: InputPopup string limit

What are you trying to do?

I want the code to accept strings that are above 20 characters.

Code

The example from InputPopup: "
import { ConsoleManager,ConfirmPopup, Box, InPageWidgetBuilder, InputPopup } from "console-gui-tools"

const opt = {
title: "Input Popup Test",
layoutOptions: {
type: "single"
},
logLocation: "popup",
enableMouse: true
}

const GUI = new ConsoleManager(opt)

GUI.on("exit", () => {
closeApp()
})

let nValue = 0
let sValue = ""

GUI.on("keypressed", (key) => {
switch (key.name) {
case "q":
new ConfirmPopup({
id: "popupQuit", title: "Are you sure you want to quit?"
}).show().on("confirm", () => closeApp())
break
case "n":
new InputPopup({
id: "popupInput",
title: "Enter a number:",
value: nValue,
numeric: true
}).show().on("confirm", (value) => {
console.log(You entered: ${value})
nValue = value
refresh()
})
break
case "s":
new InputPopup({
id: "popupInput",
title: "Enter a string:",
value: sValue,
numeric: false
}).show().on("confirm", (value) => {
console.log(You entered: ${value.lenght})
sValue = value
refresh()
})
break
default:
break
}
})

const closeApp = () => {
console.clear()
process.exit()
}

const b = new Box({
id: "box",
x: 2,
y: 3,
width: 45,
height: 4,
style: {
boxed: true,
}
})

const content = new InPageWidgetBuilder()

content.addRow({
text: "Press 'n' to open a Numeric Input Popup",
color: "rgb(255,0,0)",
bg: "rgb(0,0,255)",
})

content.addRow({
text: "Press 's' to open a String Input Popup",
color: "blue",
})

b.setContent(content)

const b1 = new Box({
id: "box1",
x: 2,
y: 7,
width: 45,
height: 4,
style: {
boxed: true,
}
})

const refresh = () => {
const content1 = new InPageWidgetBuilder()
content1.clear()
content1.addRow({
text: Numeric value: ${nValue},
color: "rgb(255,0,0)",
bg: "rgb(0,0,255)",
})
content1.addRow({
text: String value: ${sValue},
color: "blue",
})
b1.setContent(content1)
GUI.refresh()
}"

Library Version

3.3.0

Node Version

20.5.1

What operating system are you using?

Other Linux

Terminal

xterm

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.