mirror of
https://github.com/mempool/mempool.git
synced 2025-09-23 19:25:12 +02:00
Improve cropping in asm component
This commit is contained in:
@@ -36,14 +36,35 @@ export class AsmComponent {
|
|||||||
parseASM(): void {
|
parseASM(): void {
|
||||||
let instructions = this.asm.split('OP_');
|
let instructions = this.asm.split('OP_');
|
||||||
// trim instructions to a whole number of instructions with at most `crop` characters total
|
// trim instructions to a whole number of instructions with at most `crop` characters total
|
||||||
if (this.crop) {
|
if (this.crop && this.asm.length > this.crop) {
|
||||||
let chars = 0;
|
let chars = 0;
|
||||||
for (let i = 0; i < instructions.length; i++) {
|
for (let i = 0; i < instructions.length; i++) {
|
||||||
chars += instructions[i].length + 3;
|
if (chars + instructions[i].length + 3 > this.crop) {
|
||||||
if (chars > this.crop) {
|
let croppedInstruction = instructions[i];
|
||||||
instructions = instructions.slice(0, i);
|
instructions = instructions.slice(0, i);
|
||||||
|
// add cropped instruction
|
||||||
|
let remainingChars = this.crop - chars;
|
||||||
|
let parts = croppedInstruction.split(' ');
|
||||||
|
// only render this instruction if there is space for the instruction name and a few args
|
||||||
|
if (remainingChars > parts[0].length + 10) {
|
||||||
|
remainingChars -= parts[0].length + 1;
|
||||||
|
for (let j = 1; j < parts.length; j++) {
|
||||||
|
const arg = parts[j];
|
||||||
|
if (remainingChars >= arg.length) {
|
||||||
|
remainingChars -= arg.length + 1;
|
||||||
|
} else {
|
||||||
|
// crop this argument
|
||||||
|
parts[j] = arg.slice(0, remainingChars);
|
||||||
|
// and remove all following arguments
|
||||||
|
parts = parts.slice(0, j + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
instructions.push(`${parts.join(' ')}`);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
chars += instructions[i].length + 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.instructions = instructions.filter(instruction => instruction.trim() !== '').map(instruction => {
|
this.instructions = instructions.filter(instruction => instruction.trim() !== '').map(instruction => {
|
||||||
|
Reference in New Issue
Block a user