You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * !Logger */constos=require("node:os");constchalk=require("chalk");constwinston=require("winston");const{ combine, timestamp, json, printf, label, errors }=winston.format;/** * !console */const{
ConsoleManager,
OptionPopup,
InputPopup,
PageBuilder,
ButtonPopup,
ConfirmPopup,
CustomPopup,
FileSelectorPopup,
Progress,
Control,
InPageWidgetBuilder,
Button,
Box,EOL,}=require("console-gui-tools");constmyFormat=printf(({ level, message, label, timestamp })=>{if(level==="info"){console.log(`${chalk.blue(timestamp)}${chalk.yellow("["+label+"]")}${chalk.green(level)}: ${message}`);}elseif(level==="warn"){console.log(`${chalk.blue(timestamp)}${chalk.yellow("["+label+"]")}${chalk.red(level)}: ${message}`);}else{console.log(`${chalk.blue(timestamp)}${chalk.yellow("["+label+"]")}${chalk.red(level)}: ${message}`);}return`${timestamp} [${label}] ${level}: ${message}`;});constlogger=winston.createLogger({level: "info",format: combine(label({label: "radiman"}),timestamp(),myFormat),transports: [//new winston.transports.Console(),newwinston.transports.File({filename: "radiman.log",}),//new LogtailTransport(logtail), // onlien logging],});constopt={title: "Radiffy Radius Manager",// Title of the consolelogPageSize: 30,// Number of lines to show in logs pagelogLocation: 1,// Location of the logs pageenableMouse: false,// Enable mouse supportlayoutOptions: {boxed: true,// Set to true to enable boxed layoutshowTitle: true,// Set to false to hide title//changeFocusKey: "ctrl+l", // Change layout with ctrl+l to switch to the logs pagetype: "double",// Set to 'double' to enable double layoutdirection: "vertical",// Set to 'horizontal' to enable horizontal layoutboxColor: "yellow",boxStyle: "bold",},};constGUI=newConsoleManager(opt);letperiod=2000;letmode="debug";letvalueEmitter=null;letmin=9;letmax=12;letcpu_brand="";letcpu_speed=0;letcpu_cores=0;constperiodList=[2000,5000,10000,20000,30000,60000,120000,300000,600000,900000,1800000,3600000,7200000,14400000,28800000,43200000,86400000,];constnumberOfCores=os.cpus().length;constcores=[];for(leti=0;i<numberOfCores;i++){cores.push(newProgress({id: `htop-cpu-${i}`,x: 2,y: 1+i,interactive: false,draggable: false,label: i>9 ? `${i} ` : `${i} `,length: 40,min: 0,max: 100,style: {boxed: true,theme: "htop",showMinMax: false,showValue: false,},}));}constmem=newProgress({id: "htop-mem",x: 2,y: 1+numberOfCores,label: "Mem",length: 40,min: 0,max: os.totalmem()/(1024*1024*1024),unit: "G",style: {boxed: true,theme: "htop",showMinMax: false,},});//Create function to get CPU informationfunctioncpuAverage(core){//Initialise sum of idle and time of cores and fetch CPU infolettotalIdle=0,totalTick=0;//Select CPU coreconstcpu=os.cpus()[core];//Total up the time in the cores tickfor(leti=0,len=Object.keys(cpu.times).length;i<len;i++){totalTick+=Object.values(cpu.times)[i];}//Total up the idle time of the coretotalIdle+=cpu.times.idle;//Return the average Idle and Tick timesreturn{idle: totalIdle,total: totalTick};}functiongetCPULoadAVG(core,avgTime=1000,delay=500){returnnewPromise((resolve,reject)=>{constn=~~(avgTime/delay);if(n<=1){reject("Error: interval to small");}leti=0;constsamples=[];constavg1=cpuAverage(core);constinterval=setInterval(()=>{//GUI.log("CPU Interval: " + i)if(i>=n){clearInterval(interval);resolve(~~((samples.reduce((a,b)=>a+b,0)/samples.length)*100));}constavg2=cpuAverage(core);consttotalDiff=avg2.total-avg1.total;constidleDiff=avg2.idle-avg1.idle;samples[i]=1-idleDiff/totalDiff;i++;},delay);});}constgetSystemInfo=async()=>{constcoresPercent=[];for(leti=0;i<numberOfCores;i++){constload=awaitgetCPULoadAVG(i).catch((err)=>console.error(err));coresPercent.push(load);}constmemUsage=os.totalmem()-os.freemem();return{cpuUsage: coresPercent,
memUsage,};};constmodeList=["debug","info","error","warning","notice","crit","alert","emerg",];constfetchSystemInformation=async()=>{getSystemInfo().then((info)=>{info.cpuUsage.forEach((core,i)=>{cores[i].setValue(core);});mem.setValue(info.memUsage/(1024*1024*1024));});drawGui();};constframe=async()=>{awaitfetchSystemInformation();};/** * @description Updates the console screen * */constupdateConsole=async()=>{constuptime=os.uptime();consthours=Math.floor(uptime/3600);constminutes=Math.floor((uptime%3600)/60);constseconds=Math.floor(uptime%60);constuptimeText=`${hours}:${minutes}:${seconds}s`;constp=newPageBuilder();p.addSpacer(numberOfCores+1);if(!valueEmitter){p.addRow({text: "Sysinfo is not running! ",color: "red"},{text: "press 'space' to start",color: "white"});}else{p.addRow({text: "Sysinfo is running! ",color: "green"},{text: "press 'space' to stop",color: "white"});}// Print mode:p.addRow({text: "Logging Mode: ",color: "magenta"},{text: `${mode}`,color: "white"});GUI.setPage(p,0);GUI.refresh();};GUI.on("exit",()=>{closeApp();});GUI.on("keypressed",(key)=>{switch(key.name){case"space":
if(valueEmitter){clearInterval(valueEmitter);valueEmitter=null;drawGui();}else{valueEmitter=setInterval(frame,period);drawGui();}break;case"m":
newOptionPopup({id: "popupSelectMode",title: "Select logging mode",options: modeList,selected: mode,}).show().on("confirm",(_mode)=>{mode=_mode;//logger.transports.console.level = mode;GUI.warn(`NEW MODE: ${mode}`);drawGui();});break;case"s":
newOptionPopup({id: "popupSelectPeriod",title: "Select update period",options: periodList,selected: period,}).show().on("confirm",(_period)=>{constmsgMultiLine=`Changing period from ${period} to ${_period} ms.${EOL}This will restart the monitor.${EOL}Do you want to continue?`;newButtonPopup({id: "popupConfirmPeriod",title: "Confirm period",message: msgMultiLine,buttons: ["Yes","No","?"],}).show().on("confirm",(answer)=>{if(answer==="Yes"){period=_period;GUI.warn(`NEW PERIOD: ${period}`);}elseif(answer==="?"){GUI.info("Choose ok to confirm period");}drawGui();});});break;case"a":
newInputPopup({id: "popupTypeMax",title: "Type max value",value: max,numeric: true,}).show().on("confirm",(_max)=>{max=_max;GUI.warn(`NEW MAX VALUE: ${max}`);drawGui();});break;case"d":
newInputPopup({id: "popupTypeMin",title: "Type min value",value: min,numeric: true,}).show().on("confirm",(_min)=>{min=_min;GUI.warn(`NEW MIN VALUE: ${min}`);drawGui();});break;case"1":
{constp=newPageBuilder(5);// Add a scroll limit so it will be scrollable with up and downp.addRow({text: "Example of a custom popup content!",color: "yellow",});p.addRow({text: "This is a custom popup!",color: "green"});p.addRow({text: "It can be used to show a message,",color: "green",});p.addRow({text: "or to show variables.",color: "green"});p.addRow({text: "TCP Message sent: ",color: "green"},{text: `${12}`,color: "white"});p.addRow({text: "Connected clients: ",color: "green"},{text: `${20}`,color: "white"});p.addRow({text: "Mode: ",color: "green"},{text: `${"radsec"}`,color: "white"});p.addRow({text: "Message period: ",color: "green"},{text: `${100} ms`,color: "white"});newCustomPopup({id: "popupCustom1",title: "See that values",content: p,width: 32,}).show();}break;case"q":
newConfirmPopup({id: "popupQuit",title: "Are you sure you want to quit?",}).show().on("confirm",()=>closeApp());break;default:
break;}});constcloseApp=()=>{console.clear();process.exit();};GUI.refresh();constfooter=newBox({id: "footer",x: 0,y: GUI.Screen.height-1,width: GUI.Screen.width,height: 1,});constrow_footer=newInPageWidgetBuilder(1);row_footer.addRow({text: "F1:",color: "white",bold: true},{text: "Help ",color: "black",bg: "bgCyan",bold: false},{text: "F6:",color: "white",bold: true},{text: "SortBy",color: "black",bg: "bgCyan",bold: false},{text: "F9:",color: "white",bold: true},{text: "Kill ",color: "black",bg: "bgCyan",bold: false},{text: "F10:",color: "white",bold: true},{text: "Quit ",color: "black",bg: "bgCyan",bold: false});footer.setContent(row_footer);GUI.on("resize",()=>{footer.absoluteValues={x: 0,y: GUI.Screen.height-2,width: GUI.Screen.width,height: 1,};GUI.refresh();});constdrawGui=()=>{updateConsole();};drawGui();valueEmitter=setInterval(frame,2000);setInterval(()=>{logger.info("test");},5000);
Library Version
^3.7.0
Node Version
^3.7.0
What operating system are you using?
Windows
Terminal
powershell and git bash
Interest to fix the bug
I would like to fix this bug!
The text was updated successfully, but these errors were encountered:
What happened?
A bug happened! Broken box
What should have happened?
Box should be not broken
Code
Library Version
^3.7.0
Node Version
^3.7.0
What operating system are you using?
Windows
Terminal
powershell and git bash
Interest to fix the bug
The text was updated successfully, but these errors were encountered: