As part of working on issue #66 I spent some time looking at the output of the sensors command and how the data is parsed by the extension. It reminded me of Issue #6 where I found a while loop inside a for loop in the top parser function, and I realise now I didn't understand then why that loop was there. Changing the inner while loop to an if didn't break anything, but that function has always bothered me when I caught sight of it... something dark lurking in the shadows.
Now I understand the while loop was looking for the blank line between chips, and relates to skipping the following two lines (chip name and adapter name) to get straight to the first feature for that chip.
To atone for changing that code without fully understanding it, and make the layout of the function more closely aligned to the layout of the sensor data, I will re-instate the inner while loop, and re-work the continuation line logic.
$ git log -p -- utilities.js
...
Author: MisterGuinness
Date: Sat Apr 21 17:10:17 2018 +0800
Fixed Issue #6. Code tidy up
diff --git a/src/utilities.js b/src/utilities.js
index e960eb2..f31ece9 100644
--- a/src/utilities.js
+++ b/src/utilities.js
@@ -81,11 +81,10 @@ function parseSensorsOutput(txt,parser) {
let feature_value = undefined;
let sensors = new Array();
//iterate through each lines
- for(let i = 0; i < sensors_output.length; i++){
+ for(let i = 2; i < sensors_output.length; i++){
// ignore chipset driver name and 'Adapter:' line for now
- i += 2;
// get every feature of the chip
- while(sensors_output[i]){
+ if(sensors_output[i]){
// if it is not a continutation of a feature line
if(sensors_output[i].indexOf(' ') != 0){
let feature = parser(feature_label, feature_value);
As part of working on issue #66 I spent some time looking at the output of the sensors command and how the data is parsed by the extension. It reminded me of Issue #6 where I found a
while
loop inside afor
loop in the top parser function, and I realise now I didn't understand then why that loop was there. Changing the innerwhile
loop to anif
didn't break anything, but that function has always bothered me when I caught sight of it... something dark lurking in the shadows.Now I understand the
while
loop was looking for the blank line between chips, and relates to skipping the following two lines (chip name and adapter name) to get straight to the first feature for that chip.To atone for changing that code without fully understanding it, and make the layout of the function more closely aligned to the layout of the sensor data, I will re-instate the inner while loop, and re-work the continuation line logic.