PowerShell: Character Animation in Console and SetCursorPosition got crazy - animation

Experts,
I'm building a long list of Visual Studio projects using msbuild. And while hiding the msbuild output, displaying a status and an animation based upon some characters is displayed while msbuild doing its job. Here my script to build using msbuild and display wait animation (You will surely like this...):
$anim=#("|","/","-","\","|") # Animation sequence characters
$ReturnCode = #{}
$BuildStatus="Building $(ProjectName)"
$CursorTop=[Console]::CursorTop #// Cursor position on Y axis
$CursorLeft=$BuildStatus.Length #// Cursor position on X axis
Write-Host $BuildStatus -ForegroundColor Cyan
#// starting the MsBuild job in background.
$MsbJob = [PowerShell]::Create().AddScript(
{
param($MsbArgs, $Result)
& msbuild $MsbArgs | Out-Null
$Result.Value = $LASTEXITCODE
}
).AddArgument($MsbArgs).AddArgument($ReturnCode)
$async = $MsbJob.BeginInvoke() #// start executing the job.
#// While above script block is doing its job in background, display status and animation in console window.
while (!$async.IsCompleted)
{
foreach ($item in $anim) #// looping on array containing characters to form animation
{
[Console]::SetCursorPosition($CursorLeft + 5,$CursorTop) #//setting position for cursor
Write-Host $item -ForegroundColor Yellow
Start-Sleep -m 50
}
}
$MsbJob.EndInvoke($async)
most of the time, it works as expected i.e. showing the status like:
Building MyProject (Animating characters)..
but suddenly, it becomes like this:
Only Discovered Solution: I was able to correct this is to increase the Screen Buffer Size of Console (Console Properties --> Layout: Screen Buffer Size) to 1024. In addition, I also increased Window Size to fill out the monitor and it didn't break like that.
Is my assessment about Screen Buffer is correct? or anything else is breaking up?
If Yes, do I have to increase the screen buffer size pragmatically i.e. from inside my .psm1 script.?
Any help would be really appreciated.

By default Write-Host puts a newline after the printed string. Instead of re-positioning the cursor try printing the output without the newline, so you can use backspace (`b) to erase the character printed before:
while (!$async.IsCompleted) {
$anim | % {
Write-Host "`b$_" -NoNewline -ForegroundColor Yellow
Start-Sleep -m 50
}
}

So, after digging a little, I find one method which I was also expecting it to work i.e. Increase Screen Buffer Values of Console Window hosting all my crap. So added this line in my script which seems to be preventing the character animation from breaking up:
[Console]::SetBufferSize(512,512)
I also experimented by giving it very low values i.e. 15,5 and yes I reproduced above problem.
So at this time, this seems to be a solution. However, I'm still testing it with time to time...

Related

Create Identifier for input box with AHK GUI

I have created a GUI in AHK and it works well now. I am processing multiple records and would like to be able to track the place that I am on. My code loops through each record and does some actions before moving on to the next one. While this is happening the GUI window is shown. Also I am writing this in AHK then using the conversion tool and creating an .exe with it. I am developing this tool to be distributed as a stand alone EXE that one can install/save and then run when they want to. Below is a screen shot of the tool and the code to load in the names.
Gui, PasteGUI:Add, Text,, Please add the Names that you want to Process.
Counter := 0
Loop, parse, Clipboard, `n, `r
{
x%A_Index% := A_LoopField
Counter++
}
Counter--
Loop, %Counter% ; Dynamic List length
Gui PasteGUI:Add, Edit, vButton%A_Index%, % x%A_Index%
Gui PasteGUI:Add, Button, x200 y270 w88 h26 vButton02 gGoCont Default, Continue
Gui PasteGUI:Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui, PasteGUI:Show
}
Return
GoCont:
{
Loop, %Counter%
{
CODE TO PROCESS MY EACH NAME
}
MsgBox Done!
Gui Destroy
}
Return
GoQuit:
Gui Destroy
Return
I want to add something so that when I am processing Jason it can be identified. Having an arrow that moves as I loop through the list would be nice. As I have depicted it below,I drew it on in paint. Otherwise if I could turn the past records a color that would work too. So for the below example the names "Chris" & "Ben" would be highlighted in a color or the boxes would be somehow identified as different. I am not sure how to do either so it would be great to learn both if possible. Lastly, whatever method is described I need to be able to convert it to an .exe with Ahk2Exe and then be able to run the .exe and not have a need to have any further files or other references in the program that would not work. This is interned to be run on a standard Windows computer so if there are some default images that can be accessed that might be useful too.
Okay so Ive worked out how to do this with PGilm's method of checkboxes. You could also possibly do this with a table of some sort. But the code below looks to be working for me.
Also I wanted to let you know I changed the var x to cliparray so it is easier to read.
Gui, Add, Text,section, Please add the Names that you want to Process.
Counter := 0
Loop, parse, Clipboard, `n, `r
{
cliparray%A_Index% := A_LoopField
Counter++
}
Counter--
Loop, %Counter% {
; Dynamic List length
Gui, Add, Checkbox, xs vCheckBox%A_Index%
Gui Add, Edit, yp+1 xs+30 vTextbox%A_Index%, % cliparray%A_Index%
}
Gui Add, Button, x200 y270 w88 h26 gGoCont vButton02 Default, Continue
Gui Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui, Show
Return
GoCont:
;needed to get the variables from the edits and check box, else the varibles dont exist See below for more information.
Gui, Submit, NoHide
msgbox, Go..
Loop, %Counter%
{
line=Textbox%A_Index%
GuiControl,, CheckBox%A_Index%, 1
backone:=A_Index-1
GuiControl,, CheckBox%backone%, 0
Msgbox % "variable " line " contains: " Textbox%A_Index%
}
MsgBox Done!
Return
GoQuit:
Gui Destroy
Return
;Used to debug to see list of all variables. Super helpful :D
F7::
ListVars
return
Some logic to take note of would be on the lines that add the edits and checkbox's. I used the Section logic of Gui positioning to make the edit and check on the same line. In this code the section element is set in the first Gui, Add, for the text section. And thus carries down to the other gui elements. Section AHK Documentation
Gui, Add, Checkbox, xs vCheckBox%A_Index%
Gui Add, Edit, yp+1 xs+30 vTextbox%A_Index%, % cliparray%A_Index%
The next part to take a closer look at is in the GoCont function. I am using the index of the loop to check the CheckBox%A_Index% checkbox so that the current line turns on. I also turn off the last index's check box with the GuiControl,, CheckBox%backone%, 0 line. This give the effect of the check box moving through list as you process text with in each element.
One last line to mention is the Gui, Submit, NoHide. Without this you will be missing the variables created for each checkbox and edit. This will create and fill the variables with the data from each gui element. Gui, Submit AHK Documentation

Is there any way to view entire contents of variable in Python IDLE Debugger?

I am trying to view the entire contents of a variable in the IDLE Debugger for Python 3.6.1. The debugger gives a preview but there appears to be no way to pull all the data out from the debugger.
The only work-around I've found is to throw a print() statement in the code somewhere. Is this the only way? See picture:
This example's decryptedText variable has over 700 characters but as we see, only a few are visible. Thanks.
As the IDLE debugger is currently written, the only way to get more information about the state of an object at a particular point in the execution is to either insert print calls in the code or stop execution (raise SystemExit, for instance) and interact with the object in the Shell.
What you see in the locals/globals panels are representations of objects produced by reprlib.Repr with maxstring and maxother increased to 60. One could edit NamespaceViewer in idlelib/debugger.py (3.6 name) to increase maxstring to, say, 200 and maximize the debug window. (I verified that this works to show more of a string.) One could also try replacing the single line Entry widget with a Label widget sized to height lines and width chars and setting maxstring to height * width. (Untried.)
I agree that being able to get more information on a object would be good. I am currently thinking about a separate popup window with type, length (if appropriate), and a much bigger slice of the contents.

