Skip to content

Commit a6eb09c

Browse files
save file
1 parent 607942a commit a6eb09c

1 file changed

Lines changed: 47 additions & 33 deletions

File tree

utils/misc/nodejs-terminal/v2.0/nodejs-terminal-v2.0.html

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,13 @@
787787
hide : ()=>term.write('\x1b[?25l'),
788788
show : ()=>term.write('\x1b[?25h'),
789789
xy : ()=>{
790-
// Current Column
790+
// Note: These are 0-indexed, so the top-left is 0,0.
791+
// ANSI sequences are usually 1-indexed (1,1).
792+
// Current Column
791793
var x = term.buffer.active.cursorX;
792-
// Current Row
794+
// Current Row
793795
var y = term.buffer.active.cursorY;
794-
console.log(`Cursor is at: ${x}, ${y}`);
796+
console.log(`cursor is at: ${x}, ${y}`);
795797
return {x,y};
796798

797799
},//xy
@@ -1168,48 +1170,60 @@
11681170

11691171
function spinner({x,y}={}){
11701172

1171-
var frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
1172-
var i = 0;
1173+
var spinner = {};
1174+
spinner.timer = null;
1175+
spinner.stop = null;
1176+
spinner.x = null;
1177+
spinner.y = null;
11731178

1179+
var frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
1180+
var i = 0;
11741181
// Hide the cursor so it doesn't flicker
11751182
//term.write(cursor.hide);
1183+
setTimeout(setup,50);
11761184

1177-
if(x===undefined){
1178-
({x,y} = cursor.xy());
1179-
}
1180-
1181-
var spinner = {};
1185+
return spinner;
11821186

1183-
spinner.timer = setInterval(()=>{
1184-
// \r moves to start of line, colors.cyan makes it pop
1185-
cursor.save();
1186-
cursor.to(x,y);
1187-
term.write(`\r${colors.cyan}${frames[i]}${colors.reset}`);
1188-
cursor.restore();
1189-
i = (i+1)%frames.length;
1190-
1191-
},80);
11921187

1193-
spinner.stop = function(){
1188+
function setup(){
11941189

1195-
if(!spinner.timer){
1196-
return;
1190+
if(x===undefined){
1191+
({x,y} = cursor.xy());
1192+
spinner.x = x;
1193+
spinner.y = y;
11971194
}
11981195

1199-
clearInterval(spinner.timer);
1200-
spinner.timer = null;
1196+
1197+
spinner.timer = setInterval(()=>{
1198+
// \r moves to start of line, colors.cyan makes it pop
1199+
cursor.save();
1200+
cursor.to(x+1,y);
1201+
term.write(`${colors.cyan}${frames[i]}${colors.reset}`);
1202+
cursor.restore();
1203+
i = (i+1)%frames.length;
1204+
1205+
},80);
1206+
1207+
spinner.stop = function(){
1208+
1209+
if(!spinner.timer){
1210+
return;
1211+
}
1212+
1213+
clearInterval(spinner.timer);
1214+
spinner.timer = null;
12011215
// Clear the line, show cursor, and print final message
12021216
// \x1b[K clears from cursor to end of line
1203-
cursor.save();
1204-
cursor.to(x,y);
1205-
term.write(' ');
1206-
cursor.restore();
1207-
// Show cursor
1208-
//term.write(cursor.show);
1217+
cursor.save();
1218+
cursor.to(x+1,y);
1219+
term.write(' ');
1220+
cursor.restore();
1221+
// Show cursor
1222+
//term.write(cursor.show);
1223+
1224+
}//stop
12091225

1210-
}//stop
1211-
1212-
return spinner;
1226+
}//setup
12131227

12141228
}//spinner
12151229

0 commit comments

Comments
 (0)