0.2.5 • Published 10 years ago

menu v0.2.5

Weekly downloads
50
License
MIT
Repository
github
Last release
10 years ago

menu

A cli menu for your node.

Install

build alt platform alt

npm install menu

ScreenShot1

API

Tabs

Menu is built around tabs. There are currently four types:

  • Toggle: This tab functions like a button.
  • List: This tab selects a single value from its list.
  • Search: This tab takes a string input, and has the function of a list tab.
  • Select: This tab creates a selectable drop-down list.

These tabs are declared as such...

var content = {
	tab1: {title:"column1", seltitle: "COLUMN1", type:"toggle", val:"true", color:"blue"},
	tab2: {title:["column2", "column22"], seltitle: ["COLUMN2", "COLUMN22"], type:"search", input: 0, val:"abcdefgh", color:"red"},
	tab3: {title:"column3", seltitle: "COLUMN3", type:"list", input: 0, val:["a", "b", "c"], color:"white"},
	tab4: {title:"column4", seltitle: "COLUMN4", type:"select", input: 0, val:["1","2","3","4","5","6"], color:"green"}
}

Properties

title: This is the tabs label when it's not focused. seltitle: This is the tabs label when it is focused. type: This is the tab's type. input: This is the index value for a list, select, and search tabs. val: For type toggle, it's a boolean value. For types list and select, it's an array of values. For type search it's a string. color: The tab's set color. Look at the node clivas for all possible values.

Initialization

var menu = require('./index.js');

menu.init(content);					

menu.draw()							//this draws the headers

menu.clivas							//you can custom draw with clivas

Delegate

function work() {
    menu.start(options, function(result) {
        var key = result[0]; 						//refer to node keypress for all properties
        var column = result[1]; 					//the focused tab
        
        menu.draw();								//draw tabs
        
        if(key.name=="return" && column.id === 4) {			
			menu.clivas.line(Math.abs(column.input%column.val.length));	//always mod your column input to determine focused index
		} else if(key.name=="return" && column.id === 2) {
			menu.clivas.line("You searched for "+column.val);
			column.val = "";
		} else if(key.ctrl && key.name ==="c") {
			process.exit();
		} else if(key.name ==="backspace") {
			
		} else if(key.name ==="left") {
			
		} else if(key.name ==="up") {
			
		} else if(key.name ==="down") {
			
		} else if(key.name ==="right") {
			
		} else {
			
		}
	
		if(column.id === 1) {					//use tab 1 to toggle tab 4's select contents
			if(column.val) {
				menu.columns["tab4"].val = ["z","y","x","w"];
			} else {
				menu.columns["tab4"].val = ["1","2","3","4","5","6"];
			}
			menu.draw();
		}
    })
} work();
0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.0

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago