const fs = require( 'fs' );
const path = require( 'path' );

const data = '' + fs.readFileSync( '/usr/share/themes/Material-Black-Blueberry/gtk-4.0/gtk.css' );

let lineNumber = 1;
const indexer = {};
for (let i = 0; i < data.length; i++) {
    const char = data[i];
    
    if ( char === '\n' ) {
        lineNumber++;
    } else if ( char === '#' ) {
        const extract = data.substring( i );
        const col = extract.slice( 0, extract.indexOf( '\n' ) );
        if ( !indexer[ col ] ) {
            indexer[ col ] = [];
        }
        indexer[ col ].push( lineNumber );
    } else if ( char === 'r' ) {
        const extract = data.substring( i );
        if ( extract.slice( 0, 3 ) === 'rgb' ) {
            const col = extract.slice( 0, extract.indexOf( '\n' ) );
            if ( !indexer[ col ] ) {
                indexer[ col ] = [];
            }
            indexer[ col ].push( lineNumber );
        }
    }
}


// Output
const keys = Object.keys( indexer );
for (let i = 0; i < keys.length; i++) {
    const element = keys[i];

    if ( element.length <= 25 ) {
        console.log( 'Colour ' + element.slice( 0, element.length - 1 ) + ' appears on ' + indexer[ element ] );
    }
}
