Skip to content

Instantly share code, notes, and snippets.

@Exponential-Workload
Created January 3, 2024 08:47
Show Gist options
  • Save Exponential-Workload/dbd0be5da7aa1da7ce500c5b9c57b700 to your computer and use it in GitHub Desktop.
Save Exponential-Workload/dbd0be5da7aa1da7ce500c5b9c57b700 to your computer and use it in GitHub Desktop.
hex to ansi
// only works for 6-digit hex codes, separated by newlines
const hexToRgb = v=>v.split('\n').map(line=>line.split('').map((char,idx,v)=>idx%2===0?Number(`0x${char}${v[idx+1]}`):'')).map(a=>a.filter(v=>typeof v === 'number'))
const hexToAnsi = v=>hexToRgb(v).map(r=>`\x1b[38;2;${r.join(';')}m`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment