Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ on:
jobs:
build_windows:

runs-on: windows-latest
runs-on:
- self-hosted
- ali-test

steps:

Expand Down
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new method to specifically set the control chars handle to true to make sure that the other areas using the getConsoleStream() don't break anything.

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public MessageConsoleStream getConsoleStream()
{
return getConsoleStream("ESP-IDF Console", null, false); //$NON-NLS-1$
}
public MessageConsoleStream getConsoleStream(String consoleName, URL imageUrl, boolean errorStream)

public MessageConsoleStream getConsoleStream(String consoleName, URL imageUrl, boolean errorStream, boolean handleControlChars)
{
// Create Tools console
MessageConsole msgConsole = findConsole(consoleName, imageUrl);
msgConsole.setHandleControlCharacters(handleControlChars);
msgConsole.setCarriageReturnAsControlCharacter(handleControlChars);
msgConsole.clearConsole();
MessageConsoleStream console = msgConsole.newMessageStream();
msgConsole.activate();
Expand All @@ -55,6 +57,12 @@ public void run()
return console;
}


public MessageConsoleStream getConsoleStream(String consoleName, URL imageUrl, boolean errorStream)
{
return getConsoleStream(consoleName, imageUrl, errorStream, false);
}

/**
* Find a console for a given name. If not found, it will create a new one and return
*
Expand Down
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class was only being used in context of tools installation so its safe to modify this to read the progress but it heavily relies on the idf_tools.py script to have the same output as it does now. Better way would be when we get a machine readable output of that script it will handle things much better

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ public void run()
String line = null;
while ((line = br.readLine()) != null)
{
console.println(line);
if (line.matches("^\\d+%$"))
{
updateProgressBar(line);
}
else
{
console.println(line);
}
}
}
catch (IOException e)
Expand All @@ -63,4 +70,34 @@ public void run()
}
}
}

private void updateProgressBar(String progressLine)
{
// Extract the numeric value of the progress
int progress = Integer.parseInt(progressLine.replace("%", ""));
StringBuilder progressBar = new StringBuilder("[");

// Assuming a 50-char wide progress bar for illustration
int totalBars = 50;
int filledBars = (progress * totalBars) / 100;

for (int i = 0; i < totalBars; i++)
{
if (i < filledBars)
{
progressBar.append("=");
}
else if (i == filledBars)
{
progressBar.append(">");
}
else
{
progressBar.append(" ");
}
}
progressBar.append("] ").append(progress).append("%");
console.print("\r" + progressBar.toString());
}

}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand the need to create two different console objects even when they are returning the same console. So I added a class level property for the IDFConsole and used the updated method in class to explicitly allow the handling of control chars like carriage return \r that I am using in the InputStreamConsoleThread to overwrite the existing progress when updated

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public abstract class AbstractToolsHandler extends AbstractHandler
/**
* Tools console
*/
private IDFConsole idfConsole;
protected MessageConsoleStream console;
protected MessageConsoleStream errorConsoleStream;
protected String idfPath;
Expand Down Expand Up @@ -113,9 +114,10 @@ public Object execute(ExecutionEvent event) throws ExecutionException

protected void activateIDFConsoleView()
{
console = new IDFConsole().getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null, false);
errorConsoleStream = new IDFConsole().getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null,
true);
idfConsole = new IDFConsole();
console = idfConsole.getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null, false, true);
errorConsoleStream = idfConsole.getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null,
true, true);
}

protected String getPythonExecutablePath()
Expand Down