forked from finanalyst/raku-pod-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight-filename-from-stdin.coffee
executable file
·41 lines (36 loc) · 1.19 KB
/
highlight-filename-from-stdin.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!highlights/node_modules/coffee-script/bin/coffee
Highlights = require 'highlights'
fs = require 'fs'
path = require 'path'
highlighter = new Highlights()
highlighter.requireGrammarsSync
modulePath: require.resolve('./atom-language-perl6/package.json')
stdin = process.openStdin()
stdin.setEncoding 'utf8'
mystderr = process.stderr
mystdout = process.stdout
process_file = (given_path) ->
full_path = path.resolve given_path
i = 0
e = true
while e && !fs.existsSync(given_path)
i++
if i > 100000
console.error "Highlights runner: ERROR Giving up looking for the file. Cannot read file #{full_path}"
e = false
if i > 0
console.error "Highlights runner: file #{full_path} does not exist. tried #{i} times."
fs.readFile full_path, 'utf8', (read_err, file_str) ->
if read_err
console.error read_err
else
highlighter.highlight (fileContents: file_str, scopeName: 'source.perl6fe'), (hl_err, html) ->
if hl_err
console.error hl_err
else
obj = {}
obj.file = full_path
obj.html = html
mystdout.write(JSON.stringify(obj) + '\n' )
stdin.on 'data', (input) ->
process_file input.trim()