Skip to content

Commit

Permalink
Merge pull request #523 from PRATHAM-SPS/automatic_scrolling
Browse files Browse the repository at this point in the history
Automatic_Scrolling for arduino console.
  • Loading branch information
firuza committed Jun 23, 2023
2 parents 989b334 + 1ac06cf commit c2f7649
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
27 changes: 23 additions & 4 deletions ArduinoFrontend/src/app/Libs/outputs/Arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,31 @@ export class ArduinoUno extends CircuitElement {
}
});

// Flag to control automatic scrolling
let shouldScrollToBottom = true;
const msg = document.getElementById('msg');

// Scroll Listener in console
msg.addEventListener('scroll', () => {
const isScrolledToBottom = msg.scrollHeight - msg.clientHeight <= msg.scrollTop + 1;
shouldScrollToBottom = isScrolledToBottom;
});

this.runner.usart.onByteTransmit = (value) => {
/// TODO: Show On Console
myOutput.textContent += String.fromCharCode(value);
};
{
// TODO: Show On Console
const isScrolledToBottom = msg.scrollHeight - msg.clientHeight <= msg.scrollTop + 1;
myOutput.textContent += String.fromCharCode(value);

document.getElementById('msg').append(myOutput);
if (shouldScrollToBottom && isScrolledToBottom) {
// Scroll to bottom if both conditions are met
msg.scrollTop = msg.scrollHeight;
}
}
};
// Appending output to console
msg.appendChild(myOutput);
msg.scrollTop = msg.scrollHeight;
this.pinNameMap['5V'].setValue(5, null);
this.pinNameMap['3.3V'].setValue(3.3, null);

Expand Down
1 change: 1 addition & 0 deletions ArduinoFrontend/src/app/simulator/simulator.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ body {
display: flex;
color: #fff;
flex-direction: column;
max-height: 200px;
}

#msg label {
Expand Down

0 comments on commit c2f7649

Please sign in to comment.