Term::ReadKey::GetTermialSize on MSWin32 OS

When I call this script on a Linux OS Term::Size::Any (chars) and Term::ReadKey (GetTerminalSize) return always the same number of columns.
When I call the script on a Windows machine the returned number of columns differ as soon as I resize the terminal with the mouse to a smaller size. chars returns the new width while GetTerminalSize returns the initial terminal width.
Is there a trick to get from GetTerminalSize the new resized terminal width?
use strict;
use warnings;
use 5.10.0;
use Term::Size::Any qw(chars);
use Term::ReadKey qw(GetTerminalSize);
say( ( chars( \*STDOUT ) )[0] );
say( ( GetTerminalSize( \*STDOUT ) )[0] );
What you are currently doing is not called "resizing", the terminal screen size is still the same, you are just diminishing the terminal visible size.
To change the Window Terminal "size", click on the top left corner, go to Properties change the "Screen Buffer Size", at the moment you are just changing the "Window Size"

alarm on screen change

I have to use a software which list my clients processes. I need a sound alert program if something change on 50x10 pixel region. I try to write a program on autohotkey but i can't succeed in. Anybody have this program?
Here is an example that you can use.
^Launch_Media:: ; Make a reference screenshot with NirSoft NIRCMD by pressing Ctrl+Media or any other program...
run, "C:\Program Files\1 My Programs\nircmd.exe" savescreenshot "c:\Temp\Screenshot.bmp" 33 40 17 20 ; Location of "Save As" Icon in SciTE4AutoHotKey Editor
Return
Launch_Media:: ; Launch this test manually with Media Button
CoordMode Pixel ; Interprets the coordinates below as relative to the screen rather than the active window.
ImageSearch, FoundX, FoundY, 0, 0, 200, 200, C:\Temp\Screenshot.bmp ; search for image in area staring at 0,0 to 200,200
if ErrorLevel = 2
MsgBox Could not conduct the search.
else if ErrorLevel = 1
MsgBox Image could not be found on the screen.
else
SoundBeep, 1000, 1000
MsgBox The Image was found at %FoundX% %FoundY%.
ClickX:=FoundX + 5 ; Move the mouse click away from the edge of the icon
ClickY:=FoundY + 5 ; Move the mouse click away from the edge of the icon
Click, %ClickX%, %ClickY% ; Click on the Save As icon.
Return
When we know more about what you want to test (I think that an area of 50x10 might be too small), and what you want to do in case the area has changed, we might be able to help you with a more suited script.
In this example I used NirSoft's nircmd.exe, but you can create a reference image by other means as well. If You only need an audible alarm, you can comment all the other commands under if, then, else out with ;.
Did you check this post from 2 years ago in the AutoHotKey community?
http://www.autohotkey.com/board/topic/56219-fast-screen-change-check-using-histograms/
The above script might be a little overwhelming, but you can also create a screenshot of a fixed area and do an image comparison in AutoHotKey as others have done before you.

Change the color of an already existing label in Tcl/Tk

I have a status bar which is a label connected to a variable:
label .main_frame.status_bar.status_label -textvariable _DB(status_text)
I want to change the color of the text each time I get an error, meaning when the status bar shows an error, the text should be red, when later it shows normal status, it should change back to black. How do I change the -foreground property of the label "on the fly"?
You can reconfigure any Tk widget property live by calling the widget configure procedure. In this case:
.main_frame.status_bar.status_label configure -foreground $new_colour
$label configure -fg $color
or
$label configure -foreground $color
Run $label configure in an interactive wish shell to see all the options you can change.
P.S.
I should add that IMO this approach to error reporting is flawed. Showing non-critical warnings this way is okay, but errors should be reported more aggressively.

Resources