Page 1 of 1
How to get percentage from npm install in Pure?
Posted: Tue Jun 09, 2020 5:23 pm
by Mythros
Hi all! How can I add a progress bar that shows the percent of a command prompt npm install? IE : You know how when installing with npm, it shows a text loading bar?
How do I grab that current value & turn it into a percentage & plug it into a percentage bar?
ANY & ALL help is GREATLY appreciated! <3
Thank You! <3
Re: How to get percentage from npm install in Pure?
Posted: Tue Jun 09, 2020 5:46 pm
by infratec
viewtopic.php?p=544671#p544671
You have to search the line which contains '[' and count the carrets.
Re: How to get percentage from npm install in Pure?
Posted: Tue Jun 09, 2020 6:09 pm
by Mythros
@infratec : Thank you! Although I do not understand this. Is there easier way?
Thank You! <3
Re: How to get percentage from npm install in Pure?
Posted: Tue Jun 09, 2020 8:15 pm
by infratec
No, it's not enough to show the way...
I have to code it all
Code: Select all
EnableExplicit
Import "kernel32.lib"
AttachConsole(processID.l)
EndImport
Procedure.f GetHashPercentage()
Protected hConsole.i, processID.i, hStdOut.i, NumberOfChars.l, Y.i, Pos1.i, Pos2.i, Result.f
Protected MaxCarrets.i, CurrentCarrets.i
Protected ConsoleScreenBufferInfo.CONSOLE_SCREEN_BUFFER_INFO
Protected *Buffer
Protected ReadCoord.COORD
Protected Line$
Result = -1
hConsole = FindWindow_("ConsoleWindowClass", #Null)
If hConsole
GetWindowThreadProcessId_(hConsole, @processID)
If AttachConsole(processID)
hStdOut = GetStdHandle_(#STD_OUTPUT_HANDLE)
If hStdOut
If GetConsoleScreenBufferInfo_(hStdOut, @ConsoleScreenBufferInfo)
*Buffer = AllocateMemory((ConsoleScreenBufferInfo\srWindow\right + 1) * (ConsoleScreenBufferInfo\srWindow\bottom + 1) * SizeOf(Character), #PB_Memory_NoClear)
If *Buffer
ReadCoord\x = 0
ReadCoord\y = ConsoleScreenBufferInfo\srWindow\top
If ReadConsoleOutputCharacter_(hStdOut, *Buffer, (ConsoleScreenBufferInfo\srWindow\right + 1) * (ConsoleScreenBufferInfo\srWindow\bottom + 1), PeekL(@ReadCoord), @NumberOfChars)
For Y = 0 To ConsoleScreenBufferInfo\srWindow\bottom - ConsoleScreenBufferInfo\srWindow\top
Line$ = PeekS(*Buffer + (Y * (ConsoleScreenBufferInfo\srWindow\right + 1) * SizeOf(Character)), ConsoleScreenBufferInfo\srWindow\right + 1)
Pos1 = FindString(Line$, "[")
If Pos1
Debug Line$
If Pos1 < 16 ; I don't know where it starts, but needed because DOS returns the Version in []
Pos1 + 1
Pos2 = FindString(Line$, "]", Pos1)
If Pos2
MaxCarrets = Pos2 - Pos1
Line$ = Mid(Line$, Pos1, MaxCarrets)
CurrentCarrets = CountString(Line$, "#")
Debug Str(CurrentCarrets) + " of " + Str(MaxCarrets)
Result = CurrentCarrets * 100 / MaxCarrets
Break
EndIf
EndIf
EndIf
Next Y
EndIf
FreeMemory(*Buffer)
EndIf
EndIf
EndIf
FreeConsole_()
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Define Prog.i
Prog = RunProgram("cmd", "/K @echo [##### ]", "", #PB_Program_Open)
If Prog
Delay(1000)
Debug StrF(GetHashPercentage(), 2) + "%"
Delay(3000)
KillProgram(Prog)
CloseProgram(Prog)
EndIf
Re: How to get percentage from npm install in Pure?
Posted: Tue Jun 09, 2020 8:38 pm
by infratec
I finished.
Now I go for a walk with my dogs.